netstat
command-line tool was one of the tools that system administrators often used. However, the netstat
team was recognized as outdated and replaced by a faster and more convenient ss
command to use.ss
in order to learn about what is happening with the network on a computer running Linux.ss
command is a tool used to display network statistics in a form similar to that issued by the netstat
command. However, ss
makes it easier and faster than netstat
. In addition, ss
provides more information about TCP connections and connection states than most other tools. In particular, ss
can output data about entities such as PACKET, TCP, UDP, DCCP, RAW, and Unix domain sockets. The ss
command is simpler than netstat
. in order to verify this, it is enough to compare the man
pages of these two tools. With ss
you can get very detailed information about how a machine running Linux communicates with other computers. All this opens up possibilities for diagnosing and fixing various network errors.ss
command works just like any other Linux command line utility. Namely, the name of the corresponding executable file is entered on the command line, followed by the required combination of options. If you take a look at the ss
help page (you can call it with the command man ss
), you will notice that there are much fewer command line keys here than netstat
. However, this does not mean scant ss
opportunities. In fact, we have a very powerful tool.ss
with no command line arguments or options, it will display a complete list of working connections.ss
command (without options) shows a lot of data (details on all connections established via TCP, UDP, and using Unix sockets), you can send the output of this command to a file in order to analyze it later. This is done, for example, as follows: ss > ss_output
-l
option: ss -l
-t
option allows you to view information on TCP connections, the -u
option is used to display data on UDP connections, the -x
option displays data on Unix connections. It looks like this: ss -t
, ss -u
, or ss -x
. Any of these commands will display a large amount of data that can be analyzed.-t
, -u
or -x
options will display only the data on the established connections. If you want to select connections that are waiting for connections, you need to add the -a
option to the command call: ss -t -a
netstat
command, ss
does not display the PID and the name of the command responsible for a particular connection. However, even with this in mind, we have at our disposal a lot of data for searching for network errors. If something is under suspicion, ss
will let you know the details of the connection, and therefore, give the administrator information that will be useful in the early stages of solving network problems.ss
command is that it can filter the output using TCP states (or connection lifecycle states). By using states, ss
output filtering is facilitated. Namely, all standard TCP states are available here:established
syn-sent
syn-recv
fin-wait-1
fin-wait-2
time-wait
closed
close-wait
last-ack
listening
closing
ss
recognizes the following state identifiers:all
(all of the above)connected
(all states except pending and closed)synchronized
(all states corresponding to the established connections, except for syn-sent
)bucket
(states representing mini-sockets, for example - time-wait
and syn-recv
)big
(all except the bucket
id) ss -4 state FILTER
ss -6 state FILTER
FILTER
is a state identifier. ss -4 state listening
ss
is to get information on connections established from certain IP addresses using this command. Suppose you need to find out whether the machine is connected, say, with the IP address 192.168.1.139 to our server, and if this is the case, learn more about it. To solve this problem, this command is suitable: ss dst 192.168.1.139
ss
utility can be very useful in finding and troubleshooting network problems for Linux servers. Of course, in order to fully master ss
, it would be nice to read man
and practice. However, you now have an idea of how to use this command, which a modern Linux administrator just needs to know.Source: https://habr.com/ru/post/346744/
All Articles