{"id":18176,"date":"2024-11-18T13:46:29","date_gmt":"2024-11-18T05:46:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18176\/"},"modified":"2024-11-18T13:46:29","modified_gmt":"2024-11-18T05:46:29","slug":"linux%e6%80%8e%e4%b9%88%e6%9f%a5%e7%9c%8b%e8%bf%9b%e7%a8%8b%e7%ab%af%e5%8f%a3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18176\/","title":{"rendered":"linux\u600e\u4e48\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3"},"content":{"rendered":"<blockquote><p>\n  \u5728 linux \u7cfb\u7edf\u4e2d\uff0c\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\u53ef\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\uff1anetstat \u547d\u4ee4\uff1anetstat -apn\uff1a\u663e\u793a\u6240\u6709\u8fdb\u7a0b\u7684\u7aef\u53e3\u7ed1\u5b9a\u3002netstat -tulpn\uff1a\u663e\u793a\u4ec5 tcp \u548c udp \u7aef\u53e3\u3002netstat -lntp\uff1a\u663e\u793a\u4ec5\u4fa6\u542c\u7aef\u53e3\u3002lsof \u547d\u4ee4\uff1alsof -i -p\uff1a\u663e\u793a\u4f7f\u7528\u7f51\u7edc\u8fde\u63a5\u7684\u8fdb\u7a0b\u548c\u7aef\u53e3\u53f7\u3002lsof -i4tcp:port\uff1a\u663e\u793a\u76d1\u542c\u7279\u5b9a tcp \u7aef\u53e3\u7684\u8fde\u63a5\u3002lsof -i4udp:port\uff1a\u663e\u793a\u76d1\u542c\u7279\u5b9a udp \u7aef\u53e3\u7684\u8fde\u63a5\u3002ss \u547d\u4ee4\uff1ass -tulpn\uff1a\u663e\u793a\u6240\u6709 tcp \u548c udp\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/04\/2024060412032367890.jpg\" class=\"aligncenter\" title=\"linux\u600e\u4e48\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\u63d2\u56fe\" alt=\"linux\u600e\u4e48\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u67e5\u770b Linux \u8fdb\u7a0b\u7aef\u53e3<\/strong><\/p>\n<p>\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u8f7b\u677e\u67e5\u770b\u8fdb\u7a0b\u6b63\u5728\u76d1\u542c\u54ea\u4e9b\u7aef\u53e3\u3002\u8fd9\u5bf9\u4e8e\u6545\u969c\u6392\u9664\u3001\u7f51\u7edc\u7ba1\u7406\u548c\u5b89\u5168\u6027\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528 netstat \u547d\u4ee4<\/strong><\/p>\n<p>netstat \u547d\u4ee4\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>netstat -apn \u5217\u51fa\u6240\u6709\u8fdb\u7a0b\u7684\u7aef\u53e3\u7ed1\u5b9a\uff0c\u5305\u62ec\u8fdb\u7a0b ID (PID) \u548c\u547d\u4ee4\u540d\u79f0\u3002<\/li>\n<li>netstat -tulpn \u4ec5\u5217\u51fa TCP \u548c UDP \u7aef\u53e3\u3002<\/li>\n<li>netstat -lntp \u4ec5\u5217\u51fa\u4fa6\u542c\u7aef\u53e3\u3002<\/li>\n<\/ul>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528 lsof \u547d\u4ee4<\/strong><\/p>\n<p>lsof \u547d\u4ee4\u53ef\u4ee5\u5217\u51fa\u6240\u6709\u6253\u5f00\u7684\u6587\u4ef6\u548c\u7f51\u7edc\u8fde\u63a5\uff1a<\/p>\n<ul>\n<li>lsof -i -P \u5217\u51fa\u6240\u6709\u6b63\u5728\u4f7f\u7528\u7f51\u7edc\u8fde\u63a5\u7684\u8fdb\u7a0b\uff0c\u5305\u62ec\u7aef\u53e3\u53f7\u548c\u8fdb\u7a0b ID\u3002<\/li>\n<li>lsof -i4TCP:port \u4ec5\u5217\u51fa\u4fa6\u542c\u7279\u5b9a\u7aef\u53e3\u7684 TCP \u8fde\u63a5\u3002<\/li>\n<li>lsof -i4UDP:port \u4ec5\u5217\u51fa\u4fa6\u542c\u7279\u5b9a\u7aef\u53e3\u7684 UDP \u8fde\u63a5\u3002<\/li>\n<\/ul>\n<p><strong>\u65b9\u6cd5 3\uff1a\u4f7f\u7528 ss \u547d\u4ee4<\/strong><\/p>\n<p>ss \u547d\u4ee4\u662f\u8f83\u65b0\u7684\u547d\u4ee4\uff0c\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u7684\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>ss -tulpn \u5217\u51fa\u6240\u6709 TCP \u548c UDP \u7aef\u53e3\uff0c\u5305\u62ec\u8fdb\u7a0b ID \u548c\u72b6\u6001\u3002<\/li>\n<li>ss -s \u663e\u793a\u6bcf\u4e2a\u534f\u8bae\u7684\u7edf\u8ba1\u4fe1\u606f\u3002<\/li>\n<li>ss -lntp \u4ec5\u5217\u51fa\u4fa6\u542c\u7aef\u53e3\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a\u4f7f\u7528 netstat<\/strong><\/p>\n<p>\u4ee5\u4e0b\u547d\u4ee4\u5c06\u5217\u51fa\u7cfb\u7edf\u4e0a\u6240\u6709\u6b63\u5728\u4fa6\u542c\u7aef\u53e3\u7684\u8fdb\u7a0b\uff1a<\/p>\n<pre>netstat -lntp<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u7c7b\u4f3c\u4e8e\uff1a<\/p>\n<pre>Active Internet connections (only servers)\nProto Recv-Q Send-Q Local Address           Foreign Address         State       PID\/Program name\ntcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      6725\/sshd\ntcp6       0      0 :::22                   :::*                    LISTEN      6725\/sshd\ntcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      2393\/cupsd\ntcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      646\/systemd-resolved\ntcp        0      0 127.0.0.1:80            0.0.0.0:*               LISTEN      24552\/apache2<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u8f93\u51fa\u663e\u793a\u4e86\u4e94\u4e2a\u8fdb\u7a0b\u6b63\u5728\u4fa6\u542c\u7aef\u53e3\uff0c\u5305\u62ec sshd\u3001cupsd\u3001systemd-resolved \u548c 2\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 linux \u7cfb\u7edf\u4e2d\uff0c\u67e5\u770b\u8fdb\u7a0b\u7aef\u53e3\u53ef\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\uff1anetstat \u547d\u4ee4\uff1anetstat -apn\uff1a\u663e\u793a\u6240\u6709\u8fdb\u7a0b\u7684\u7aef\u53e3\u7ed1\u5b9a\u3002netstat -tulpn\uff1a\u663e\u793a\u4ec5 tcp \u548c udp \u7aef\u53e3\u3002netstat -lntp\uff1a\u663e\u793a\u4ec5\u4fa6\u542c\u7aef\u53e3\u3002lsof \u547d\u4ee4\uff1alsof -i -p\uff1a\u663e\u793a\u4f7f\u7528\u7f51\u7edc\u8fde\u63a5\u7684\u8fdb\u7a0b\u548c\u7aef\u53e3\u53f7\u3002lsof -i4tcp:port\uff1a\u663e\u793a\u76d1\u542c\u7279\u5b9a tcp \u7aef\u53e3\u7684\u8fde\u63a5\u3002lsof -i4udp:port\uff1a\u663e\u793a\u76d1\u542c\u7279\u5b9a udp \u7aef\u53e3\u7684\u8fde\u63a5\u3002ss \u547d\u4ee4\uff1ass -tulpn\uff1a\u663e\u793a\u6240\u6709 tcp \u548c udp \u5982\u4f55\u67e5\u770b Linux \u8fdb\u7a0b\u7aef\u53e3 \u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u8f7b\u677e\u67e5\u770b\u8fdb\u7a0b\u6b63\u5728\u76d1\u542c\u54ea\u4e9b\u7aef\u53e3\u3002\u8fd9\u5bf9\u4e8e\u6545\u969c\u6392\u9664\u3001\u7f51\u7edc\u7ba1\u7406\u548c\u5b89\u5168\u6027\u81f3\u5173\u91cd\u8981\u3002 \u65b9\u6cd5 1\uff1a\u4f7f\u7528 netstat \u547d\u4ee4 netstat \u547d\u4ee4\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff1a netstat -apn \u5217\u51fa\u6240\u6709\u8fdb\u7a0b\u7684\u7aef\u53e3\u7ed1\u5b9a\uff0c\u5305\u62ec\u8fdb\u7a0b ID (PID) \u548c\u547d\u4ee4\u540d\u79f0\u3002 netstat -tulpn \u4ec5\u5217\u51fa TCP \u548c UDP \u7aef\u53e3\u3002 netstat -lntp \u4ec5\u5217\u51fa\u4fa6\u542c\u7aef\u53e3\u3002 \u65b9\u6cd5 2\uff1a\u4f7f\u7528 [&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-18176","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18176","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=18176"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18176\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}