地方エンジニアの学習日記

興味ある技術の雑なメモだったりを書いてくブログ。たまに日記とガジェット紹介。

【Linux】SSコマンドで取れない統計情報 netstat

milestone-of-se.nesuke.com

オプションはnetstatもssもほぼ同じ。

       -l, --listening リッスンしているやつ
       -n, --numeric   ポートやナマのIPで表示
       -t, --tcp       TCPを表示
       -u, --udp       UDPを表示
       -x, --unix      UNIX Domainソケットを表示

TCPのやつを表示する場合は -ltn で。

$ netstat -ltn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN

$ ss -ltn
State      Recv-Q Send-Q                     Local Address:Port                       Peer Address:Port
LISTEN     0      100                                   :::110                                  :::*
LISTEN     0      100                                    *:110                                   *:*
LISTEN     0      100                                   :::143                                  :::*
LISTEN     0      100                                    *:143                                   *:*
LISTEN     0      128                                   :::111                                  :::*

-p は netstat と ss は微妙に違っているけど、気にしない。

$ netstat -p
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  
tcp        0      0 frank:ssh                   epitaph:49943               ESTABLISHED 8761/sshd         
tcp        0     96 frank:ssh                   epitaph:58700               ESTABLISHED 12097/sshd        
tcp        0      0 frank:ssh                   epitaph:59786               ESTABLISHED 3962/sshd         
tcp        0      0 frank:ssh                   epitaph:51301               ESTABLISHED 9383/sshd         
tcp        0      0 frank:ssh                   epitaph:54043               ESTABLISHED 1680/sshd

$ ss -p
State      Recv-Q Send-Q                   Local Address:Port                       Peer Address:Port
ESTAB      0      0                         192.168.0.40:ssh                         192.168.0.3:49943    users:(("sshd",8761,3))
ESTAB      0      96                        192.168.0.40:ssh                         192.168.0.3:58700    users:(("sshd",12097,3))
ESTAB      0      0                         192.168.0.40:ssh