2. 命令: netstat

netstat命令显示各种网络相关的信息,如网络连接,路由表,接口统计,伪装连接,组播成员身份等....

列出所有的网络端口

  1. [avishek@tecmint ~]$ netstat -a 
  2. Active UNIX domain sockets (servers and established) 
  3. Proto RefCnt Flags       Type       State         I-Node   Path 
  4. unix  2      [ ACC ]     STREAM     LISTENING     741379   /run/user/user1/keyring-I5cn1c/gpg 
  5. unix  2      [ ACC ]     STREAM     LISTENING     8965     /var/run/acpid.socket 
  6. unix  2      [ ACC ]     STREAM     LISTENING     18584    /tmp/.X11-unix/X0 
  7. unix  2      [ ACC ]     STREAM     LISTENING     741385   /run/user/user1/keyring-I5cn1c/ssh 
  8. unix  2      [ ACC ]     STREAM     LISTENING     741387   /run/user/user1/keyring-I5cn1c/pkcs11 
  9. unix  2      [ ACC ]     STREAM     LISTENING     20242    @/tmp/dbus-ghtTjuPN46 
  10. unix  2      [ ACC ]     STREAM     LISTENING     13332    /var/run/samba/winbindd_privileged/pipe 
  11. unix  2      [ ACC ]     STREAM     LISTENING     13331    /tmp/.winbindd/pipe 
  12. unix  2      [ ACC ]     STREAM     LISTENING     11030    /var/run/mysqld/mysqld.sock 
  13. unix  2      [ ACC ]     STREAM     LISTENING     19308    /tmp/ssh-qnZadSgJAbqd/agent.3221 
  14. unix  2      [ ACC ]     STREAM     LISTENING     436781   /tmp/HotShots 
  15. unix  2      [ ACC ]     STREAM     LISTENING     46110    /run/user/ravisaive/pulse/native 
  16. unix  2      [ ACC ]     STREAM     LISTENING     19310    /tmp/gpg-zfE9YT/S.gpg-agent 
  17. .... 

显示所有tcp相关端口

  1. [avishek@tecmint ~]$ netstat -at 
  2. Active Internet connections (servers and established) 
  3. Proto Recv-Q Send-Q Local Address           Foreign Address         State 
  4. tcp        0      0 localhost:mysql         *:*                     LISTEN 
  5. tcp        0      0 *:5901                  *:*                     LISTEN 
  6. tcp        0      0 *:5902                  *:*                     LISTEN 
  7. tcp        0      0 *:x11-1                 *:*                     LISTEN 
  8. tcp        0      0 *:x11-2                 *:*                     LISTEN 
  9. tcp        0      0 *:5938                  *:*                     LISTEN 
  10. tcp        0      0 localhost:5940          *:*                     LISTEN 
  11. tcp        0      0 ravisaive-OptiPl:domain *:*                     LISTEN 
  12. tcp        0      0 ravisaive-OptiPl:domain *:*                     LISTEN 
  13. tcp        0      0 localhost:ipp           *:*                     LISTEN 
  14. tcp        0      0 ravisaive-OptiPle:48270 ec2-23-21-236-70.c:http ESTABLISHED 
  15. tcp        0      0 ravisaive-OptiPle:48272 ec2-23-21-236-70.c:http TIME_WAIT 
  16. tcp        0      0 ravisaive-OptiPle:48421 bom03s01-in-f22.1:https ESTABLISHED 
  17. tcp        0      0 ravisaive-OptiPle:48269 ec2-23-21-236-70.c:http ESTABLISHED 
  18. tcp        0      0 ravisaive-OptiPle:39084 channel-ecmp-06-f:https ESTABLISHED 
  19. ... 

显示所有连接的统计信息

  1. [avishek@tecmint ~]$ netstat -s 
  2. Ip: 
  3. 4994239 total packets received 
  4. 0 forwarded 
  5. 0 incoming packets discarded 
  6. 4165741 incoming packets delivered 
  7. 3248924 requests sent out 
  8. 8 outgoing packets dropped 
  9. Icmp: 
  10. 29460 ICMP messages received 
  11. 566 input ICMP message failed. 
  12. ICMP input histogram: 
  13. destination unreachable: 98 
  14. redirects: 29362 
  15. 2918 ICMP messages sent 
  16. 0 ICMP messages failed 
  17. ICMP output histogram: 
  18. destination unreachable: 2918 
  19. IcmpMsg: 
  20. InType3: 98 
  21. InType5: 29362 
  22. OutType3: 2918 
  23. Tcp: 
  24. 94533 active connections openings 
  25. 23 passive connection openings 
  26. 5870 failed connection attempts 
  27. 7194 connection resets received 
  28. .... 

好的!由于某些原因如果你不想解析netstat 输出的主机、端口和用户名称的话 。

  1. [avishek@tecmint ~]$ netstat -an 

好,你可能需要获取的 netstat 持续输出的动态信息,通过传递中断输出指令 (ctrl + c)来停止。

  1. [avishek@tecmint ~]$ netstat -c 

更多关于“netstat”的例子和使用方法,浏览文章“20个netstat 的使用案例”。


相关内容