ss: 查看 Linux TCP / UDP 网络和套接字信息
by: VIVEK GITE on JUNE 2, 2009
source:http://www.cyberciti.biz/tips/linux-investigate-sockets-network-connections.html
- # ss -s
- Total: 734 (kernel 904)
- TCP: 1415 (estab 112, closed 1259, orphaned 11, synrecv 0, timewait 1258/0), ports 566
- Transport Total IP IPv6
- * 904 - -
- RAW 0 0 0
- UDP 15 12 3
- TCP 156 134 22
- INET 171 146 25
- FRAG 0 0 0
- # ss -l
- Recv-Q Send-Q Local Address:Port Peer Address:Port 0 0 *:ndmp *:* 0 0 192.168.122.1:domain *:* 0 0 *:ssh *:* 0 0 :::ssh :::*
- # ss -pl
- # ss -lp | grep 4949
- 0 0 *:4949 *:* users:(("munin-node",3772,5))
- munin-node (PID # 3772) is responsible for opening port # 4949. You can get more information about this process (like memory used, users, current working directory and so on) visiting /proc/3772 directory:
- # cd /proc/3772
- # ls -l
- # ss -t -a
- # ss -u -a
- # ss -o state established '( dport = :smtp or sport = :smtp )'
- # ss -o state established '( dport = :http or sport = :http )'
- # ss -x src /tmp/.X11-unix/*
- # ss -o state fin-wait-1 '( sport = :http or sport = :https )' dst 202.54.1/24
- ss -4 state FILTER-NAME-HERE
- ss -6 state FILTER-NAME-HERE
- #ss -4 state closing
- Recv-Q Send-Q Local Address:Port Peer Address:Port
- 1 11094 75.126.153.214:http 175.44.24.85:4669
- #ss dst ADDRESS_PATTERN
- #ss dst 192.168.1.5
- #ss dst 192.168.1.5:http
- #ss dst 192.168.1.5:smtp
- #ss dst 192.168.1.5:443
- # ss dst 123.1.2.100:http
- State Recv-Q Send-Q Local Address:Port Peer Address:Port
- ESTAB 0 0 75.126.153.206:http 123.1.2.100:35710
- ESTAB 0 0 75.126.153.206:http 123.1.2.100:35758
- #ss src ADDRESS_PATTERN
- #ss src 75.126.153.214
- #ss src 75.126.153.214:http
- #ss src 75.126.153.214:80
- #ss src 75.126.153.214:smtp
- #ss src 75.126.153.214:25
- ss dport OP PORT
- sport OP PORT
- #ss sport = :http
- #ss dport = :http
- #ss dport \> :1024
- #ss sport \> :1024
- #ss sport \< :32000
- #ss sport eq :22
- #ss dport != :22
- #ss state connected sport = :http
- #ss \( sport = :http or sport = :https \)
- #ss -o state fin-wait-1 \( sport = :http or sport = :https \) dst 192.168.1/24
- # time netstat -at
- Sample outputs:
- real 2m52.254s
- user 0m0.178s
- sys 0m0.170s
- Now, try the ss command:
- # time ss
- Sample outputs:
- real 2m11.102s
- user 0m0.124s
- sys 0m0.068s