{"id":89005,"date":"2024-02-14T01:23:12","date_gmt":"2024-02-13T17:23:12","guid":{"rendered":"http:\/\/gulass.cn\/?p=89005"},"modified":"2024-02-14T01:23:12","modified_gmt":"2024-02-13T17:23:12","slug":"netstat-common-method","status":"publish","type":"post","link":"https:\/\/gulass.cn\/netstat-common-method.html","title":{"rendered":"Netstat \u7684\u51e0\u4e2a\u5e38\u7528\u65b9\u6cd5"},"content":{"rendered":"
Netstat \u662f\u4e00\u6b3e\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ef\u7528\u4e8e\u5217\u51fa\u7cfb\u7edf\u4e0a\u6240\u6709\u7684\u7f51\u7edc\u5957\u63a5\u5b57\u8fde\u63a5\u60c5\u51b5\uff0c\u5305\u62ec tcp, udp \u4ee5\u53ca unix \u5957\u63a5\u5b57\uff0c\u53e6\u5916\u5b83\u8fd8\u80fd\u5217\u51fa\u5904\u4e8e\u76d1\u542c\u72b6\u6001\uff08\u5373\u7b49\u5f85\u63a5\u5165\u8bf7\u6c42\uff09\u7684\u5957\u63a5\u5b57\u3002\u5982\u679c\u4f60\u60f3\u786e\u8ba4\u7cfb\u7edf\u4e0a\u7684 Web \u670d\u52a1\u6709\u6ca1\u6709\u8d77\u6765\uff0c\u4f60\u53ef\u4ee5\u67e5\u770b80\u7aef\u53e3\u6709\u6ca1\u6709\u6253\u5f00\u3002\u4ee5\u4e0a\u529f\u80fd\u4f7f netstat \u6210\u4e3a\u7f51\u7ba1\u548c\u7cfb\u7edf\u7ba1\u7406\u5458\u7684\u5fc5\u5907\u5229\u5668\u3002\u5728\u8fd9\u7bc7\u6559\u7a0b\u4e2d\uff0c\u6211\u4f1a\u5217\u51fa\u51e0\u4e2a\u4f8b\u5b50\uff0c\u6559\u5927\u5bb6\u5982\u4f55\u4f7f\u7528 netstat \u53bb\u67e5\u627e\u7f51\u7edc\u8fde\u63a5\u4fe1\u606f\u548c\u7cfb\u7edf\u5f00\u542f\u7684\u7aef\u53e3\u53f7\u3002<\/p>\n
<\/p>\n
\u4ee5\u4e0b\u7684\u7b80\u5355\u4ecb\u7ecd\u6765\u81ea netstat \u7684 man \u624b\u518c\uff1a<\/p>\n
netstat \u2013 \u6253\u5370\u7f51\u7edc\u8fde\u63a5\u3001\u8def\u7531\u8868\u3001\u8fde\u63a5\u7684\u6570\u636e\u7edf\u8ba1\u3001\u4f2a\u88c5\u8fde\u63a5\u4ee5\u53ca\u5e7f\u64ad\u57df\u6210\u5458\u3002<\/p><\/blockquote>\n
1. \u5217\u51fa\u6240\u6709\u8fde\u63a5<\/strong><\/div>\n\u7b2c\u4e00\u4e2a\u8981\u4ecb\u7ecd\u7684\uff0c\u662f\u6700\u7b80\u5355\u7684\u547d\u4ee4\uff1a\u5217\u51fa\u6240\u6709\u5f53\u524d\u7684\u8fde\u63a5\u3002\u4f7f\u7528 -a \u9009\u9879\u5373\u53ef\u3002<\/p>\n
$ netstat -a\r\n\r\nActive Internet connections (servers and established)\r\nProto Recv-Q Send-Q Local Address Foreign Address State \r\ntcp 0 0 enlightened:domain *:* LISTEN \r\ntcp 0 0 localhost:ipp *:* LISTEN \r\ntcp 0 0 enlightened.local:54750 li240-5.members.li:http ESTABLISHED\r\ntcp 0 0 enlightened.local:49980 del01s07-in-f14.1:https ESTABLISHED\r\ntcp6 0 0 ip6-localhost:ipp [::]:* LISTEN \r\nudp 0 0 enlightened:domain *:* \r\nudp 0 0 *:bootpc *:* \r\nudp 0 0 enlightened.local:ntp *:* \r\nudp 0 0 localhost:ntp *:* \r\nudp 0 0 *:ntp *:* \r\nudp 0 0 *:58570 *:* \r\nudp 0 0 *:mdns *:* \r\nudp 0 0 *:49459 *:* \r\nudp6 0 0 fe80::216:36ff:fef8:ntp [::]:* \r\nudp6 0 0 ip6-localhost:ntp [::]:* \r\nudp6 0 0 [::]:ntp [::]:* \r\nudp6 0 0 [::]:mdns [::]:* \r\nudp6 0 0 [::]:63811 [::]:* \r\nudp6 0 0 [::]:54952 [::]:* \r\nActive UNIX domain sockets (servers and established)\r\nProto RefCnt Flags Type State I-Node Path\r\nunix 2 [ ACC ] STREAM LISTENING 12403 @\/tmp\/dbus-IDgfj3UGXX\r\nunix 2 [ ACC ] STREAM LISTENING 40202 @\/dbus-vfs-daemon\/socket-6nUC6CCx\r\n<\/pre>\n\u4e0a\u8ff0\u547d\u4ee4\u5217\u51fa tcp, udp \u548c unix \u534f\u8bae\u4e0b\u6240\u6709\u5957\u63a5\u5b57\u7684\u6240\u6709\u8fde\u63a5\u3002\u7136\u800c\u8fd9\u4e9b\u4fe1\u606f\u8fd8\u4e0d\u591f\u8be6\u7ec6\uff0c\u7ba1\u7406\u5458\u5f80\u5f80\u9700\u8981\u67e5\u770b\u67d0\u4e2a\u534f\u8bae\u6216\u7aef\u53e3\u7684\u5177\u4f53\u8fde\u63a5\u60c5\u51b5\u3002<\/p>\n
2. \u53ea\u5217\u51fa TCP \u6216 UDP \u534f\u8bae\u7684\u8fde\u63a5<\/strong><\/div>\n\u4f7f\u7528 -t<\/strong> \u9009\u9879\u5217\u51fa TCP \u534f\u8bae\u7684\u8fde\u63a5\uff1a<\/p>\n
$ netstat -at\r\nActive Internet connections (servers and established)\r\nProto Recv-Q Send-Q Local Address Foreign Address State \r\ntcp 0 0 enlightened:domain *:* LISTEN \r\ntcp 0 0 localhost:ipp *:* LISTEN \r\ntcp 0 0 enlightened.local:36310 del01s07-in-f24.1:https ESTABLISHED\r\ntcp 0 0 enlightened.local:45038 a96-17-181-10.depl:http ESTABLISHED\r\ntcp 0 0 enlightened.local:37892 ABTS-North-Static-:http ESTABLISHED\r\n.....\r\n<\/pre>\n\u4f7f\u7528 -u<\/strong> \u9009\u9879\u5217\u51fa UDP \u534f\u8bae\u7684\u8fde\u63a5\uff1a<\/p>\n
$ netstat -au\r\nActive Internet connections (servers and established)\r\nProto Recv-Q Send-Q Local Address Foreign Address State \r\nudp 0 0 *:34660 *:* \r\nudp 0 0 enlightened:domain *:* \r\nudp 0 0 *:bootpc *:* \r\nudp 0 0 enlightened.local:ntp *:* \r\nudp 0 0 localhost:ntp *:* \r\nudp 0 0 *:ntp *:* \r\nudp6 0 0 fe80::216:36ff:fef8:ntp [::]:* \r\nudp6 0 0 ip6-localhost:ntp [::]:* \r\nudp6 0 0 [::]:ntp [::]:*\r\n<\/pre>\n\u4e0a\u9762\u540c\u65f6\u663e\u793a\u4e86 IPv4 \u548c IPv6 \u7684\u8fde\u63a5\u3002<\/p>\n
3. \u7981\u7528\u53cd\u5411\u57df\u540d\u89e3\u6790\uff0c\u52a0\u5feb\u67e5\u8be2\u901f\u5ea6<\/strong><\/div>\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b netstat \u4f1a\u901a\u8fc7\u53cd\u5411\u57df\u540d\u89e3\u6790\u6280\u672f\u67e5\u627e\u6bcf\u4e2a IP \u5730\u5740\u5bf9\u5e94\u7684\u4e3b\u673a\u540d\u3002\u8fd9\u4f1a\u964d\u4f4e\u67e5\u627e\u901f\u5ea6\u3002\u5982\u679c\u4f60\u89c9\u5f97 IP \u5730\u5740\u5df2\u7ecf\u8db3\u591f\uff0c\u800c\u6ca1\u6709\u5fc5\u8981\u77e5\u9053\u4e3b\u673a\u540d\uff0c\u5c31\u4f7f\u7528 -n<\/strong> \u9009\u9879\u7981\u7528\u57df\u540d\u89e3\u6790\u529f\u80fd\u3002<\/p>\n
$ netstat -ant\r\nActive Internet connections (servers and established)\r\nProto Recv-Q Send-Q Local Address Foreign Address State \r\ntcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN \r\ntcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN \r\ntcp 0 0 192.168.1.2:49058 173.255.230.5:80 ESTABLISHED\r\ntcp 0 0 192.168.1.2:33324 173.194.36.117:443 ESTABLISHED\r\ntcp6 0 0 ::1:631 :::* LISTEN\r\n<\/pre>\n\u4e0a\u8ff0\u547d\u4ee4\u5217\u51fa\u6240\u6709 TCP \u534f\u8bae\u7684\u8fde\u63a5\uff0c\u6ca1\u6709\u4f7f\u7528\u57df\u540d\u89e3\u6790\u6280\u672f\u3002So easy ? \u975e\u5e38\u597d\u3002<\/p>\n
4. \u53ea\u5217\u51fa\u76d1\u542c\u4e2d\u7684\u8fde\u63a5<\/strong><\/div>\n\u4efb\u4f55\u7f51\u7edc\u670d\u52a1\u7684\u540e\u53f0\u8fdb\u7a0b\u90fd\u4f1a\u6253\u5f00\u4e00\u4e2a\u7aef\u53e3\uff0c\u7528\u4e8e\u76d1\u542c\u63a5\u5165\u7684\u8bf7\u6c42\u3002\u8fd9\u4e9b\u6b63\u5728\u76d1\u542c\u7684\u5957\u63a5\u5b57\u4e5f\u548c\u8fde\u63a5\u7684\u5957\u63a5\u5b57\u4e00\u6837\uff0c\u4e5f\u80fd\u88ab netstat \u5217\u51fa\u6765\u3002\u4f7f\u7528 -l<\/strong> \u9009\u9879\u5217\u51fa\u6b63\u5728\u76d1\u542c\u7684\u5957\u63a5\u5b57\u3002<\/p>\n
$ netstat -tnl\r\nActive Internet connections (only servers)\r\nProto Recv-Q Send-Q Local Address Foreign Address State \r\ntcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN \r\ntcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN \r\ntcp6 0 0 ::1:631 :::* LISTEN\r\n<\/pre>\n\u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u5904\u4e8e\u76d1\u542c\u72b6\u6001\u7684 TCP \u7aef\u53e3\u548c\u8fde\u63a5\u3002\u5982\u679c\u4f60\u67e5\u770b\u6240\u6709\u76d1\u542c\u7aef\u53e3\uff0c\u53bb\u6389 -t<\/strong> \u9009\u9879\u3002\u5982\u679c\u4f60\u53ea\u60f3\u67e5\u770b UDP \u7aef\u53e3\uff0c\u4f7f\u7528 -u<\/strong> \u9009\u9879\uff0c\u4ee3\u66ff -t<\/strong> \u9009\u9879\u3002<\/p>\n
\u6ce8\u610f\uff1a\u4e0d\u8981\u4f7f\u7528 -a<\/strong> \u9009\u9879\uff0c\u5426\u5219 netstat \u4f1a\u5217\u51fa\u6240\u6709\u8fde\u63a5\uff0c\u800c\u4e0d\u4ec5\u4ec5\u662f\u76d1\u542c\u7aef\u53e3\u3002<\/p>\n
5. \u83b7\u53d6\u8fdb\u7a0b\u540d\u3001\u8fdb\u7a0b\u53f7\u4ee5\u53ca\u7528\u6237 ID<\/strong><\/div>\n\u67e5\u770b\u7aef\u53e3\u548c\u8fde\u63a5\u7684\u4fe1\u606f\u65f6\uff0c\u80fd\u67e5\u770b\u5230\u5b83\u4eec\u5bf9\u5e94\u7684\u8fdb\u7a0b\u540d\u548c\u8fdb\u7a0b\u53f7\u5bf9\u7cfb\u7edf\u7ba1\u7406\u5458\u6765\u8bf4\u662f\u975e\u5e38\u6709\u5e2e\u52a9\u7684\u3002\u4e3e\u4e2a\u6817\u5b50\uff0cApache \u7684 httpd \u670d\u52a1\u5f00\u542f80\u7aef\u53e3\uff0c\u5982\u679c\u4f60\u8981\u67e5\u770b http \u670d\u52a1\u662f\u5426\u5df2\u7ecf\u542f\u52a8\uff0c\u6216\u8005 http \u670d\u52a1\u662f\u7531 apache \u8fd8\u662f nginx \u542f\u52a8\u7684\uff0c\u8fd9\u65f6\u5019\u4f60\u53ef\u4ee5\u770b\u770b\u8fdb\u7a0b\u540d\u3002<\/p>\n
\u4f7f\u7528 -p<\/strong> \u9009\u9879\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f\u3002<\/p>\n
~$ sudo netstat -nlpt\r\nActive Internet connections (only servers)\r\nProto Recv-Q Send-Q Local Address Foreign Address State PID\/Program name\r\ntcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN 1144\/dnsmasq \r\ntcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 661\/cupsd \r\ntcp6 0 0 ::1:631 :::* LISTEN 661\/cupsd\r\n<\/pre>\n\u4f7f\u7528 -p<\/strong> \u9009\u9879\u65f6\uff0cnetstat \u5fc5\u987b\u8fd0\u884c\u5728 root \u6743\u9650\u4e4b\u4e0b\uff0c\u4e0d\u7136\u5b83\u5c31\u4e0d\u80fd\u5f97\u5230\u8fd0\u884c\u5728 root \u6743\u9650\u4e0b\u7684\u8fdb\u7a0b\u540d\uff0c\u800c\u5f88\u591a\u670d\u52a1\u5305\u62ec http \u548c ftp \u90fd\u8fd0\u884c\u5728 root \u6743\u9650\u4e4b\u4e0b\u3002<\/p>\n
\u76f8\u6bd4\u8fdb\u7a0b\u540d\u548c\u8fdb\u7a0b\u53f7\u800c\u8a00\uff0c\u67e5\u770b\u8fdb\u7a0b\u7684\u62e5\u6709\u8005\u4f1a\u66f4\u6709\u7528\u3002\u4f7f\u7528 -ep<\/strong> \u9009\u9879\u53ef\u4ee5\u540c\u65f6\u67e5\u770b\u8fdb\u7a0b\u540d\u548c\u7528\u6237\u540d\u3002<\/p>\n
$ sudo netstat -ltpe\r\nActive Internet connections (only servers)\r\nProto Recv-Q Send-Q Local Address Foreign Address State User Inode PID\/Program name\r\ntcp 0 0 enlightened:domain *:* LISTEN root 11090 1144\/dnsmasq \r\ntcp 0 0 localhost:ipp *:* LISTEN root 9755 661\/cupsd \r\ntcp6 0 0 ip6-localhost:ipp [::]:* LISTEN root 9754 661\/cupsd\r\n<\/pre>\n\u4e0a\u9762\u5217\u51fa TCP \u534f\u8bae\u4e0b\u7684\u76d1\u542c\u5957\u63a5\u5b57\uff0c\u540c\u65f6\u663e\u793a\u8fdb\u7a0b\u4fe1\u606f\u548c\u4e00\u4e9b\u989d\u5916\u4fe1\u606f\u3002<\/p>\n
\u8fd9\u4e9b\u989d\u5916\u7684\u4fe1\u606f\u5305\u62ec\u7528\u6237\u540d\u548c\u8fdb\u7a0b\u7684\u7d22\u5f15\u8282\u70b9\u53f7\u3002\u8fd9\u4e2a\u547d\u4ee4\u5bf9\u7f51\u7ba1\u6765\u8bf4\u5f88\u6709\u7528\u3002<\/p>\n
\u6ce8\u610f<\/strong> \u2013 \u5047\u5982\u4f60\u5c06 -n<\/strong> \u548c -e<\/strong> \u9009\u9879\u4e00\u8d77\u4f7f\u7528\uff0cUser \u5217\u7684\u5c5e\u6027\u5c31\u662f\u7528\u6237\u7684 ID \u53f7\uff0c\u800c\u4e0d\u662f\u7528\u6237\u540d\u3002<\/p>\n
6. \u6253\u5370\u7edf\u8ba1\u6570\u636e<\/strong><\/div>\nnetstat \u53ef\u4ee5\u6253\u5370\u51fa\u7f51\u7edc\u7edf\u8ba1\u6570\u636e\uff0c\u5305\u62ec\u67d0\u4e2a\u534f\u8bae\u4e0b\u7684\u6536\u53d1\u5305\u6570\u91cf\u3002<\/p>\n
\u4e0b\u9762\u5217\u51fa\u6240\u6709\u7f51\u7edc\u5305\u7684\u7edf\u8ba1\u60c5\u51b5\uff1a<\/p>\n
$ netstat -s\r\nIp:\r\n 32797 total packets received\r\n 0 forwarded\r\n 0 incoming packets discarded\r\n 32795 incoming packets delivered\r\n 29115 requests sent out\r\n 60 outgoing packets dropped\r\nIcmp:\r\n 125 ICMP messages received\r\n 0 input ICMP message failed.\r\n ICMP input histogram:\r\n destination unreachable: 125\r\n 125 ICMP messages sent\r\n 0 ICMP messages failed\r\n ICMP output histogram:\r\n destination unreachable: 125\r\n... OUTPUT TRUNCATED ...\r\n<\/pre>\n\u5982\u679c\u60f3\u53ea\u6253\u5370\u51fa TCP \u6216 UDP \u534f\u8bae\u7684\u7edf\u8ba1\u6570\u636e\uff0c\u53ea\u8981\u52a0\u4e0a\u5bf9\u5e94\u7684\u9009\u9879\uff08-t<\/strong> \u548c -u<\/strong>\uff09\u5373\u53ef\uff0cso easy\u3002<\/p>\n
7. \u663e\u793a\u5185\u6838\u8def\u7531\u4fe1\u606f<\/strong><\/div>\n\u4f7f\u7528 -r<\/strong> \u9009\u9879\u6253\u5370\u5185\u6838\u8def\u7531\u4fe1\u606f\u3002\u6253\u5370\u51fa\u6765\u7684\u4fe1\u606f\u4e0e route \u547d\u4ee4\u8f93\u51fa\u7684\u4fe1\u606f\u4e00\u6837\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528 -n<\/strong> \u9009\u9879\u7981\u6b62\u57df\u540d\u89e3\u6790\u3002<\/p>\n
$ netstat -rn\r\nKernel IP routing table\r\nDestination Gateway Genmask Flags MSS Window irtt Iface\r\n0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0\r\n192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0\r\n<\/pre>\n8. \u6253\u5370\u7f51\u7edc\u63a5\u53e3<\/strong><\/div>\nnetstat \u4e5f\u80fd\u6253\u5370\u7f51\u7edc\u63a5\u53e3\u4fe1\u606f\uff0c-i<\/strong> \u9009\u9879\u5c31\u662f\u4e3a\u8fd9\u4e2a\u529f\u80fd\u800c\u751f\u3002<\/p>\n
$ netstat -i\r\nKernel Interface table\r\nIface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\r\neth0 1500 0 31611 0 0 0 27503 0 0 0 BMRU\r\nlo 65536 0 2913 0 0 0 2913 0 0 0 LRU\r\n<\/pre>\n\u4e0a\u9762\u8f93\u51fa\u7684\u4fe1\u606f\u6bd4\u8f83\u539f\u59cb\u3002\u6211\u4eec\u5c06 -e<\/strong> \u9009\u9879\u548c -i<\/strong> \u9009\u9879\u642d\u914d\u4f7f\u7528\uff0c\u53ef\u4ee5\u8f93\u51fa\u7528\u6237\u53cb\u597d\u7684\u4fe1\u606f\u3002<\/p>\n
$ netstat -ie\r\nKernel Interface table\r\neth0 Link encap:Ethernet HWaddr 00:16:36:f8:b2:64 \r\n inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0\r\n inet6 addr: fe80::216:36ff:fef8:b264\/64 Scope:Link\r\n UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1\r\n RX packets:31682 errors:0 dropped:0 overruns:0 frame:0\r\n TX packets:27573 errors:0 dropped:0 overruns:0 carrier:0\r\n collisions:0 txqueuelen:1000 \r\n RX bytes:29637117 (29.6 MB) TX bytes:4590583 (4.5 MB)\r\n Interrupt:18 Memory:da000000-da020000 \r\n\r\nlo Link encap:Local Loopback \r\n inet addr:127.0.0.1 Mask:255.0.0.0\r\n inet6 addr: ::1\/128 Scope:Host\r\n UP LOOPBACK RUNNING MTU:65536 Metric:1\r\n RX packets:2921 errors:0 dropped:0 overruns:0 frame:0\r\n TX packets:2921 errors:0 dropped:0 overruns:0 carrier:0\r\n collisions:0 txqueuelen:0 \r\n RX bytes:305297 (305.2 KB) TX bytes:305297 (305.2 KB)\r\n<\/pre>\n\u4e0a\u9762\u7684\u8f93\u51fa\u4fe1\u606f\u4e0e ifconfig \u8f93\u51fa\u7684\u4fe1\u606f\u4e00\u6837\u3002<\/p>\n
9. netstat \u6301\u7eed\u8f93\u51fa<\/strong><\/div>\n\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 netstat \u7684 -c<\/strong> \u9009\u9879\u6301\u7eed\u8f93\u51fa\u4fe1\u606f\u3002<\/p>\n
$ netstat -ct\r\n<\/pre>\n\u8fd9\u4e2a\u547d\u4ee4\u53ef\u6301\u7eed\u8f93\u51fa TCP \u534f\u8bae\u4fe1\u606f\u3002<\/p>\n
10. \u663e\u793a\u591a\u64ad\u7ec4\u4fe1\u606f<\/strong><\/div>\n\u9009\u9879 -g<\/strong> \u4f1a\u8f93\u51fa IPv4 \u548c IPv6 \u7684\u591a\u64ad\u7ec4\u4fe1\u606f\u3002<\/p>\n
$ netstat -g\r\nIPv6\/IPv4 Group Memberships\r\nInterface RefCnt Group\r\n--------------- ------ ---------------------\r\nlo 1 all-systems.mcast.net\r\neth0 1 224.0.0.251\r\neth0 1 all-systems.mcast.net\r\nlo 1 ip6-allnodes\r\nlo 1 ff01::1\r\neth0 1 ff02::fb\r\neth0 1 ff02::1:fff8:b264\r\neth0 1 ip6-allnodes\r\neth0 1 ff01::1\r\nwlan0 1 ip6-allnodes\r\nwlan0 1 ff01::1\r\n<\/pre>\n\u66f4\u591a\u7528\u6cd5<\/strong><\/div>\n\u76ee\u524d\u4e3a\u6b62\u6211\u4eec\u5217\u51fa\u4e86 netstat \u7684\u57fa\u672c\u7528\u6cd5\uff0c\u73b0\u5728\u8ba9\u6211\u4eec\u4e00\u8d77\u6765 geek \u5427\uff5e<\/p>\n
\u6253\u5370 active \u72b6\u6001\u7684\u8fde\u63a5<\/strong><\/div>\nactive \u72b6\u6001\u7684\u5957\u63a5\u5b57\u8fde\u63a5\u7528 \u201cESTABLISHED\u201d \u5b57\u6bb5\u8868\u793a\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 grep \u547d\u4ee4\u83b7\u5f97 active \u72b6\u6001\u7684\u8fde\u63a5\uff1a<\/p>\n
$ netstat -atnp | grep ESTA\r\n(Not all processes could be identified, non-owned process info\r\n will not be shown, you would have to be root to see it all.)\r\ntcp 0 0 192.168.1.2:49156 173.255.230.5:80 ESTABLISHED 1691\/chrome \r\ntcp 0 0 192.168.1.2:33324 173.194.36.117:443 ESTABLISHED 1691\/chrome\r\n<\/pre>\n\u914d\u5408 watch \u547d\u4ee4\u76d1\u89c6 active \u72b6\u6001\u7684\u8fde\u63a5\uff1a<\/p>\n
$ watch -d -n0 \"netstat -atnp | grep ESTA\"\r\n<\/pre>\n\u67e5\u770b\u670d\u52a1\u662f\u5426\u5728\u8fd0\u884c<\/strong><\/div>\n\u5982\u679c\u4f60\u60f3\u770b\u770b http,smtp \u6216 ntp \u670d\u52a1\u662f\u5426\u5728\u8fd0\u884c\uff0c\u4f7f\u7528 grep\u3002<\/p>\n
\r\n$ sudo netstat -aple | grep ntp\r\nudp 0 0 enlightened.local:ntp *:* root 17430 1789\/ntpd \r\nudp 0 0 localhost:ntp *:* root 17429 1789\/ntpd \r\nudp 0 0 *:ntp *:* root 17422 1789\/ntpd \r\nudp6 0 0 fe80::216:36ff:fef8:ntp [::]:* root 17432 1789\/ntpd \r\nudp6 0 0 ip6-localhost:ntp [::]:* root 17431 1789\/ntpd \r\nudp6 0 0 [::]:ntp [::]:* root 17423 1789\/ntpd \r\nunix 2 [ ] DGRAM 17418 1789\/ntpd\r\n<\/pre>\n\u4ece\u8fd9\u91cc\u53ef\u4ee5\u770b\u5230 ntp \u670d\u52a1\u6b63\u5728\u8fd0\u884c\u3002\u4f7f\u7528 grep \u547d\u4ee4\u4f60\u53ef\u4ee5\u67e5\u770b http \u6216 smtp \u6216\u5176\u5b83\u4efb\u4f55\u4f60\u60f3\u67e5\u770b\u7684\u670d\u52a1\u3002<\/p>\n
\u597d\u4e86\uff0cnetstat \u7684\u5927\u90e8\u5206\u529f\u80fd\u90fd\u4ecb\u7ecd\u8fc7\u4e86\uff0c\u5982\u679c\u4f60\u60f3\u77e5\u9053 netstat \u66f4\u9ad8\u7ea7\u7684\u529f\u80fd\uff0c\u9605\u8bfb\u5b83\u7684\u624b\u518c\u5427\uff08man netstat\uff09\u3002<\/p>\n
\n\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/blog.jobbole.com\/113094\/<\/a><\/p>\n