Linux how to use the ss command to view the socket status

  

Linux system, ss command can be used to view the status of the system socket, and socket as the system's process communication mechanism, it is necessary to understand its status, the following small series will give Everyone introduces how Linux uses the ss command to check the status of the socket.

ss Socket Statistics is an abbreviation. As the name suggests, the ss command can be used to get socket statistics, which can display something similar to netstat. But the advantage of ss is that it can display more detailed information about TCP and connection status, and is faster and more efficient than netstat. When the number of socket connections on the server becomes very large, the execution speed will be slow regardless of whether the netstat command or cat /proc/net/tcp is used. Maybe you won't have a personal feeling, but believe me, when the server maintains tens of thousands of connections, using netstat is a waste of life, and using ss is time saving. UI. The secret of ss is that it uses tcp_diag in the TCP stack. Tcp_diag is a module for analyzing statistics, which can get the first-hand information in the Linux kernel, which ensures the fast and efficient ss. Of course, if you don't have tcp_diag in your system, ss will work fine, but the efficiency will be a bit slower. (but still faster than netstat.)

1. Command format:

ss [parameters]

ss [parameters] [filter]

2 Command function:

The ss (short for Socket Statistics) command can be used to obtain socket statistics. The output of this command is similar to the output of netstat, but it can display more detailed TCP connection status. Information and faster and more efficient than netstat. It uses tcp_diag (a module for analyzing statistics) in the TCP protocol stack, which can get the first-hand kernel information directly, which makes the ss command fast and efficient. In the absence of tcp_diag, ss can also run normally.

3. Command Parameters:

-h, --help Help Information

-V, --version Program Version Information

-n, - -numeric does not resolve service name

-r, --resolve resolve hostname

-a, --all displays all sockets (sockets)

-l, --listening Sockets that display listening status

-o, --options Display timer information

-e, --extended Display detailed sockets (sockets) Information

-m, --memory Shows the memory usage of sockets

-p, --processes shows the process using sockets

-i, --info Display TCP internal information

-s, --summary Display socket (usage) usage overview

-4, --ipv4 Display only IPv4 sets Sockets

-6, --ipv6 Show only IPv6 sockets (sockets)

-0, --packet Display PACKET sockets (sockets)

-t, --tcp show only TCP sockets (sockets)

-u, --udp only shows UCP sockets (sockets)

-d, --dccp shows only DCCP sockets (sockets)

-w, --raw shows only RAW sockets (sockets)

-x, --unix shows only Unix sockets (sockets)

-f, --family=FAMILY shows FAMILY types Sockets, FAMILY optional, support for unix, inet, inet6, link, netlink

-A, --query=QUERY, --socket=QUERY

QUERY : = {all| Inet| Tcp| Udp| Raw| Unix| Packet| Netlink}[,QUERY]

-D, --diag=FILE Dump raw TCP sockets information to a file

-F, --filter=FILE From file Filter information in the middle

FILTER := [ state TCP-STATE ] [ EXPRESSION ]

4. Use case:

Example 1: Display TCP connection

Command: ss -t -a

Output:

The code is as follows:

[root@localhost ~]# ss -t -a

State 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 ~]#

Example 2: Display Sockets Summary

Command: ss -s

Output:
Previous123Next Page Total 3 Pages

Copyright © Windows knowledge All Rights Reserved