Netstat 命令
netstat
命令显示网络连接的状态.
显示当前活动的网络连接
➤ netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:44244 0.0.0.0:* LISTEN
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
... ... ...
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] DGRAM 22370 /run/user/1000/systemd/notify
unix 2 [ ACC ] STREAM LISTENING 23426 @/tmp/.ICE-unix/2548
unix 2 [ ACC ] STREAM LISTENING 22371 /run/user/1000/systemd/private
unix 2 [ ACC ] SEQPACKET LISTENING 8934 /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 20436 /run/user/1000/keyring/control
unix 2 [ ACC ] STREAM LISTENING 24609 /tmp/fcitx-socket-:0
unix 2 [ ACC ] STREAM LISTENING 27013 /tmp/sogou-qimpanel-cell
显示运行程序的进程号/程序名
➤ netstat -tapn
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:44244 0.0.0.0:* LISTEN 9720/1452662683780-
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:587 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:47034 127.0.0.1:44244 ESTABLISHED 9680/editor
tcp 0 0 127.0.0.1:44244 127.0.0.1:47034 ESTABLISHED 9720/1452662683780-
tcp 0 0 127.0.0.1:47038 127.0.0.1:44244 ESTABLISHED 9680/editor
tcp 0 0 127.0.0.1:44244 127.0.0.1:47038 ESTABLISHED 9720/1452662683780-
tcp6 0 0 :::1080 :::* LISTEN 31588/shadowsocks
tcp6 0 0 :::1088 :::* LISTEN 31589/shadowsocks
在最后一列有运行的进程号/程序名.
显示路由表
➤ netstat --route
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
link-local * 255.255.0.0 U 0 0 0 docker0
172.17.0.0 * 255.255.0.0 U 0 0 0 docker0
显示RAW网络统计
➤ netstat --statistics --raw
Ip:
3046724 total packets received
20 forwarded
0 incoming packets discarded
3045898 incoming packets delivered
1985453 requests sent out
48 outgoing packets dropped
1611 dropped because of missing route
Icmp:
474 ICMP messages received
0 input ICMP message failed.
ICMP input histogram:
destination unreachable: 471
echo requests: 3
1999 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 1996
echo replies: 3
IcmpMsg:
InType3: 471
InType8: 3
OutType0: 3
OutType3: 1996
UdpLite:
IpExt:
InNoRoutes: 38
InMcastPkts: 143
OutMcastPkts: 164
InBcastPkts: 310
OutBcastPkts: 6
InOctets: 5251249872
OutOctets: 149575262
InMcastOctets: 26980
OutMcastOctets: 27820
InBcastOctets: 32799
OutBcastOctets: 284
InNoECTPkts: 3750022
➤
(显示太占篇幅了...)
其他
netstat –-tcp –-numeric
列出本机的TCP连接netstat --tcp --listening –-programs
显示系统正在监听的端口以及程序
➤ netstat --tcp --listening –-programs -n
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:44244 0.0.0.0:* LISTEN
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:587 0.0.0.0:* LISTEN
tcp6 0 0 :::1080 :::* LISTEN
tcp6 0 0 :::1088 :::* LISTEN
netstat –rnC
显示路由缓存