20个对Linux专家非常有用命令(1)(2)
2. 命令: netstat
netstat命令显示各种网络相关的信息,如网络连接,路由表,接口统计,伪装连接,组播成员身份等....
列出所有的网络端口
- [avishek@tecmint ~]$ netstat -a
- Active UNIX domain sockets (servers and established)
- Proto RefCnt Flags Type State I-Node Path
- unix 2 [ ACC ] STREAM LISTENING 741379 /run/user/user1/keyring-I5cn1c/gpg
- unix 2 [ ACC ] STREAM LISTENING 8965 /var/run/acpid.socket
- unix 2 [ ACC ] STREAM LISTENING 18584 /tmp/.X11-unix/X0
- unix 2 [ ACC ] STREAM LISTENING 741385 /run/user/user1/keyring-I5cn1c/ssh
- unix 2 [ ACC ] STREAM LISTENING 741387 /run/user/user1/keyring-I5cn1c/pkcs11
- unix 2 [ ACC ] STREAM LISTENING 20242 @/tmp/dbus-ghtTjuPN46
- unix 2 [ ACC ] STREAM LISTENING 13332 /var/run/samba/winbindd_privileged/pipe
- unix 2 [ ACC ] STREAM LISTENING 13331 /tmp/.winbindd/pipe
- unix 2 [ ACC ] STREAM LISTENING 11030 /var/run/mysqld/mysqld.sock
- unix 2 [ ACC ] STREAM LISTENING 19308 /tmp/ssh-qnZadSgJAbqd/agent.3221
- unix 2 [ ACC ] STREAM LISTENING 436781 /tmp/HotShots
- unix 2 [ ACC ] STREAM LISTENING 46110 /run/user/ravisaive/pulse/native
- unix 2 [ ACC ] STREAM LISTENING 19310 /tmp/gpg-zfE9YT/S.gpg-agent
- ....
显示所有tcp相关端口
- [avishek@tecmint ~]$ netstat -at
- Active Internet connections (servers and established)
- Proto Recv-Q Send-Q Local Address Foreign Address State
- tcp 0 0 localhost:mysql *:* LISTEN
- tcp 0 0 *:5901 *:* LISTEN
- tcp 0 0 *:5902 *:* LISTEN
- tcp 0 0 *:x11-1 *:* LISTEN
- tcp 0 0 *:x11-2 *:* LISTEN
- tcp 0 0 *:5938 *:* LISTEN
- tcp 0 0 localhost:5940 *:* LISTEN
- tcp 0 0 ravisaive-OptiPl:domain *:* LISTEN
- tcp 0 0 ravisaive-OptiPl:domain *:* LISTEN
- tcp 0 0 localhost:ipp *:* LISTEN
- tcp 0 0 ravisaive-OptiPle:48270 ec2-23-21-236-70.c:http ESTABLISHED
- tcp 0 0 ravisaive-OptiPle:48272 ec2-23-21-236-70.c:http TIME_WAIT
- tcp 0 0 ravisaive-OptiPle:48421 bom03s01-in-f22.1:https ESTABLISHED
- tcp 0 0 ravisaive-OptiPle:48269 ec2-23-21-236-70.c:http ESTABLISHED
- tcp 0 0 ravisaive-OptiPle:39084 channel-ecmp-06-f:https ESTABLISHED
- ...
显示所有连接的统计信息
- [avishek@tecmint ~]$ netstat -s
- Ip:
- 4994239 total packets received
- 0 forwarded
- 0 incoming packets discarded
- 4165741 incoming packets delivered
- 3248924 requests sent out
- 8 outgoing packets dropped
- Icmp:
- 29460 ICMP messages received
- 566 input ICMP message failed.
- ICMP input histogram:
- destination unreachable: 98
- redirects: 29362
- 2918 ICMP messages sent
- 0 ICMP messages failed
- ICMP output histogram:
- destination unreachable: 2918
- IcmpMsg:
- InType3: 98
- InType5: 29362
- OutType3: 2918
- Tcp:
- 94533 active connections openings
- 23 passive connection openings
- 5870 failed connection attempts
- 7194 connection resets received
- ....
好的!由于某些原因如果你不想解析netstat 输出的主机、端口和用户名称的话 。
- [avishek@tecmint ~]$ netstat -an
好,你可能需要获取的 netstat 持续输出的动态信息,通过传递中断输出指令 (ctrl + c)来停止。
- [avishek@tecmint ~]$ netstat -c
更多关于“netstat”的例子和使用方法,浏览文章“20个netstat 的使用案例”。
评论暂时关闭