{"id":6966,"date":"2018-10-02T18:47:40","date_gmt":"2018-10-02T15:47:40","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-ss-command\/"},"modified":"2018-10-02T18:47:40","modified_gmt":"2018-10-02T15:47:40","slug":"linux-ss-command-tutorial-for-beginners-8-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-ss-command-tutorial-for-beginners-8-examples\/","title":{"rendered":"Linux ss Command Tutorial for Beginners (8 Examples)"},"content":{"rendered":"<p>When it comes to accessing socket related information through the command line in Linux, the first tool that comes to mind is <a href=\"https:\/\/www.howtoforge.com\/linux-netstat-command\/\" target=\"_blank\" rel=\"noopener noreferrer\">netstat<\/a>. However, there&#8217;s another utility that can do this work for you.<\/p>\n<p>It&#8217;s called <strong>ss<\/strong>. In this tutorial, we will discuss the basics of this tool using some easy to understand examples. But before we do that, it&#8217;s worth mentioning that all examples here have been tested on an Ubuntu 18.04 LTS machine.<\/p>\n<h2 id=\"linux-ss-command\">Linux ss command<\/h2>\n<p>The ss command in Linux allows you to investigate sockets. Following is its syntax:<\/p>\n<p class=\"command\">ss [options] [ FILTER ]<\/p>\n<p>And here&#8217;s what the tool&#8217;s man page says about it:<\/p>\n<pre>ss is used to dump socket statistics. It allows showing information similar to netstat.\u00a0 <br\/>It can display more TCP and state information than other tools.<\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a better idea on how the ss command works.<\/p>\n<h2 id=\"q-how-to-use-ss-command\">Q1. How to use ss command?<\/h2>\n<p>In its very basic form, you can use the ss command by executing &#8216;ss&#8217; sans any option.<\/p>\n<p class=\"command\">ss<\/p>\n<p>Following is the output the command produced in my case:<\/p>\n<p><a class=\"fancybox\" id=\"img-ss-basic-usage\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/ss-basic-usage.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/linux-ss-command-tutorial-for-beginners-8-examples.png\" alt=\"How to use ss command\" width=\"500\" height=\"265\" title=\"\"><\/a><\/p>\n<p>You&#8217;ll noticed that ss displays sockets with established connections in its default output.<\/p>\n<h2 id=\"q-how-to-make-ssnbspsuppress-header-line\">Q2. How to make ss\u00a0suppress header line?<\/h2>\n<p>This can be done using the -H command line option.<\/p>\n<p class=\"command\">ss -H<\/p>\n<p>The following screenshot shows this command line option in action:<\/p>\n<p><a class=\"fancybox\" id=\"img-ss-h-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/ss-h-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/linux-ss-command-tutorial-for-beginners-8-examples-1.png\" alt=\"How to make ss suppress header line\" width=\"500\" height=\"256\" title=\"\"><\/a><\/p>\n<p>So you can see the header line is missing in this case.<\/p>\n<h2 id=\"q-how-to-make-ss-display-both-listening-and-nonlistening-sockets\">Q3. How to make ss display both listening and non-listening sockets?<\/h2>\n<p>This you can do using the -a command line option.<\/p>\n<p class=\"command\">ss -a<\/p>\n<p>Note that listening sockets are omitted by default, so using -a makes ss include them in the output. However, if you want ss to only display listening sockets, use the -l command line option.<\/p>\n<p class=\"command\">ss -l<\/p>\n<h2 id=\"q-how-to-make-ss-show-processes-using-sockets\">Q4. How to make ss show processes using sockets?<\/h2>\n<p>If you want the ss command to show process information along with the other info it already produces in output, then use the -p command line option.<\/p>\n<p class=\"command\">ss -p<\/p>\n<p>The following screenshot shows the output in my case:<\/p>\n<p><a class=\"fancybox\" id=\"img-ss-p-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/ss-p-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/linux-ss-command-tutorial-for-beginners-8-examples-2.png\" alt=\"How to make ss show processes using sockets\" width=\"500\" height=\"274\" title=\"\"><\/a><\/p>\n<p>So you can see that process information was also displayed in output.<\/p>\n<h2 id=\"q-how-to-make-ss-produce-summary-info\">Q5. How to make ss produce summary info?<\/h2>\n<p>If you don&#8217;t want to see the output the ss command produces by default. Then there&#8217;s an option through which you can ask ss to produce a small summary of the information it parses.<\/p>\n<p>This summary can be produced using the -s command line option:<\/p>\n<p class=\"command\">ss -s<\/p>\n<p>For example, following is the summary produced in my case:<\/p>\n<pre readability=\"8\">Total: 1334 (kernel 0)<br\/>TCP:\u00a0\u00a0 41 (estab 35, closed 3, orphaned 0, synrecv 0, timewait 3\/0), ports 0<p>Transport Total\u00a0\u00a0\u00a0\u00a0 IP\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 IPv6<br\/>*\u00a0\u00a0 \u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0<br\/>RAW\u00a0\u00a0 \u00a0\u00a0 1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0<br\/>UDP\u00a0\u00a0 \u00a0\u00a0 7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 5\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0<br\/>TCP\u00a0\u00a0 \u00a0\u00a0 38\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 37\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0<br\/>INET\u00a0\u00a0 \u00a0\u00a0 46\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 42\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0<br\/>FRAG\u00a0\u00a0 \u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0<\/p><\/pre>\n<h2 id=\"q-how-to-make-ss-display-only-ipv-or-ipv-sockets\">Q6. How to make ss display only IPv4 or IPv6 sockets?<\/h2>\n<p>This can be done using the -4 and -6 options.<\/p>\n<p>For example, to make ss only show IPv4 sockets, run the following command:<\/p>\n<p class=\"command\">ss -4<\/p>\n<p>Similarly for IPv6, execute the following command:<\/p>\n<p class=\"command\">ss -6<\/p>\n<h2 id=\"q-how-to-make-ss-only-display-tcp-or-udp-sockets\">Q7. How to make ss only display TCP or UDP sockets?<\/h2>\n<p>There are different command line options that you can use here: -t for TCP and -u for UDP.<\/p>\n<p>Following is a useful excerpt from the ss command man page.<\/p>\n<pre readability=\"20\"> -t, --tcp<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Display TCP sockets.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -u, --udp<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Display UDP sockets.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -d, --dccp<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Display DCCP sockets.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -w, --raw<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Display RAW sockets.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -x, --unix<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Display Unix domain sockets (alias for -f unix).<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -S, --sctp<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Display SCTP sockets.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 --vsock<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Display vsock sockets (alias for -f vsock).<\/p><\/pre>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>The ss command is a very useful tool if your Linux work involves networking. Here, in this tutorial, we have discussed some command line options ss offers. Once you&#8217;re done practicing these, head to the tool&#8217;s\u00a0<a href=\"https:\/\/linux.die.net\/man\/8\/ss\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a> to learn more.<\/p>\n<div class=\"authorbox\" readability=\"15\">\n<img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/linux-ss-command-tutorial-for-beginners-8-examples.jpg\" alt=\"Himanshu Arora\" title=\"\"> <\/p>\n<p><strong>About Himanshu Arora<\/strong><\/p>\n<p>Himanshu Arora has been working on Linux since 2007. He carries professional experience in system level programming, networking protocols, and command line. In addition to HowtoForge, Himanshu&#8217;s work has also been featured in some of world&#8217;s other leading publications including Computerworld, IBM DeveloperWorks, and Linux Journal.<\/p>\n<\/div>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-ss-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/linux-ss-command-tutorial-for-beginners-8-examples-3.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-ss-command%2F&amp;text=Linux+ss+Command+Tutorial+for+Beginners+%288+Examples%29&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/linux-ss-command-tutorial-for-beginners-8-examples-4.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/linux-ss-command-tutorial-for-beginners-8-examples-5.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-ss-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/linux-ss-command-tutorial-for-beginners-8-examples-6.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>When it comes to accessing socket related information through the command line in Linux, the first tool that comes to mind is netstat. However, there&#8217;s another utility that can do this work for you. It&#8217;s called ss. In this tutorial, we will discuss the basics of this tool using some easy to understand examples. But &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-6966","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=6966"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6966\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=6966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=6966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=6966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}