linux 下 ss命令详解
2014-03-25 11:19
423 查看
ss命令和netstat类似,用来显示socket统计信息。能够列出PACKET sockets、TCP sockets、 UDP sockets、DCCP sockets、RAW sockets、Unix域名sockets等统计信息。支持像netstat命令一样显示。和其他工具相比,ss能够显示更多的TCP和描述信息。作为一个非常有用快捷的跟踪TCP连接和套接字的工具。ss提供如下信息: 所有的TCP套接字。 所有的UDP套接字。 所有建立连接的如:ssh / ftp / http / https 的连接信息。 所有连接到X sever的本地进程。 过滤类似状态(connected, synchronized, SYN-RECV, SYN-SENT,TIME-WAIT)。地址和端口。 所有TCP套接字如FIN-WAIT-1等。 大多数linux发行版本包含了ss及其它一些监控工具,帮助你理解系统sockets在做什么,及找到可能导致性能问题的原因。示例: 显示 Sockets 摘要 列出当前的established, closed, orphaned and waiting TCP sockets:# 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 :::*
通过以下命令查看进程使用的socket:# ss -pl
找出谁负责打开套接字/端口#4949:# 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
示例:显示所有TCP Sockets # ss -t -a
示例:显示所有UDP Sockets# ss -u -a
示例: 显示所有状态为established的SMTP连接# ss -o state established '( dport = :smtp or sport = :smtp )'
示例: 显示所有状态为Established的HTTP连接# ss -o state established '( dport = :http or sport = :http )'
示例: 查找本地所有连接到的进程 X Server# ss -x src /tmp/.X11-unix/*
示例:列出所有状态为FIN-WAIT-1的Tcp Sockets # ss -o state fin-wait-1 '( sport = :http or sport = :https )' dst 202.54.1/24
怎样用TCP 状态过滤Sockets?使用以下参数:## tcp ipv4 ##ss -4 state FILTER-NAME-HERE
## tcp ipv6 ##ss -6 state FILTER-NAME-HERE
FILTER-NAME-HERE 可以代表以下任何一个, establishedsyn-sentsyn-recvfin-wait-1fin-wait-2time-waitclosedclose-waitlast-acklistenclosingall : 所有以上状态connected : 除了listen and closed的所有状态synchronized :所有已连接的状态除了syn-sentbucket : 显示状态为maintained as minisockets,如:time-wait和syn-recv.big : 和bucket相反.例子:输入以下命令查看closing sockets:#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
## 显示所有连接到远程服务器192.168.1.5的端口###ss dst 192.168.1.5
## show all ports connected from remote 192.168.1.5:http port###ss dst 192.168.1.5:http
#ss dst 192.168.1.5:smtp
#ss dst 192.168.1.5:443
Find out connection made by remote 123.1.2.100:http to our local virtual servers:# 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
### find out all ips connected to nixcraft.com ip address 75.126.153.214 ##### Show all ports connected to local 75.126.153.214###ss src 75.126.153.214
## http (80) port only ###ss src 75.126.153.214:http
#ss src 75.126.153.214:80
## smtp (25) port only ###ss src 75.126.153.214:smtp
#ss src 75.126.153.214:25
怎样将本地或者远程端口和一个数比较? 使用以下参数: ## 远程端口和一个数比较##ss dport OP PORT
##本地端口和一个数比较 ##sport OP PORT
OP 可以代表以下任意一个: <= or le : 小于或等于端口号>= or ge : 大于或等于端口号== or eq : 等于端口号!= or ne : 不等于端口号< or gt : 小于端口号> or lt : 大于端口号注意: le, gt, eq, ne etc. are use in unix shell and are accepted as well.例子:###################################################################################### 注意字符问题 ###################################################################################### #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
ss 和 netstat 效率对比用time 命令分别获取通过netstat和ss命令获取程序和概要占用资源所使用的时间: # 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
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 :::*
通过以下命令查看进程使用的socket:# ss -pl
找出谁负责打开套接字/端口#4949:# 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
示例:显示所有TCP Sockets # ss -t -a
示例:显示所有UDP Sockets# ss -u -a
示例: 显示所有状态为established的SMTP连接# ss -o state established '( dport = :smtp or sport = :smtp )'
示例: 显示所有状态为Established的HTTP连接# ss -o state established '( dport = :http or sport = :http )'
示例: 查找本地所有连接到的进程 X Server# ss -x src /tmp/.X11-unix/*
示例:列出所有状态为FIN-WAIT-1的Tcp Sockets # ss -o state fin-wait-1 '( sport = :http or sport = :https )' dst 202.54.1/24
怎样用TCP 状态过滤Sockets?使用以下参数:## tcp ipv4 ##ss -4 state FILTER-NAME-HERE
## tcp ipv6 ##ss -6 state FILTER-NAME-HERE
FILTER-NAME-HERE 可以代表以下任何一个, establishedsyn-sentsyn-recvfin-wait-1fin-wait-2time-waitclosedclose-waitlast-acklistenclosingall : 所有以上状态connected : 除了listen and closed的所有状态synchronized :所有已连接的状态除了syn-sentbucket : 显示状态为maintained as minisockets,如:time-wait和syn-recv.big : 和bucket相反.例子:输入以下命令查看closing sockets:#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
## 显示所有连接到远程服务器192.168.1.5的端口###ss dst 192.168.1.5
## show all ports connected from remote 192.168.1.5:http port###ss dst 192.168.1.5:http
#ss dst 192.168.1.5:smtp
#ss dst 192.168.1.5:443
Find out connection made by remote 123.1.2.100:http to our local virtual servers:# 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
### find out all ips connected to nixcraft.com ip address 75.126.153.214 ##### Show all ports connected to local 75.126.153.214###ss src 75.126.153.214
## http (80) port only ###ss src 75.126.153.214:http
#ss src 75.126.153.214:80
## smtp (25) port only ###ss src 75.126.153.214:smtp
#ss src 75.126.153.214:25
怎样将本地或者远程端口和一个数比较? 使用以下参数: ## 远程端口和一个数比较##ss dport OP PORT
##本地端口和一个数比较 ##sport OP PORT
OP 可以代表以下任意一个: <= or le : 小于或等于端口号>= or ge : 大于或等于端口号== or eq : 等于端口号!= or ne : 不等于端口号< or gt : 小于端口号> or lt : 大于端口号注意: le, gt, eq, ne etc. are use in unix shell and are accepted as well.例子:###################################################################################### 注意字符问题 ###################################################################################### #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
ss 和 netstat 效率对比用time 命令分别获取通过netstat和ss命令获取程序和概要占用资源所使用的时间: # 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
相关文章推荐
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解【转】
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解
- linux sar、ss 命令详解
- Linux网络状态工具ss命令使用详解
- linux sar ss命令详解
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解
- Linux网络状态工具ss命令使用详解
- 11_04_Linux网络配置之四 ifconfig及ip命令详解