# \u7528ss \u68c0\u67e5\u76d1\u542c\u7aef\u53e3 <\/strong><\/span><\/div>\nss\u662f\u65b0\u7684netstat\u3002\u5b83\u7f3a\u5c11netstat\u7684\u67d0\u4e9b\u529f\u80fd\uff0c\u4f46\u662f\u516c\u5f00\u4e86\u66f4\u591a\u7684TCP\u72b6\u6001\uff0c\u5e76\u4e14\u901f\u5ea6\u7a0d\u5feb\u3002\u547d\u4ee4\u9009\u9879\u57fa\u672c\u76f8\u540c\uff0c\u56e0\u6b64\u4ecenetstat\u5230ss\u7684\u8f6c\u6362\u5e76\u4e0d\u56f0\u96be\u3002<\/p>\n
\u8981\u4f7f\u7528ss\u83b7\u53d6\u6240\u6709\u76d1\u542c\u7aef\u53e3\u7684\u5217\u8868\uff0c\u8bf7\u8f93\u5165\uff1a<\/p>\n
sudo ss -tunlp\r\n<\/pre>\n\u8f93\u51fa\u4e0enetstat\u62a5\u544a\u7684\u8f93\u51fa\u51e0\u4e4e\u76f8\u540c\uff1a<\/p>\n
State Recv-Q Send-Q Local Address:Port Peer Address:Port\r\nLISTEN 0 128 0:22 0:* users:((\"sshd\",pid=445,fd=3))\r\nLISTEN 0 100 0:25 0:* users:((\"master\",pid=929,fd=13))\r\nLISTEN 0 128 *:3306 *:* users:((\"mysqld\",pid=534,fd=30))\r\nLISTEN 0 128 *:80 *:* users:((\"apache2\",pid=765,fd=4),(\"apache2\",pid=764,fd=4),(\"apache2\",pid=515,fd=4))\r\nLISTEN 0 128 [::]:22 [::]:* users:((\"sshd\",pid=445,fd=4))\r\nLISTEN 0 100 [::]:25 [::]:* users:((\"master\",pid=929,fd=14))\r\nLISTEN 0 70 *:33060 *:* users:((\"mysqld\",pid=534,fd=33))\r\n<\/pre>\n# \u4f7f\u7528lsof \u68c0\u67e5\u76d1\u542c\u7aef\u53e3<\/strong><\/span><\/div>\nlsof\u662f\u529f\u80fd\u5f3a\u5927\u7684\u547d\u4ee4\u884c\u5e94\u7528\u7a0b\u5e8f\uff0c\u53ef\u63d0\u4f9b\u6709\u5173\u8fdb\u7a0b\u6253\u5f00\u7684\u6587\u4ef6\u7684\u4fe1\u606f\u3002<\/p>\n
\u5728Linux\u4e2d\uff0c\u6240\u6709\u5185\u5bb9\u90fd\u662f\u6587\u4ef6\u3002\u4f60\u53ef\u4ee5\u5c06\u5957\u63a5\u5b57\u89c6\u4e3a\u5199\u5165\u7f51\u7edc\u7684\u6587\u4ef6\u3002<\/p>\n
\u8981\u83b7\u53d6\u5177\u6709lsof\u7684\u6240\u6709\u4fa6\u542cTCP\u7aef\u53e3\u7684\u5217\u8868\uff0c\u8bf7\u8f93\u5165\uff1a<\/p>\n
sudo lsof -nP -iTCP -sTCP:LISTEN\r\n<\/pre>\n\u4f7f\u7528\u7684\u9009\u9879\u5982\u4e0b:<\/p>\n
\n- -n-\u4e0d\u8981\u5c06\u7aef\u53e3\u53f7\u8f6c\u6362\u4e3a\u7aef\u53e3\u540d\u79f0\u3002<\/li>\n
- -p -\u4e0d\u89e3\u6790\u4e3b\u673a\u540d\uff0c\u663e\u793a\u6570\u5b57\u5730\u5740\u3002<\/li>\n
- -iTCP -sTCP:LISTEN -\u4ec5\u663e\u793aTCP\u72b6\u6001\u4e3aLISTEN\u7684\u7f51\u7edc\u6587\u4ef6\u3002<\/li>\n<\/ol>\n
COMMAND PID USER FD TYPE DEVICE SIZE\/OFF NODE NAME\r\nsshd 445 root 3u IPv4 16434 0t0 TCP *:22 (LISTEN)\r\nsshd 445 root 4u IPv6 16445 0t0 TCP *:22 (LISTEN)\r\napache2 515 root 4u IPv6 16590 0t0 TCP *:80 (LISTEN)\r\nmysqld 534 mysql 30u IPv6 17636 0t0 TCP *:3306 (LISTEN)\r\nmysqld 534 mysql 33u IPv6 19973 0t0 TCP *:33060 (LISTEN)\r\napache2 764 www-data 4u IPv6 16590 0t0 TCP *:80 (LISTEN)\r\napache2 765 www-data 4u IPv6 16590 0t0 TCP *:80 (LISTEN)\r\nmaster 929 root 13u IPv4 19637 0t0 TCP *:25 (LISTEN)\r\nmaster 929 root 14u IPv6 19638 0t0 TCP *:25 (LISTEN)\r\n<\/pre>\n\u5927\u591a\u6570\u8f93\u51fa\u5217\u540d\u79f0\u90fd\u662f\u4e0d\u8a00\u81ea\u660e\u7684:<\/p>\n
\n- COMMAND\uff0cPID\uff0cUSER-\u8fd0\u884c\u4e0e\u7aef\u53e3\u5173\u8054\u7684\u7a0b\u5e8f\u7684\u540d\u79f0\uff0cPID\u548c\u7528\u6237\u3002<\/li>\n
- NAME -\u7aef\u53e3\u53f7\u3002<\/li>\n<\/ol>\n
\u8981\u67e5\u627e\u6b63\u5728\u4fa6\u542c\u7279\u5b9a\u7aef\u53e3(\u4f8b\u5982\u7aef\u53e33306)\u7684\u8fdb\u7a0b\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n
sudo lsof -nP -iTCP:3306 -sTCP:LISTEN\r\n<\/pre>\n\u8f93\u51fa\u663e\u793aMySQL\u670d\u52a1\u5668\u4f7f\u7528\u7aef\u53e33306:<\/p>\n
COMMAND PID USER FD TYPE DEVICE SIZE\/OFF NODE NAME\r\nmysqld 534 mysql 30u IPv6 17636 0t0 TCP *:3306 (LISTEN)<\/pre>\n","protected":false},"excerpt":{"rendered":"Address already in use\u8fd9\u4e2a\u63d0\u793a,\u60f3\u5fc5\u5927\u5bb6\u9047\u5230\u8fc7,\u600e\u4e48\u80fd\u5feb\u901f\u627e\u5230\u95ee\u9898\u5e76\u89e3\u51b3\u5462?\u4e0b\u9762\u6709\u51e0\u79cd\u59ff […]<\/p>\n","protected":false},"author":643,"featured_media":234507,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-234498","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\/234498","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\/643"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=234498"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/234498\/revisions"}],"predecessor-version":[{"id":234506,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/234498\/revisions\/234506"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/234507"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=234498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=234498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=234498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}