{"id":5935,"date":"2018-12-18T16:20:51","date_gmt":"2018-12-18T16:20:51","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=5935"},"modified":"2018-12-28T22:02:01","modified_gmt":"2018-12-28T22:02:01","slug":"using-the-linux-ss-command-to-examine-network-and-socket-connections","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/18\/using-the-linux-ss-command-to-examine-network-and-socket-connections\/","title":{"rendered":"Using the Linux ss command to examine network and socket connections"},"content":{"rendered":"<h3>Want to know more about how your system is communicating? Try the Linux ss command. It replaces the older netstat and makes a lot of information about network connections available for you to easily examine.<\/h3>\n<p>The ss (socket statistics) command provides a lot of information by displaying details on socket activity. One way to get started, although this may be a bit overwhelming, is to use the ss -h (help) command to get a listing of the command&#8217;s numerous options. Another is to try some of the more useful commands and get an idea what each of them can tell you.<\/p>\n<p>One very useful command is the ss -s command. This command will show you some overall stats by transport type. In this output, we see stats for RAW, UDP, TCP, INET and FRAG sockets.<\/p>\n<p>$ ss -s<br \/>\nTotal: 524<br \/>\nTCP: 8 (estab 1, closed 0, orphaned 0, timewait 0)<\/p>\n<p>Transport Total IP IPv6<br \/>\nRAW 2 1 1<br \/>\nUDP 7 5 2<br \/>\nTCP 8 6 2<br \/>\nINET 17 12 5<br \/>\nFRAG 0 0 0<\/p>\n<ul>\n<li>Raw sockets allow direct sending and receiving of IP packets without protocol-specific transport layer formatting and are used for security appliications such as nmap.<\/li>\n<li>TCP provides transmission control protocol and is the primary connection protocol.<\/li>\n<li>UDP (user datagram protocol) is similar to TCP but without the error checking.<\/li>\n<li>INET includes both of the above. (INET4 and INET6 can be viewed separately with some ss commands.)<\/li>\n<li>FRAG \u2014 fragmented<\/li>\n<\/ul>\n<p>Clearly the by-protocol lines above aren&#8217;t displaying the totality of the socket activity. The figure in the Total line at the top of the output indicates that there is a lot more going on than the by-type lines suggest. Still, these breakdowns can be very useful.<\/p>\n<p>If you want to see a list of all socket activity, you can use the ss -a command, but be prepared to see a <i>lot<\/i> of activity \u2014 as suggested by this output. Much of the socket activity on this system is local to the system being examined.<\/p>\n<p>$ ss -a | wc -l<br \/>\n555<\/p>\n<p>If you want to see a specific category of socket activity:<\/p>\n<ul>\n<li>ss -ta dumps all TCP socket<\/li>\n<li>ss -ua dumps all UDP sockets<\/li>\n<li>ss -wa dumps all RAW sockets<\/li>\n<li>ss -xa dumps all UNIX sockets<\/li>\n<li>ss -4a dumps all IPV4 sockets<\/li>\n<li>ss -6a dumps all IPV6 sockets<\/li>\n<\/ul>\n<p>The a in each of the commands above means &#8220;all&#8221;.<\/p>\n<p>The ss command without arguments will display all established connections. Notice that only two of the connections shown below are for external connections \u2014 two other systems on the local network. A significant portion of the output below has been omitted for brevity.<\/p>\n<p>$ ss | more<br \/>\nNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port<br \/>\nu_str ESTAB 0 0 * 20863 * 20864<br \/>\nu_str ESTAB 0 0 * 32232 * 33018<br \/>\nu_str ESTAB 0 0 * 33147 * 3257544ddddy<br \/>\nu_str ESTAB 0 0 \/run\/user\/121\/bus 32796 * 32795<br \/>\nu_str ESTAB 0 0 \/run\/user\/121\/bus 32574 * 32573<br \/>\nu_str ESTAB 0 0 * 32782 * 32783<br \/>\nu_str ESTAB 0 0 \/run\/systemd\/journal\/stdout 19091 * 18113<br \/>\nu_str ESTAB 0 0 * 769568 * 768429<br \/>\nu_str ESTAB 0 0 * 32560 * 32561<br \/>\nu_str ESTAB 0 0 @\/tmp\/dbus-8xbBdjNe 33155 * 33154<br \/>\nu_str ESTAB 0 0 \/run\/systemd\/journal\/stdout 32783 * 32782<br \/>\n\u2026<br \/>\ntcp ESTAB 0 64 192.168.0.16:ssh 192.168.0.6:25944<br \/>\ntcp ESTAB 0 0 192.168.0.16:ssh 192.168.0.6:5385<\/p>\n<p>To see just established tcp connections, use the -t option.<\/p>\n<p>$ ss -t<br \/>\nState Recv-Q Send-Q Local Address:Port Peer Address:Port<br \/>\nESTAB 0 64 192.168.0.16:ssh 192.168.0.6:25944<br \/>\nESTAB 0 0 192.168.0.16:ssh 192.168.0.9:5385<\/p>\n<p>To display only listening sockets, try ss -lt.<\/p>\n<p>$ ss -lt<br \/>\nState Recv-Q Send-Q Local Address:Port Peer Address:Port<br \/>\nLISTEN 0 10 127.0.0.1:submission 0.0.0.0:*<br \/>\nLISTEN 0 128 127.0.0.53%lo:domain 0.0.0.0:*<br \/>\nLISTEN 0 128 0.0.0.0:ssh 0.0.0.0:*<br \/>\nLISTEN 0 5 127.0.0.1:ipp 0.0.0.0:*<br \/>\nLISTEN 0 10 127.0.0.1:smtp 0.0.0.0:*<br \/>\nLISTEN 0 128 [::]:ssh [::]:*<br \/>\nLISTEN 0 5 [::1]:ipp [::]:*<\/p>\n<p>If you&#8217;d prefer to see port number than service names, try ss -ltn instead:<\/p>\n<p>$ ss -ltn<br \/>\nState Recv-Q Send-Q Local Address:Port Peer Address:Port<br \/>\nLISTEN 0 10 127.0.0.1:587 0.0.0.0:*<br \/>\nLISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:*<br \/>\nLISTEN 0 128 0.0.0.0:22 0.0.0.0:*<br \/>\nLISTEN 0 5 127.0.0.1:631 0.0.0.0:*<br \/>\nLISTEN 0 10 127.0.0.1:25 0.0.0.0:*<br \/>\nLISTEN 0 128 [::]:22 [::]:*<br \/>\nLISTEN 0 5 [::1]:631 [::]:*<\/p>\n<p>Plenty of help is available for the ss command either through the man page or by using the -h (help) option as shown below:<\/p>\n<p>$ ss -h<br \/>\nUsage: ss [ OPTIONS ]<br \/>\nss [ OPTIONS ] [ FILTER ]<br \/>\n-h, &#8211;help this message<br \/>\n-V, &#8211;version output version information<br \/>\n-n, &#8211;numeric don&#8217;t resolve service names<br \/>\n-r, &#8211;resolve resolve host names<br \/>\n-a, &#8211;all display all sockets<br \/>\n-l, &#8211;listening display listening sockets<br \/>\n-o, &#8211;options show timer information<br \/>\n-e, &#8211;extended show detailed socket information<br \/>\n-m, &#8211;memory show socket memory usage<br \/>\n-p, &#8211;processes show process using socket<br \/>\n-i, &#8211;info show internal TCP information<br \/>\n&#8211;tipcinfo show internal tipc socket information<br \/>\n-s, &#8211;summary show socket usage summary<br \/>\n-b, &#8211;bpf show bpf filter socket information<br \/>\n-E, &#8211;events continually display sockets as they are destroyed<br \/>\n-Z, &#8211;context display process SELinux security contexts<br \/>\n-z, &#8211;contexts display process and socket SELinux security contexts<br \/>\n-N, &#8211;net switch to the specified network namespace name<\/p>\n<p>-4, &#8211;ipv4 display only IP version 4 sockets<br \/>\n-6, &#8211;ipv6 display only IP version 6 sockets<br \/>\n-0, &#8211;packet display PACKET sockets<br \/>\n-t, &#8211;tcp display only TCP sockets<br \/>\n-S, &#8211;sctp display only SCTP sockets<br \/>\n-u, &#8211;udp display only UDP sockets<br \/>\n-d, &#8211;dccp display only DCCP sockets<br \/>\n-w, &#8211;raw display only RAW sockets<br \/>\n-x, &#8211;unix display only Unix domain sockets<br \/>\n&#8211;tipc display only TIPC sockets<br \/>\n&#8211;vsock display only vsock sockets<br \/>\n-f, &#8211;family=FAMILY display sockets of type FAMILY<br \/>\nFAMILY :=<\/p>\n<p>-K, &#8211;kill forcibly close sockets, display what was closed<br \/>\n-H, &#8211;no-header Suppress header line<\/p>\n<p>-A, &#8211;query=QUERY, &#8211;socket=QUERY<br \/>\nQUERY := [,QUERY]<\/p>\n<p>-D, &#8211;diag=FILE Dump raw information about TCP sockets to FILE<br \/>\n-F, &#8211;filter=FILE read filter information from FILE<br \/>\nFILTER := [ state STATE-FILTER ] [ EXPRESSION ]<br \/>\nSTATE-FILTER :=<br \/>\nTCP-STATES := |time-wait|closed|close-wait|last-ack|listening|closing}<br \/>\nconnected := |time-wait|close-wait|last-ack|closing}<br \/>\nsynchronized := |time-wait|close-wait|last-ack|closing}<br \/>\nbucket :=<br \/>\nbig := |closed|close-wait|last-ack|listening|closing}<\/p>\n<p>The ss command clearly offers a huge range of options for examining sockets, but you still might want to turn those that provide you with the most useful information into aliases to make them more memorable. For example:<\/p>\n<p>$ alias listen=&#8221;ss -lt&#8221;<br \/>\n$ alias socksum=&#8221;ss -s&#8221;<\/p>\n<p><a href=\"https:\/\/www.networkworld.com\/article\/3327557\/linux\/using-the-linux-ss-command-to-examine-network-and-socket-connections.html\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Want to know more about how your system is communicating? Try the Linux ss command. It replaces the older netstat and makes a lot of information about network connections available for you to easily examine. The ss (socket statistics) command provides a lot of information by displaying details on socket activity. One way to get &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/18\/using-the-linux-ss-command-to-examine-network-and-socket-connections\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using the Linux ss command to examine network and socket connections&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5935","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/5935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=5935"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/5935\/revisions"}],"predecessor-version":[{"id":6550,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/5935\/revisions\/6550"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=5935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=5935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=5935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}