1.软文推荐

2.软文推荐

3.软文推荐

Linux系统中ss命令用于获取 socket 统计信息,它显示的内容和 netstat 类似,但是ss命令更快,够显示更多更详细的有关 TCP 和连接状态的信息,下面为大家分享一下Linux系统ss命令具体使用方法。

常用选项
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Usage: ss [ OPTIONS ]        ss [ OPTIONS ] [ FILTER ]    -h, --help           this message    -V, --version        output version information    -n, --numeric        don't resolve service names    -r, --resolve       resolve host names    -a, --all            display all sockets    -l, --listening      display listening socket    -o, --options       show timer information    -e, --extended      show detailed socket information    -m, --memory        show socket memory usage    -p, --processes      show process using socket    -i, --info           show internal TCP information    -s, --summary        show socket usage summary    -4, --ipv4          display only IP version 4 sockets    -6, --ipv6          display only IP version 6 sockets    -0, --packet display PACKET sockets    -t, --tcp            display only TCP sockets    -u, --udp            display only UDP sockets    -d, --dccp           display only DCCP sockets    -w, --raw            display only RAW sockets    -x, --unix           display only Unix domain sockets    -f, --family=FAMILY display sockets of type FAMILY    -A, --query=QUERY, --socket=QUERY        QUERY := {all|inet|tcp|udp|raw|unix|packet|netlink}[,QUERY]    -D, --diag=FILE      Dump raw information about TCP sockets to FILE    -F, --filter=FILE   read filter information from FILE        FILTER := [ state TCP-STATE ] [ EXPRESSION ]
ss命令应用实例

实例1:显示TCP连接

命令:

ss -t -a

输出:

[root@localhost ~]# ss -t -aState   Recv-Q Send-Q                Local Address:Port                  Peer Address:Port  LISTEN   0   0                     127.0.0.1:smux                        :    LISTEN   0   0                         *:3690                        :    LISTEN   0   0                         *:ssh                        :    ESTAB   0   0                  192.168.120.204:ssh                    10.2.0.68:49368  [root@localhost ~]#

说明:

实例2:显示 Sockets 摘要

命令:

ss -s

输出:

[root@localhost ~]# ss -sTotal: 34 (kernel 48)TCP:  4 (estab 1, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 3

Transport Total   IP    IPv6*     48    –     –    RAW    0     0     0    UDP    5     5     0    TCP    4     4     0    INET   9     9     0    FRAG   0     0     0    

[root@localhost ~]#

说明:

列出当前的established, closed, orphaned and waiting TCP sockets

实例3:列出所有打开的网络连接端口

命令:

ss -l

输出:

[root@localhost ~]# ss -lRecv-Q Send-Q                   Local Address:Port                     Peer Address:Port  0   0                       127.0.0.1:smux                          :    0   0                           *:3690                          :    0   0                           *:ssh                           :    [root@localhost ~]#

说明:

实例4:查看进程使用的socket

命令:

ss -pl

输出:

[root@localhost ~]# ss -plRecv-Q Send-Q                   Local Address:Port                     Peer Address:Port  0   0                       127.0.0.1:smux                          :    users:((“snmpd”,2716,8))0   0                           *:3690                          :    users:((“svnserve”,3590,3))0   0                           *:ssh                           :    users:((“sshd”,2735,3))[root@localhost ~]#

说明:

实例5:找出打开套接字/端口应用程序

命令:

ss -lp | grep 3306

输出:

[root@localhost ~]# ss -lp|grep 19350   0              *:1935             :    users:((“fmsedge”,2913,18))0   0          127.0.0.1:19350             :    users:((“fmsedge”,2913,17))[root@localhost ~]# ss -lp|grep 33060   0              *:3306             :    users:((“mysqld”,2871,10))[root@localhost ~]#

说明:

实例6:显示所有UDP Sockets

命令:

ss -u -a

输出:

[root@localhost ~]# ss -u -aState   Recv-Q Send-Q                Local Address:Port                  Peer Address:Port  UNCONN   0   0                     127.0.0.1:syslog                       :    UNCONN   0   0                         *:snmp                        :    ESTAB   0   0                  192.168.120.203:39641                 10.58.119.119:domain [root@localhost ~]#

说明:

实例7:显示所有状态为established的SMTP连接

命令:

ss -o state established ‘( dport = :smtp or sport = :smtp )’

输出:

[root@localhost ~]# ss -o state established ‘( dport = :smtp or sport = :smtp )’ Recv-Q Send-Q                   Local Address:Port                     Peer Address:Port  [root@localhost ~]#

说明:

实例8:显示所有状态为Established的HTTP连接

命令:

ss -o state established ‘( dport = :http or sport = :http )’

输出:

[root@localhost ~]# ss -o state established ‘( dport = :http or sport = :http )’ Recv-Q Send-Q                   Local Address:Port                     Peer Address:Port  0   0                       75.126.153.214:2164                    192.168.10.42:http  [root@localhost ~]#

说明:

实例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.113State   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:httpState   Recv-Q Send-Q                Local Address:Port                  Peer Address:Port  [root@localhost ~]# ss dst 192.168.119.113:3844State   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:16021State   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 ge : 大于或等于端口号

== or eq : 等于端口号

!= or ne : 不等于端口号

> or lt : 大于端口号

实例14:ss 和 netstat 效率对比

命令:

time netstat -at

time ss

输出:

[root@localhost ~]# time ss  real  0m0.739suser  0m0.019ssys   0m0.013s[root@localhost ~]# [root@localhost ~]# time netstat -atreal  2m45.907suser  0m0.063ssys   0m0.067s[root@localhost ~]#

总结

至此关于Linux系统ss命令的使用方法分享结束,大家如果对ss命令的使用方法还有疑问可以通过评论区将问题提交给我们。

以上就是良许教程网为各位朋友分享的Linux系统相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你!

本文来源:www.lxlinux.net/2581.html,若引用不当,请联系修改。

相关文章 8

1

Linux安装-云服务器 2分钟前

大家在学习Linux的时候一般都会使用虚拟机进行学习,但是自己安装虚拟机比较麻烦,所以还有一部分人使用云服务器,比较方便,价格也不...

2

seo网推广优化(seo 网站推广) 2分钟前

目录:1、SEO如何优化推广2、SEO网站优化推广是什么意思3、如何做seo网络推广?4、seo优化推广怎么做SEO如何优化推广 SEO 优化大致包含4个方...

3

SQL Server 跨数据库查询具体方法 3分钟前

有时会遇到一段语句里操作不同的服务器上的不同的数据库里的不同的表的情况,这就涉及到跨数据库查询,本篇文章重点为大家讲解一下...

4

10g服务器(服务器10g网卡) 5分钟前

目录:1、高防服务器10G防御这些有什么用2、10G高防服务器防御够用吗3、10g高防服务器需要多少流量攻击高防服务器10G防御这些有什么用 ...

5

Linux系统查看GCC编译器版本命令 5分钟前

GCC 编译器是Linux下最常用的C/C++编译器,它以 gcc 命令的形式呈现,那么在Linux系统中如何查看Gcc版本号?下面良许教程网为大家分享一下Lin...

6

新店手机淘宝搜索优化怎么做(淘宝如何做搜索优化) 6分钟前

目录:1、优化淘宝搜索seo方法2、淘宝新开店铺如何运营 淘宝自然搜索流量优化方法3、淘宝新店如何运营 自然搜索流量优化方法4、淘宝店...

7

Linux中安装Flash具体方法 8分钟前

Flash是一种动画创作与应用程序开发于一身的创作软件,为创建数字动画、交互式Web站点、桌面应用程序以及手机应用程序开发提供了功能全...

8

Linux下按进程实时统计网络带宽利用率-NetHogs 9分钟前

NetHogs是终端中一个网络流量监控工具,它可以显示每个进程的带宽占用情况,能清晰的观察网络使用情况,NetHogs可以支持IPv4 和 IPv6 协议、...