Table of Contents
This tip is about the how To Use ss Command in Linux. So read this free guide, How To Use ss Command in Linux step by step. If you have query related to same article you may contact us.
How To Use ss Command in Linux – Guide
ss is a command used to get information about network connections. This is very helpful during the connection troubleshooting process. ss is a command equivalent to the netstat command. It will display detailed information about how your machine interacts with other networks, services and network connections. THE guide about how to use ss command in Linux is given below.
Show all connections:
The ss command with no options displays all connections regardless of their state:
[root@srv ~]# ssNetid State Recv-Q Send-Q Local Address:Port Peer Address:Portu_str ESTAB 0 0 * 39987 * 39988u_str ESTAB 0 0 * 39942 * 39943u_str ESTAB 0 0 * 39984 * 39985u_str ESTAB 0 0 * 39985 * 39984u_str ESTAB 0 8 * 0 * 39957u_str Estat 0 0 * 39990 * 39991u_str Estat 0 0 * 39991 * 39990u_str Estat 0 0 * 39988 * 39987u_str Estat 0 0 * 39957 * 39958u_str Estat 0 0 * 36290 * 36293u_str Estat 0 0 / Run / Systemd / Diary / Stdout 22240 * 22239u_str Estat 0 0 * 39933 * 39932u_str Estat 0 0 * 39978 * 39979u_str Estat 0 0 * 39979 * 39978u_str Estat 0 0 * 39960 * 39961u_str Estat 0 0 * 39976 * 39975u_stra Estat 0 0 * 39949 * 39948u_str Estat 0 0 * 39982 * 39981u_str ESTAB 0 0 * 22239 * 22240u_str ESTAB 0 0 * 39948 * 39949/u_str ESTAB 0 0 * 39981 * 39982
Display listening sockets with ss command:
To display only listening sockets, use the -l option:
[root@srv ~]# ss -lNetid State Recv-Q Send-Q Local Address:Port Peer Address:Portnl UNCONN 0 0 rtnl:kernel *nl UNCONN 0 0 rtnl:NetworkManager/6709 *nl UNCONN 0 0 rtnl:NetworkManager/6709 *nl UNCONN 4352 0 tcpdiag:ss/8647 *nl UNCONN 768 0 tcpdiag:kernel *nl UNCONN 0 0 xfrm:kernel *nl UNCONN 0 0 selinux:kernel *nl UNCONN 0 0 selinux:systemd/1 *nl UNCONN 0 0 selinux:dbus-daemon/ 6600 *nl UNCONN 0 0 selinux:dbus-daemon/6600 *nl UNCONN 0 0 selinux:systemd/1 *nl UNCONN 0 0 audit:kernel *nl UNCONN 0 0 audit:systemd/1 *
Show all TCP connections:
To display only TCP connections, use the -t option:
[root@srv ~]# ss -tState Recv-Q Send-Q Local Address:Port Peer Address:PortESTAB 0 0 192.168.162.140:ssh 192.168.162.1:50870ESTAB 0 48 192.168.162.140:ssh 192.168.162.1:50853Show all connections UDP connections use option -u:
[root@srv ~]# ss -uaState Recv-Q Send-Q Local Address:Port Peer Address:PortUNCONN 0 0 *:bootpc *:*
View all listening UDP connections:
To display listening UDP connections, use the -lu option:
[root@srv ~]# ss -luState Recv-Q Send-Q Local Address:Port Peer Address:PortUNCONN 0 0 *:bootpc *:*
Display the PIDs of the sockets:
To do this, use the –p option:
[root@srv ~]# ss -pNetid State Recv-Q Send-Q Local Address:Port Peer Address:Portu_str ESTAB 0 0 * 39987 * 39988 users:((“master”,pid=7286,fd=81))u_str ESTAB 0 0 * 39942 * 39943 users:((“master”,pid=7286,fd=36))u_str ESTAB 0 0 * 39984 * 39985 users:((“master”,pid=7286,fd=78))u_str ESTAB 0 0 * 39985 * 39984 users:((“master”,pid=7286,fd=79))u_str ESTAB 0 0 * 39958 * 39957 users:((“master”,pid=7286,fd=52))u_str ESTAB 0 0 * 39990 * 39991 users:((“master”,pid=7286,fd=84))u_str ESTAB 0 0 * 39991 * 39990 users:((“master”,pid=7286,fd=85))u_str ESTAB 0 0 * 39988 * 39987 users:((“master”,pid=7286,fd=82))u_str ESTAB 0 0 * 39957 * 39958You can use the grep command to filter matches:[root@srv ~]# ss -p | grep 7286u_str ESTAB 0 0 * 39987 * 39988 users:((“master”,pid=7286,fd=81))u_str ESTAB 0 0 * 39942 * 39943 users:((“master”,pid=7286,fd=36) )u_str ESTAB 0 0 * 39984 * 39985 users:((“master”,pid=7286,fd=78))u_str ESTAB 0 0 * 39985 * 39984 users:((“master”,pid=7286,fd=79) )u_str ESTAB 0 0 * 39958 * 39957 users:((“master”,pid=7286,fd=52))u_str ESTAB 0 0 * 39990 * 39991 users:((“master”,pid=7286,fd=84) )u_str ESTAB 0 0 * 39991 * 39990 users:((“master”,pid=7286,fd=85))u_str ESTAB 0 0 * 39988 * 39987 users:((“master”,pid=7286,fd=82) )u_str ESTAB 0 0 * 39957 * 39958 users:((“master”,pid=7286,fd=51))
Statistics with the ss command:
If you want to display a summary of socket statistics, use the -s option:
[root@srv ~]# ss -sTotal: 575 (kernel 969)TCP: 10 (stab 2, closed 1, orphan 0, synrecv 0, timewait 0/0), ports 0Transport Total IP IPv6969 – –RAW 1 0 1UDP 1 1 0TCP 9 4 5INET 11 5 6FRAG 0 0 0
Show IPv4 sockets with ss:
[root@srv ~]# ss -4Netid State Recv-Q Send-Q Local Address:Port Peer Address:Porttcp ESTAB 0 0 192.168.162.140:ssh 192.168.162.1:50870tcp ESTAB 0 48 192.168.162.140:ssh 192.168.162.1:50853Show socket: IPv6[root@srv ~]#ss-6
Filter Connections by Port Number:
[root@srv ~]# ss -at ‘( dport = :22 or sport = :22 )’State Recv-Q Send-Q Local Address:Port Peer Address:PortLISTEN 0 128 *:ssh *:*ESTAB 0 0 192.168.162.140:ssh 192.168. 162.1: 50870Tab 0 48 192.168.162.140:Sh 192.168.162.14.168.162.14.168.162.168.162.162.168.162.168.168.162.168.1621.168.162.1: 644.162.1: 6441.162.14.168.162.14.168.162.14: 6441.162.14.168.162.140: SSH 192.168.162.1:508.162.1:50853Listen 0 128 ::: ssh ::: *[root@srv ~]#
Final note
I hope you like the guide How To Use ss Command in Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.