{"id":211113,"date":"2021-02-18T09:07:24","date_gmt":"2021-02-18T01:07:24","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=211113"},"modified":"2021-02-02T16:43:26","modified_gmt":"2021-02-02T08:43:26","slug":"linux-netstat-check","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-netstat-check.html","title":{"rendered":"\u804a\u804alinux\u67e5\u770b\u670d\u52a1\u548c\u7aef\u53e3\u72b6\u6001\u547d\u4ee4netstat"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4f7f\u7528netstat\u547d\u4ee4\u53ef\u4ee5\u67e5\u770blinux\u7cfb\u7edf\u4e2d\u6b63\u5728\u4f7f\u7528\u7684\u670d\u52a1\u548c\u7aef\u53e3\u60c5\u51b5<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u5e38\u89c1\u53c2\u6570<\/strong><\/div>\n

-a (all)\u663e\u793a\u6240\u6709\u9009\u9879\uff0c\u9ed8\u8ba4\u4e0d\u663e\u793aLISTEN\u76f8\u5173
\n-t (tcp)\u4ec5\u663e\u793atcp\u76f8\u5173\u9009\u9879
\n-u (udp)\u4ec5\u663e\u793audp\u76f8\u5173\u9009\u9879
\n-n \u62d2\u7edd\u663e\u793a\u522b\u540d\uff0c\u80fd\u663e\u793a\u6570\u5b57\u7684\u5168\u90e8\u8f6c\u5316\u6210\u6570\u5b57\u3002
\n-l \u4ec5\u5217\u51fa\u6709\u5728 Listen (\u76d1\u542c) \u7684\u670d\u52a1\u72b6\u6001<\/p>\n

-p \u663e\u793a\u5efa\u7acb\u76f8\u5173\u94fe\u63a5\u7684\u7a0b\u5e8f\u540d
\n-r \u663e\u793a\u8def\u7531\u4fe1\u606f\uff0c\u8def\u7531\u8868
\n-e \u663e\u793a\u6269\u5c55\u4fe1\u606f\uff0c\u4f8b\u5982uid\u7b49
\n-s \u6309\u5404\u4e2a\u534f\u8bae\u8fdb\u884c\u7edf\u8ba1
\n-c \u6bcf\u9694\u4e00\u4e2a\u56fa\u5b9a\u65f6\u95f4\uff0c\u6267\u884c\u8be5netstat\u547d\u4ee4\u3002<\/p>\n

\u63d0\u793a\uff1aLISTEN\u548cLISTENING\u7684\u72b6\u6001\u53ea\u6709\u7528-a\u6216\u8005-l\u624d\u80fd\u770b\u5230<\/p>\n

\u5b9e\u7528\u547d\u4ee4\u5b9e\u4f8b<\/strong><\/div>\n

1. \u5217\u51fa\u6240\u6709\u7aef\u53e3 (\u5305\u62ec\u76d1\u542c\u548c\u672a\u76d1\u542c\u7684)<\/p>\n

\"\"<\/p>\n

2. \u5217\u51fa\u6240\u6709\u5904\u4e8e\u76d1\u542c\u72b6\u6001\u7684 Sockets<\/p>\n

\u53ea\u663e\u793a\u76d1\u542c\u7aef\u53e3 netstat -l<\/p>\n

\"\"<\/p>\n

\u53ea\u5217\u51fa\u6240\u6709\u76d1\u542c tcp \u7aef\u53e3 netstat -lt<\/p>\n

\"\"<\/p>\n

\u53ea\u5217\u51fa\u6240\u6709\u76d1\u542c udp \u7aef\u53e3 netstat -lu<\/p>\n

\"\"<\/p>\n

\u53ea\u5217\u51fa\u6240\u6709\u76d1\u542c UNIX \u7aef\u53e3 netstat -lx<\/p>\n

\"\"<\/p>\n

3. \u663e\u793a\u6bcf\u4e2a\u534f\u8bae\u7684\u7edf\u8ba1\u4fe1\u606f<\/p>\n

\u663e\u793a\u6240\u6709\u7aef\u53e3\u7684\u7edf\u8ba1\u4fe1\u606f netstat -s
\n\u663e\u793a TCP \u6216 UDP \u7aef\u53e3\u7684\u7edf\u8ba1\u4fe1\u606f netstat -st \u6216 -su<\/p>\n

\"\"<\/p>\n

4.\u5728 netstat \u8f93\u51fa\u4e2d\u663e\u793a PID \u548c\u8fdb\u7a0b\u540d\u79f0 netstat -p<\/p>\n

5. \u4e0d\u663e\u793a\u4e3b\u673a\uff0c\u7aef\u53e3\u548c\u7528\u6237\u540d (host, port or user)<\/p>\n

\u5f53\u4f60\u4e0d\u60f3\u8ba9\u4e3b\u673a\uff0c\u7aef\u53e3\u548c\u7528\u6237\u540d\u663e\u793a\uff0c\u4f7f\u7528 netstat -n\u3002\u5c06\u4f1a\u4f7f\u7528\u6570\u5b57\u4ee3\u66ff\u90a3\u4e9b\u540d\u79f0\u3002<\/p>\n

\"\"<\/p>\n

6. \u6301\u7eed\u8f93\u51fa netstat \u4fe1\u606f<\/p>\n

netstat \u5c06\u6bcf\u9694\u4e00\u79d2\u8f93\u51fa\u7f51\u7edc\u4fe1\u606f\u3002netstat -c<\/p>\n

7. \u663e\u793a\u6838\u5fc3\u8def\u7531\u4fe1\u606f netstat -r<\/p>\n

\"\"<\/p>\n

8. \u627e\u51fa\u7a0b\u5e8f\u8fd0\u884c\u7684\u7aef\u53e3<\/p>\n

\u5e76\u4e0d\u662f\u6240\u6709\u7684\u8fdb\u7a0b\u90fd\u80fd\u627e\u5230\uff0c\u6ca1\u6709\u6743\u9650\u7684\u4f1a\u4e0d\u663e\u793a\uff0c\u4f7f\u7528 root \u6743\u9650\u67e5\u770b\u6240\u6709\u7684\u4fe1\u606f\u3002<\/p>\n

netstat -ap | grep ssh<\/pre>\n

\"\"<\/p>\n

\u5e38\u7528\uff1a<\/p>\n

netstat -nat \u5217\u51fa\u6240\u6709\u7684tcp\u7aef\u53e3<\/p>\n","protected":false},"excerpt":{"rendered":"

-a (all)\u663e\u793a\u6240\u6709\u9009\u9879\uff0c\u9ed8\u8ba4\u4e0d\u663e\u793aLISTEN\u76f8\u5173 -t (tcp)\u4ec5\u663e\u793atcp\u76f8\u5173\u9009\u9879 -u (udp […]<\/p>\n","protected":false},"author":310,"featured_media":211129,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-211113","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/211113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/310"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=211113"}],"version-history":[{"count":8,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/211113\/revisions"}],"predecessor-version":[{"id":211157,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/211113\/revisions\/211157"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/211129"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=211113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=211113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=211113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}