日期:2014-05-16  浏览次数:20772 次

Linux: 10 个 Netstat 命令实例

Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等。本文提供 10 个非常实用的 Netstat 命令实例。

?

1. 列出所有端口 (包括监听和未监听的)


列出所有端口 netstat -a

?

netstat -a | more

[root@diancai1 ~]# netstat -a | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 *:5666                      *:*                         LISTEN      
tcp        0      0 *:rsync                     *:*                         LISTEN      
tcp        0      0 diancai1.com:47537          115.239.224.60:60000        ESTABLISHED 
tcp        0      0 *:6080                      *:*                         LISTEN      
tcp        0      0 localhost.localdomain:8035  *:*                         LISTEN      
tcp        0      0 *:8039                      *:*                         LISTEN      
tcp        0      0 *:7080                      *:*                         LISTEN      
tcp        0      0 *:rsync                     *:*                         LISTEN      
tcp        0      0 localhost.localdomain:8015  *:*                         LISTEN      
tcp        0      0 *:webcache                  *:*                         LISTEN      
tcp        0      0 *:personal-agent            *:*                         LISTEN      
tcp        0      0 *:8019                      *:*                         LISTEN      
tcp        0      0 *:ssh                       *:*                         LISTEN      
tcp        0      0 *:glrpc                     *:*                         LISTEN      
tcp        0      0 localhost.localdomain:8025  *:*                         LISTEN      
tcp        0      0 *:8029                      *:*                         LISTEN      
tcp        0      0 *:esri_sde                  *:*                         LISTEN      
tcp        0     48 diancai1.com:ssh            localhost:57648             ESTABLISHED 
tcp        0      0 diancai1.com:55624          localhost:mysql             ESTABLISHED 
tcp        0      0 diancai1.com:53528          localhost:mysql             ESTABLISHED 
tcp        0      0 diancai1.com:53529          localhost:mysql             ESTABLISHED 
tcp        0      0 diancai1.com:53484          localhost:mysql             ESTABLISHED 
tcp        0      0 diancai1.com:53483          localhost:mysql             ESTABLISHED 
tcp        0      0 diancai1.com:53482          localhost:mysql             ESTABLISHED 

?

?

列出所有 tcp 端口 netstat -at

?

[root@diancai1 ~]# netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 *:5666                      *:*                         LISTEN      
tcp        0      0 *:rsync                     *:*                         LISTEN      
tcp        0      0 diancai1.com:47537          115.239.224.60:60000        ESTABLISHED 
tcp        0      0 *:6080                      *:*                         LISTEN      
tcp        0      0 localhost.localdomain:8035  *:*                         LISTEN      
tcp        0      0 *:8039                      *:*                         LISTEN      
tcp        0      0 *:7080                      *:*                         LISTEN      
tcp        0      0 *:rsync                     *:*                         LISTEN      
tcp        0      0 localhost.localdomain:8015  *:*                         LISTEN      
tcp        0      0 *:webcache                  *:*                         LISTEN      
tcp        0      0 *:personal-agent            *:*                         LISTEN      
tcp        0      0 *:8019                      *:*