26
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

今更なnetstatとss

Posted at

ときおり、netstatのオプションを忘れて -a でgrepしちゃってダサいので、メモ。

オプションは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                         
26
16
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
26
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?