{"id":2553,"date":"2015-11-26T13:28:18","date_gmt":"2015-11-26T05:28:18","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2553"},"modified":"2015-11-26T13:28:18","modified_gmt":"2015-11-26T05:28:18","slug":"linux%e7%9a%84netstat%e5%91%bd%e4%bb%a4%e5%8f%8a%e5%ae%83%e7%9a%84%e6%9b%bf%e4%bb%a3%e8%80%85ss%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2553.html","title":{"rendered":"Linux\u7684netstat\u547d\u4ee4\u53ca\u5b83\u7684\u66ff\u4ee3\u8005ss\u547d\u4ee4"},"content":{"rendered":"<p>=Start=<\/p>\n<h6>\u641c\u7d22\u5173\u952e\u5b57\uff1a<\/h6>\n<p>linux netstat vs. ss<\/p>\n<h6>\u53c2\u8003\u89e3\u7b54\uff1a<\/h6>\n<pre class=\"lang:default decode:true\">$ man netstat\n...\nNOTE\n\tThis program is obsolete. Replacement for netstat is ss. Replacement for 'netstat -r' is 'ip route'. Replacement for 'netstat -i' is 'ip -s link'. Replacement for 'netstat -g' is 'ip maddr'.\n...<\/pre>\n<p>==<\/p>\n<p><em><code>ss<\/code>\u00a0is one another utility to investigate sockets. <span style=\"color: #0000ff;\"><strong>Functionally it is NOT better than <code>netstat<\/code>\u00a0combined with some perl\/awk scripts<\/strong><\/span> and though <strong><span style=\"color: #ff0000;\">it is surely faster it is not enough to make it much better.<\/span><\/strong> \ud83d\ude42 So, stop reading this now and do not waste your time. Well, certainly, it proposes some functionality, which current netstat is still not able to do, but surely will soon.<\/em><\/p>\n<p><span style=\"color: #ff0000;\"><code>\/proc<\/code>\u00a0interface is inadequate, unfortunately. When amount of sockets is enough large, <strong><code>netstat<\/code><\/strong>\u00a0or even plain <code>cat \/proc\/net\/tcp\/<\/code>\u00a0cause nothing but pains and curses.<\/span> In linux-2.4 the desease became worse: even if amount of sockets is small reading <code>\/proc\/net\/tcp\/<\/code>\u00a0is slow enough.<\/p>\n<p>This utility presents a new approach, which is supposed to scale well. I am not going to describe technical details here and will concentrate on description of the command. The only important thing to say is that it is not so bad idea to load module <code>tcp_diag<\/code>, which can be found in directory <code>Modules<\/code>\u00a0of <code>iproute2<\/code>. If you do not make this <code>ss<\/code>\u00a0will work, but it falls back to<code>\/proc<\/code>\u00a0and becomes slow like <code>netstat<\/code>, well, a bit faster yet (see section &#8220;<a href=\"http:\/\/www.cyberciti.biz\/files\/ss.html\" target=\"_blank\">Some numbers<\/a>&#8220;).<\/p>\n<p>==<\/p>\n<h6>#\u548cnetstat\u8bf4\u518d\u89c1\u7684\u539f\u56e0#<\/h6>\n<p>\u5f53\u670d\u52a1\u5668\u7684socket\u8fde\u63a5\u6570\u91cf\u53d8\u5f97\u975e\u5e38\u5927\u65f6\uff0c\u65e0\u8bba\u662f\u4f7f\u7528netstat\u547d\u4ee4\u8fd8\u662f\u76f4\u63a5cat \/proc\/net\/tcp\uff0c\u6267\u884c\u901f\u5ea6\u90fd\u4f1a\u5f88\u6162\u3002\u5f53\u670d\u52a1\u5668\u7ef4\u6301\u7684\u8fde\u63a5\u8fbe\u5230\u4e0a\u4e07\u4e2a\u7684\u65f6\u5019\uff0c\u4f7f\u7528netstat\u7b49\u4e8e\u6d6a\u8d39\u751f\u547d\uff0c\u800c\u7528ss\u624d\u662f\u8282\u7701\u65f6\u95f4\u3002<\/p>\n<p>\u5929\u4e0b\u6b66\u529f\u552f\u5feb\u4e0d\u7834\u3002ss\u5feb\u7684\u79d8\u8bc0\u5728\u4e8e\uff0c\u5b83\u5229\u7528\u5230\u4e86TCP\u534f\u8bae\u6808\u4e2dtcp_diag\u3002tcp_diag\u662f\u4e00\u4e2a\u7528\u4e8e\u5206\u6790\u7edf\u8ba1\u7684\u6a21\u5757\uff0c\u53ef\u4ee5\u83b7\u5f97 Linux \u5185\u6838\u4e2d\u7b2c\u4e00\u624b\u7684\u4fe1\u606f\uff0c\u8fd9\u5c31\u786e\u4fdd\u4e86ss\u7684\u5feb\u6377\u9ad8\u6548\u3002\u5f53\u7136\uff0c\u5982\u679c\u4f60\u7684\u7cfb\u7edf\u4e2d\u6ca1\u6709tcp_diag\uff0css\u4e5f\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c\uff0c\u53ea\u662f\u6548\u7387\u4f1a\u53d8\u5f97\u7a0d\u6162\u3002\uff08\u4f46\u4ecd\u7136\u6bd4 netstat \u8981\u5feb\u3002\uff09<br \/>\n==<\/p>\n<p>#\u67e5\u770b\u5f53\u524d\u670d\u52a1\u5668\u7684\u7f51\u7edc\u8fde\u63a5\u7edf\u8ba1<br \/>\n$ ss -s<\/p>\n<p>#\u67e5\u770b\u6240\u6709\u6253\u5f00\u7684\u7f51\u7edc\u7aef\u53e3<br \/>\n$ ss -l<\/p>\n<p>#\u67e5\u770b\u670d\u52a1\u5668\u4e0a\u6240\u6709\u7684socket\u8fde\u63a5\uff08\u4f7f\u7528-a\u9009\u9879\uff09<br \/>\n# ss -a<br \/>\n\u5982\u679c\u53ea\u60f3\u67e5\u770bTCP sockets\uff0c\u90a3\u4e48\u4f7f\u7528-ta\u9009\u9879\uff1b<br \/>\n\u5982\u679c\u53ea\u60f3\u67e5\u770bUDP sockets\uff0c\u90a3\u4e48\u4f7f\u7528-ua\u9009\u9879\uff1b<br \/>\n\u5982\u679c\u53ea\u60f3\u67e5\u770bRAW sockets\uff0c\u90a3\u4e48\u4f7f\u7528-wa\u9009\u9879\uff1b<br \/>\n\u5982\u679c\u53ea\u60f3\u67e5\u770bUNIX sockets\uff0c\u90a3\u4e48\u4f7f\u7528-xa\u9009\u9879\u3002<\/p>\n<p>==<\/p>\n<pre class=\"lang:default decode:true\" title=\"ss\u547d\u4ee4\u7684\u5e38\u7528\u9009\u9879\u7ec4\u5408\">$ ss -ltn\n$ ss -lun\n\n$ sudo ss -tpl\n$ sudo ss -nlp\n$ sudo ss -plan\n$ sudo ss -plant<\/pre>\n<p>==<\/p>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/roclinux.cn\/?p=2418\" target=\"_blank\">http:\/\/roclinux.cn\/?p=2418<\/a><\/li>\n<li><a href=\"http:\/\/roclinux.cn\/?p=2420\" target=\"_blank\">http:\/\/roclinux.cn\/?p=2420<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/11763376\/difference-between-netstat-and-ss-in-linux\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/11763376\/difference-between-netstat-and-ss-in-linux<\/a><\/li>\n<li><a href=\"http:\/\/www.cyberciti.biz\/files\/ss.html\" target=\"_blank\">http:\/\/www.cyberciti.biz\/files\/ss.html<\/a><\/li>\n<li><a href=\"http:\/\/www.binarytides.com\/linux-ss-command\/\" target=\"_blank\">http:\/\/www.binarytides.com\/linux-ss-command\/<\/a> #\u5168\u9762\u6df1\u5165\u7ed9\u529b\uff01<\/li>\n<li><a href=\"http:\/\/www.ttlsa.com\/linux-command\/ss-replace-netstat\/\" target=\"_blank\">http:\/\/www.ttlsa.com\/linux-command\/ss-replace-netstat\/<\/a><\/li>\n<\/ul>\n<p>=EOF=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u641c\u7d22\u5173\u952e\u5b57\uff1a linux netstat vs. ss \u53c2\u8003\u89e3\u7b54\uff1a $ man netstat [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11,7,12],"tags":[30,159,572],"class_list":["post-2553","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-programing","category-tools","tag-linux","tag-netstat","tag-ss"],"views":4569,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2553"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2553\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}