LoginSignup
2
8

More than 3 years have passed since last update.

【インフラ】Linuxコマンド、シェルスクリプト集

Posted at

内容

  • ネットワークコマンド
  • サーバコマンド

ネットワークコマンド

◆ netstat -anp

  • ポート利用状況取得
$ netstat -anp
 Proto     Local Address         Foreign Address      State
  TCP        0.0.0.0:53             0.0.0.0:0        LISTENING
  TCP        0.0.0.0:80             0.0.0.0:0        LISTENING 

◆ ipconfig 

  • ipconfig:Windowsのコマンド環境
  • ifconfig:UNIXのコマンド環境
//ネットワーク環境の確認
$ ipconfig /all
$ ipconfig addr show

◆ hostname

  • サーバホスト名を確認する
$ hostname
$ uname -n
$ uname -a //詳細表示

route

◆ ルーティングテーブルの内容表示

  • メトリック:メトリックの値の小さい経路が最適な宛先ルートとしてルーティングテーブルに登録される
$ route print
Network Destination   Netmask    Gateway       Interface   Metric
    0.0.0.0          0.0.0.0   192.168.1.254  192.168.1.10   1

◆ ルーティング追加(Linux)

//IPアドレス:192.168.30.0 ゲートウェイ:192.168.1.254  サブネットマスク:255.255.255.0
$ route add -net 192.168.30.0 gw 192.168.1.254 metric 1 netmask 255.255.255.0 eth0

サーバコマンド

◆ w

  • 現在のサーバの状態を簡易出力する
$ w
 16:40:10 up  1:26,  1 user,  load average: 0.00, 0.01, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
vagrant  pts/0    10.0.2.2         15:28    0.00s  0.17s  0.00s w

◆ vmstat

  • 各種リソースの使用状況を表示する
$ vmstat 1 3   //1秒単位で3プロセス表示
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0  59188 140888 162272 1216520    3    3     6    88    6    7  2  1 94  3  0
 0  0  59188 140880 162272 1216548    0    0     0     0  186  366  1  0 99  0  0
 0  0  59188 140880 162272 1216548    0    0     0     0  168  362  1  1 99  0  0

◆ iostat

  • オプション"-c"でCPU使用率表示
  • オプション"-d"でI/Oデバイスの使用状況表示
$ iostat
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
vda               0.46         2.63         9.55    2239142    8134170
vdb               0.00         0.00         0.00       1754          8

参考文献

2
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
8