{"id":63881,"date":"2025-04-29T11:29:08","date_gmt":"2025-04-29T03:29:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63881\/"},"modified":"2025-04-29T11:29:08","modified_gmt":"2025-04-29T03:29:08","slug":"linux%e6%9f%a5%e7%9c%8b%e8%bf%9b%e7%a8%8b%e7%ab%af%e5%8f%a3-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63881\/","title":{"rendered":"linux\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3"},"content":{"rendered":"<blockquote><p>\n  \u5728 linux \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\uff1a\u4f7f\u7528 netstat \u547d\u4ee4\uff1anetstat -tupnl \u8f93\u51fa\u672c\u5730\u548c\u8fdc\u7a0b\u5730\u5740\u548c\u7aef\u53e3\u3002\u4f7f\u7528 lsof \u547d\u4ee4\uff1alsof -i :port_number \u67e5\u770b\u7279\u5b9a\u7aef\u53e3\u53f7\u7684\u8fdb\u7a0b\u3002\u4f7f\u7528 ss \u547d\u4ee4\uff1ass -tupnl \u63d0\u4f9b\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u8fdb\u7a0b\u540d\u79f0\u548c pid\u3002\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f\u6587\u4ef6\uff1acat \/proc\/[pid]\/net\/tcp \u663e\u793a\u6253\u5f00\u7684 tcp \u7aef\u53e3\u4fe1\u606f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/17\/2024081718370238978.jpg\" class=\"aligncenter\" title=\"linux\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\u63d2\u56fe\" alt=\"linux\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\u63d2\u56fe\" \/><\/p>\n<p><strong>Linux\u4e2d\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3<\/strong><\/p>\n<p>\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\uff1a<\/p>\n<p><strong>1. netstat \u547d\u4ee4<\/strong><\/p>\n<p>netstat\u547d\u4ee4\u662f\u7528\u4e8e\u663e\u793a\u7cfb\u7edf\u7f51\u7edc\u8fde\u63a5\u4fe1\u606f\u7684\u5de5\u5177\u3002\u8981\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>netstat -tupnl<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u7ed3\u679c\u4e2d\uff0c&#8221;Local Address&#8221;\u5217\u663e\u793a\u4e86\u8fdb\u7a0b\u7ed1\u5b9a\u7684\u672c\u5730\u5730\u5740\u548c\u7aef\u53e3\uff0c&#8221;Foreign Address&#8221;\u5217\u663e\u793a\u4e86\u8fdb\u7a0b\u8fde\u63a5\u7684\u8fdc\u7a0b\u5730\u5740\u548c\u7aef\u53e3\u3002<\/p>\n<p><strong>2. lsof \u547d\u4ee4<\/strong><\/p>\n<p>lsof\u547d\u4ee4\u7528\u4e8e\u663e\u793a\u6253\u5f00\u7684\u6587\u4ef6\u5217\u8868\u3002\u8981\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>lsof -i :PORT_NUMBER<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0cPORT_NUMBER\u662f\u4f60\u8981\u67e5\u770b\u7684\u7aef\u53e3\u53f7\u3002<\/p>\n<p><strong>3. ss \u547d\u4ee4<\/strong><\/p>\n<p>ss\u547d\u4ee4\u662fnetstat\u547d\u4ee4\u7684\u6539\u8fdb\u7248\u672c\uff0c\u53ef\u4ee5\u63d0\u4f9b\u66f4\u591a\u4fe1\u606f\u3002\u8981\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>ss -tupnl<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u7ed3\u679c\u4e0enetstat\u547d\u4ee4\u7c7b\u4f3c\uff0c\u4f46\u63d0\u4f9b\u4e86\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\uff0c\u4f8b\u5982\u8fdb\u7a0b\u540d\u79f0\u548cPID\u3002<\/p>\n<p><strong>4. \u8fdb\u7a0b\u4fe1\u606f\u6587\u4ef6<\/strong><\/p>\n<p>\u6bcf\u4e2a\u8fdb\u7a0b\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\u90fd\u6709\u4e00\u4e2a\u4fe1\u606f\u6587\u4ef6\uff0c\u4f4d\u4e8e&#8221;\/proc\/[PID]&#8221;\u76ee\u5f55\u4e2d\u3002\u8981\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>cat \/proc\/[PID]\/net\/tcp<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u7ed3\u679c\u663e\u793a\u4e86\u8fdb\u7a0b\u6253\u5f00\u7684TCP\u7aef\u53e3\uff0c\u5305\u62ec\u672c\u5730\u5730\u5740\u3001\u7aef\u53e3\u3001\u8fdc\u7a0b\u5730\u5740\u548c\u7aef\u53e3\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 linux \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\uff1a\u4f7f\u7528 netstat \u547d\u4ee4\uff1anetstat -tupnl \u8f93\u51fa\u672c\u5730\u548c\u8fdc\u7a0b\u5730\u5740\u548c\u7aef\u53e3\u3002\u4f7f\u7528 lsof \u547d\u4ee4\uff1alsof -i :port_number \u67e5\u770b\u7279\u5b9a\u7aef\u53e3\u53f7\u7684\u8fdb\u7a0b\u3002\u4f7f\u7528 ss \u547d\u4ee4\uff1ass -tupnl \u63d0\u4f9b\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u8fdb\u7a0b\u540d\u79f0\u548c pid\u3002\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f\u6587\u4ef6\uff1acat \/proc\/[pid]\/net\/tcp \u663e\u793a\u6253\u5f00\u7684 tcp \u7aef\u53e3\u4fe1\u606f\u3002 Linux\u4e2d\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3 \u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\uff1a 1. netstat \u547d\u4ee4 netstat\u547d\u4ee4\u662f\u7528\u4e8e\u663e\u793a\u7cfb\u7edf\u7f51\u7edc\u8fde\u63a5\u4fe1\u606f\u7684\u5de5\u5177\u3002\u8981\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a netstat -tupnl \u767b\u5f55\u540e\u590d\u5236 \u8f93\u51fa\u7ed3\u679c\u4e2d\uff0c&#8221;Local Address&#8221;\u5217\u663e\u793a\u4e86\u8fdb\u7a0b\u7ed1\u5b9a\u7684\u672c\u5730\u5730\u5740\u548c\u7aef\u53e3\uff0c&#8221;Foreign Address&#8221;\u5217\u663e\u793a\u4e86\u8fdb\u7a0b\u8fde\u63a5\u7684\u8fdc\u7a0b\u5730\u5740\u548c\u7aef\u53e3\u3002 2. lsof \u547d\u4ee4 lsof\u547d\u4ee4\u7528\u4e8e\u663e\u793a\u6253\u5f00\u7684\u6587\u4ef6\u5217\u8868\u3002\u8981\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a lsof -i :PORT_NUMBER \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0cPORT_NUMBER\u662f\u4f60\u8981\u67e5\u770b\u7684\u7aef\u53e3\u53f7\u3002 3. ss \u547d\u4ee4 ss\u547d\u4ee4\u662fnetstat\u547d\u4ee4\u7684\u6539\u8fdb\u7248\u672c\uff0c\u53ef\u4ee5\u63d0\u4f9b\u66f4\u591a\u4fe1\u606f\u3002\u8981\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a ss -tupnl \u767b\u5f55\u540e\u590d\u5236 \u8f93\u51fa\u7ed3\u679c\u4e0enetstat\u547d\u4ee4\u7c7b\u4f3c\uff0c\u4f46\u63d0\u4f9b\u4e86\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\uff0c\u4f8b\u5982\u8fdb\u7a0b\u540d\u79f0\u548cPID\u3002 4. \u8fdb\u7a0b\u4fe1\u606f\u6587\u4ef6 \u6bcf\u4e2a\u8fdb\u7a0b\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\u90fd\u6709\u4e00\u4e2a\u4fe1\u606f\u6587\u4ef6\uff0c\u4f4d\u4e8e&#8221;\/proc\/[PID]&#8221;\u76ee\u5f55\u4e2d\u3002\u8981\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a cat \/proc\/[PID]\/net\/tcp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-63881","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=63881"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63881\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}