系统之家 - 系统光盘下载网站!

当前位置:系统之家 > 系统教程 > Linux使用ss命令查看socket状态

Linux如何使用ss命令查看socket状态(3)

时间:2014-12-30 17:51:04 作者:qipeng 来源:系统之家 1. 扫描二维码随时看资讯 2. 请使用手机浏览器访问: https://m.xitongzhijia.net/xtjc/20141230/33791.html 手机查看 评论

  实例9:列举出处于 FIN-WAIT-1状态的源端口为 80或者 443,目标网络为 193.233.7/24所有 tcp套接字

  命令:ss -o state fin-wait-1 ‘( sport = :http or sport = :https )’ dst 193.233.7/24

  实例10:用TCP 状态过滤Sockets:

  命令:

  代码如下:

  ss -4 state FILTER-NAME-HERE

  ss -6 state FILTER-NAME-HERE

  输出:

  代码如下:

  [root@localhost ~]#ss -4 state closing

  Recv-Q Send-Q Local Address:Port Peer Address:Port

  1 11094 75.126.153.214:http 192.168.10.42:4669

  说明:

  FILTER-NAME-HERE 可以代表以下任何一个:

  代码如下:

  established

  syn-sent

  syn-recv

  fin-wait-1

  fin-wait-2

  time-wait

  closed

  close-wait

  last-ack

  listen

  closing

  all : 所有以上状态

  connected : 除了listen and closed的所有状态

  synchronized :所有已连接的状态除了syn-sent

  bucket : 显示状态为maintained as minisockets,如:time-wait和syn-recv.

  big : 和bucket相反。

  实例11:匹配远程地址和端口号

  命令:

  代码如下:

  ss dst ADDRESS_PATTERN

  ss dst 192.168.1.5

  ss dst 192.168.119.113:http

  ss dst 192.168.119.113:smtp

  ss dst 192.168.119.113:443

  输出:

  代码如下:

  [root@localhost ~]# ss dst 192.168.119.113

  State Recv-Q Send-Q Local Address:Port Peer Address:Port

  ESTAB 0 0 192.168.119.103:16014 192.168.119.113:20229

  ESTAB 0 0 192.168.119.103:16014 192.168.119.113:61056

  ESTAB 0 0 192.168.119.103:16014 192.168.119.113:61623

  ESTAB 0 0 192.168.119.103:16014 192.168.119.113:60924

  ESTAB 0 0 192.168.119.103:16050 192.168.119.113:43701

  ESTAB 0 0 192.168.119.103:16073 192.168.119.113:32930

  ESTAB 0 0 192.168.119.103:16073 192.168.119.113:49318

  ESTAB 0 0 192.168.119.103:16014 192.168.119.113:3844

  [root@localhost ~]# ss dst 192.168.119.113:http

  State Recv-Q Send-Q Local Address:Port Peer Address:Port

  [root@localhost ~]# ss dst 192.168.119.113:3844

  State Recv-Q Send-Q Local Address:Port Peer Address:Port

  ESTAB 0 0 192.168.119.103:16014 192.168.119.113:3844

  [root@localhost ~]#

  实例12:匹配本地地址和端口号

  命令:

  代码如下:

  ss src ADDRESS_PATTERN

  ss src 192.168.119.103

  ss src 192.168.119.103:http

  ss src 192.168.119.103:80

  ss src 192.168.119.103:smtp

  ss src 192.168.119.103:25

  输出:

  代码如下:

  [root@localhost ~]# ss src 192.168.119.103:16021

  State Recv-Q Send-Q Local Address:Port Peer Address:Port

  ESTAB 0 0 192.168.119.103:16021 192.168.119.201:63054

  ESTAB 0 0 192.168.119.103:16021 192.168.119.201:62894

  ESTAB 0 0 192.168.119.103:16021 192.168.119.201:63055

  ESTAB 0 0 192.168.119.103:16021 192.168.119.201:2274

  ESTAB 0 0 192.168.119.103:16021 192.168.119.201:44784

  ESTAB 0 0 192.168.119.103:16021 192.168.119.201:7233

  ESTAB 0 0 192.168.119.103:16021 192.168.119.103:58660

  ESTAB 0 0 192.168.119.103:16021 192.168.119.201:44822

  ESTAB 0 0 192.168.119.103:16021 10.2.1.206:56737

  ESTAB 0 0 192.168.119.103:16021 10.2.1.206:57487

  ESTAB 0 0 192.168.119.103:16021 10.2.1.206:56736

  ESTAB 0 0 192.168.119.103:16021 10.2.1.206:64652

  ESTAB 0 0 192.168.119.103:16021 10.2.1.206:56586

  ESTAB 0 0 192.168.119.103:16021 10.2.1.206:64653

  ESTAB 0 0 192.168.119.103:16021 10.2.1.206:56587

  [root@localhost ~]#

  实例13:将本地或者远程端口和一个数比较

  命令:

  代码如下:

  ss dport OP PORT

  ss sport OP PORT

  输出:

  代码如下:

  [root@localhost ~]# ss sport = :http

  [root@localhost ~]# ss dport = :http

  [root@localhost ~]# ss dport \》 :1024

  [root@localhost ~]# ss sport \》 :1024

  [root@localhost ~]# ss sport \《 :32000

  [root@localhost ~]# ss sport eq :22

  [root@localhost ~]# ss dport != :22

  [root@localhost ~]# ss state connected sport = :http

  [root@localhost ~]# ss \( sport = :http or sport = :https \)

  [root@localhost ~]# ss -o state fin-wait-1 \( sport = :http or sport = :https \) dst 192.168.1/24

  说明:

  ss dport OP PORT 远程端口和一个数比较;ss sport OP PORT 本地端口和一个数比较。

  OP 可以代表以下任意一个:

  《= or le : 小于或等于端口号

  》= or ge : 大于或等于端口号

  == or eq : 等于端口号

  != or ne : 不等于端口号

  《 or gt : 小于端口号

  》 or lt : 大于端口号

  实例14:ss 和 netstat 效率对比

  命令:

  代码如下:

  time netstat -at

  time ss

  输出:

  代码如下:

  [root@localhost ~]# time ss

  real 0m0.739s

  user 0m0.019s

  sys 0m0.013s

  [root@localhost ~]#

  [root@localhost ~]# time netstat -at

  real 2m45.907s

  user 0m0.063s

  sys 0m0.067s

  [root@localhost ~]#

  说明:

  用time 命令分别获取通过netstat和ss命令获取程序和概要占用资源所使用的时间。在服务器连接数比较多的时候,netstat的效率完全没法和ss比。

  上面就是Linux使用ss命令查看socket状态的方法介绍了,本文一共介绍了14个使用ss命令的实例,相信通过这个实例讲解,你能对ss命令有一定的了解。

发表评论

0

没有更多评论了

评论就这些咯,让大家也知道你的独特见解

立即评论

以上留言仅代表用户个人观点,不代表系统之家立场

其他版本软件

热门教程

人气教程排行

Linux系统推荐

官方交流群 软件收录