网络状态检测的利器 - ss命令
发布日期:2021-05-14 06:27:15 浏览次数:17 分类:博客文章

本文共 14147 字,大约阅读时间需要 47 分钟。

ss��������������� socket statistic������������������������Linux���������socket���������������������������������������������������ss������������������������������ TCP������������������������

������

ss [ OPTIONS ]

���Linux��������������������������������� ss ������,������������������������������������������

ss ��� netstat ������

netstat ��������� ss ������������������������������������������������������socket������������������ netstat���������ss ���������������TCP������������������������������������������������������������������ ss ��� netstat ���������������������

[cgyx@cghost35 ~]$ time ss -a | wc -l439real    0m0.014suser    0m0.004ssys     0m0.010s[cgyx@cghost35 ~]$ time netstat -a | wc -l366real    0m0.029suser    0m0.005ssys     0m0.008s

������������������������������ss ������439���socket���������������0.014s, netstat ������366���socket���������������0.029s���ss ������������������������������������������������������������������ ss ������ netstat

���������������������

���������������������������������������������TCP������,������������������������������������������������������������������������������������������������������������������������������������������������

[root@ecs-centos-7 ~]# ss -sTotal: 185 (kernel 264)TCP:   7 (estab 2, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 0Transport Total     IP        IPv6*         264       -         -         RAW       0         0         0        UDP       7         4         3        TCP       7         4         3        INET      14        8         6        FRAG      0         0         0

������������������

������������������������������ss������������������������������������������������������������������,������������������������,������������������������������������

[root@ecs-centos-7 ~]# ssNetid  State      Recv-Q Send-Q                 Local Address:Port                                  Peer Address:Port u_str ESTAB      0      0                         /run/dbus/system_bus_socket 12050                 * 11962tcp    ESTAB      0      0                        192.168.0.9:ssh                                   27.38.240.56:ssm-cssps            tcp    ESTAB      0      4200                     192.168.0.9:ssh                                   27.38.240.56:rsmtp                tcp    ESTAB      0      0                        192.168.0.9:ssh                                   27.38.240.56:pearldoc-xact

���������������������������

  • Netid

socket������������������������������������ TCP���u_str���unix������������������

  • State

���������������������������������������TCP���������������������������������, ���������������TCP���������������������������������������������

LISTEN:  ������������������������������������������������SYN-SENT: ������������������������������������������������������������������������������SYN-RECEIVED: ���������������������������������������������������������������������������������������ESTABLISHED: ������������������������������������������������������������������������������������������FIN-WAIT-1: ���������������������������close������������������������������������������������������,���������������������������������������������������FIN-WAIT-2: ���������������������������������������������������������������������������������������������������������������������������������������TCP������������������������������������������������������������������������CLOSE-WAIT: ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������TCP������������������������������������������������������������������������CLOSING: ������������������������������������������������������(������close������)������������,������������������������������������������������������������������������������������������������������������������������������������������������������������CLOSING���������������CLOSING������������,������������������������������������������������������������������������TIME-WAIT���������������CLOSING���������������������������������,���������������������LAST-ACK: ������������������������������������������,������������������������������������������������������������������������������������������������������������TIME-WAIT: ������������������������������������������������������������������������������������������������������������������������,������������������������������������������������������������������������������������������������������CLOSED: ���������������������������������������������������
  • Recv-Q

��� ESTAB ������������������������������������������������������������������������������������������������������������������������������������������������

  • Send-Q

��� ESTAB ���������������������������������������������������������������������������������������ACK������������������������������������������������������������������������������

  • Local Address:Port

���������������������

  • Peer Address:Port

���������������������

������������������������������

������ -l ������������������������������������(LISTEN)������������������

[root@ecs-centos-7 ~]# ss -lNetid  State    Recv-Q Send-Q   Local Address:Port  Peer Address:Port  tcp    LISTEN     0      100    127.0.0.1:smtp          *:*                    tcp    LISTEN     0      128    *:ssh                   *:*                    tcp    LISTEN     0      100    [::1]:smtp              [::]:*                    tcp    LISTEN     0      254    [::]:mysql              [::]:*                    tcp    LISTEN     0      128    [::]:ssh                [::]:*

������������������������

������ -a������������������������������������������������������������������������������������������������������������������������������������

[root@ecs-centos-7 ~]# ss -aNetid  State      Recv-Q Send-Q         Local Address:Port  Peer Address:Porttcp    LISTEN     0      100              127.0.0.1:smtp        *:*                    tcp    LISTEN     0      128               *:ssh                *:*                    tcp    ESTAB      0      16644            192.168.0.9:ssh      27.38.240.99:21669  tcp    ESTAB      0      0                192.168.0.9:ssh    27.38.240.103:kyoceranetdev        tcp    LISTEN     0      100              [::1]:smtp            [::]:*                    tcp    LISTEN     0      254              [::]:mysql            [::]:*                    tcp    LISTEN     0      128              [::]:ssh              [::]:*

������������������������

������������ TCP���UDP���Unix���Raw���IPV4���IPV6 ������������������������������������������������������TCP/UDP/IPV4������������������

ss -ua : ������Unix���������ss -wa : ������Raw���������ss -6a : ������IPV6���������
  • TCP���������

������ -t ������(TCP), ������������������TCP���������

[root@ecs-centos-7 ~]# ss -a -tState      Recv-Q Send-Q                    Local Address:Port                                     Peer Address:Port                LISTEN     0      100                           127.0.0.1:smtp                                                *:*                    LISTEN     0      128                                   *:ssh                                                 *:*                    ESTAB      0      52                          192.168.0.9:ssh                                      27.38.240.99:21787                ESTAB      0      0                           192.168.0.9:ssh                                      27.38.240.99:21669                ESTAB      0      0                           192.168.0.9:ssh                                     27.38.240.103:kyoceranetdev        LISTEN     0      100                               [::1]:smtp                                             [::]:*                    LISTEN     0      254                                [::]:mysql                                            [::]:*                    LISTEN     0      128                                [::]:ssh                                              [::]:*
  • UDP���������

������ -u ������(UCP), ������������������UCP���������

[root@ecs-centos-7 ~]# ss -a -uState      Recv-Q Send-Q                    Local Address:Port                                     Peer Address:Port                UNCONN     0      0                                     *:bootpc                                              *:*                    UNCONN     0      0                           192.168.0.9:ntp                                                 *:*                    UNCONN     0      0                             127.0.0.1:ntp                                                 *:*                    UNCONN     0      0                                     *:ntp                                                 *:*                    UNCONN     0      0      [fe80::f816:3eff:fee0:4fb8]%eth0:ntp                                              [::]:*                    UNCONN     0      0                                 [::1]:ntp                                              [::]:*                    UNCONN     0      0                                  [::]:ntp                                              [::]:*
  • ipv4 ���������

������ -4 ������(IPV4), ������������������IPV4������������

[root@ecs-centos-7 ~]# ss -4aNetid  State      Recv-Q Send-Q                 Local Address:Port                                  Peer Address:Port                udp    UNCONN     0      0                                  *:bootpc                                           *:*                    udp    UNCONN     0      0                        192.168.0.9:ntp                                              *:*                    udp    UNCONN     0      0                          127.0.0.1:ntp                                              *:*                    udp    UNCONN     0      0                                  *:ntp                                              *:*                    tcp    LISTEN     0      100                        127.0.0.1:smtp                                             *:*                    tcp    LISTEN     0      128                                *:ssh                                              *:*                    tcp    ESTAB      0      0                        192.168.0.9:ssh                                   27.38.240.99:21787

������������������

��������������������������������������������������������������������������������������������������������������������������� -p ������

[root@ecs-centos-7 ~]# ss -a -t -pState      Recv-Q Send-Q                    Local Address:Port                                     Peer Address:Port LISTEN     0      254                                [::]:mysql                                            [::]:*

������������������������Local Address:Port ������������������������������������mysql��������������������������� -p���������������������������������mysql������������3306

������������������������������

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

  • ������������������
[root@ecs-centos-7 ~]# ss -ap sport eq 3306Netid  State      Recv-Q Send-Q                 Local Address:Port                                  Peer Address:Port                tcp    LISTEN     0      254                             [::]:mysql                                         [::]:*

���������������������sport ��������������������� dport ���������������������������������3306������������������������������������������3306���mysql���������

������������������������������������������������������������������������������������,������������������������

ss -ap sport le 3306 : ������������������������������3306������������ss -ap sport lt 3306 ���������������������������3306������������ss -ap sport ge 3306 : ������������������������������3306������������ss -ap sport gt 3306 : ������������������������3306������������ss -ap sport ne 3306 : ���������������������������3306������������
  • ���������������������
[root@ecs-centos-7 ~]# ss -an sport eq mysqlNetid  State      Recv-Q Send-Q                 Local Address:Port                                  Peer Address:Port                tcp    LISTEN     0      254                             [::]:3306                                         [::]:*

���������������������������������������mysql������������, ������������������ -n������������������������������������������������������������������������������������������������������

������IP������������

  • ������������������������

������������������������������IP���������27.38.240.99���������������dst ���������������

[root@ecs-centos-7 ~]# ss -a dst 27.38.240.99Netid  State      Recv-Q Send-Q                 Local Address:Port                                  Peer Address:Port                tcp    ESTAB      0      52                       192.168.0.9:ssh                                   27.38.240.99:21907                tcp    ESTAB      0      0                        192.168.0.9:ssh                                   27.38.240.99:21787                tcp    ESTAB      0      0                        192.168.0.9:ssh                                   27.38.240.99:23260                tcp    ESTAB      0      0                        192.168.0.9:ssh                                   27.38.240.99:22810
  • ���������������������

���������������������������IP���������192.168.0.99���������������src ������������

[root@ecs-centos-7 ~]# ss -a src 192.168.0.9Netid  State      Recv-Q Send-Q                 Local Address:Port                                  Peer Address:Port                udp    UNCONN     0      0                        192.168.0.9:ntp                                              *:*                    tcp    ESTAB      0      52                       192.168.0.9:ssh                                   27.38.240.99:21907                tcp    ESTAB      0      0                        192.168.0.9:ssh                                   27.38.240.99:21787                tcp    ESTAB      0      0                        192.168.0.9:ssh                                   27.38.240.99:23260
上一篇:Linux 软链接和硬链接
下一篇:Linux不同时钟的区别

发表评论

最新留言

感谢大佬
[***.8.128.20]2025年04月27日 10时42分51秒