显示网络状态

语法格式:netstat 参数

常用参数

-a

显示所有连接中的接口信息

-n

直接使用ip地址,而不是域名

-A

设置网络连接类型

-N

显示网络硬件外围设备的符号链接名称

-c

持续显示网络状态

-o

显示计时器数据信息

-C

显示路由配置信息

-p

显示正在使用接口的程序识别码和名称

-F

显示路由缓存信息

-r

显示路由表信息

-g

显示多重广播功能群组成员名单

-s

显示网络工作信息统计表信息

-h

显示帮助信息

-t

显示TCP传输协议的连接状态

-i

显示网络界面信息表单

-u

显示UDP传输协议的连接状态

-l

仅显示正在监听的服务状态

-V

显示版本信息

参考示例

显示系统网络状态中的所有连接信息

[root@liuwei ~]# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN     
tcp        0      0 iZuf6ih4q2o15k68600:ssh 82.118.242.220:https    SYN_RECV   
tcp        0      0 iZuf6ih4q2o15k686:59960 100.100.30.26:http      ESTABLISHED
tcp        0      0 iZuf6ih4q2o15k686:60264 100.100.36.108:http     TIME_WAIT  
tcp        0    232 iZuf6ih4q2o15k68600:ssh 58.214.121.96:21704     ESTABLISHED
udp        0      0 0.0.0.0:bootpc          0.0.0.0:*                          
udp        0      0 localhost:323           0.0.0.0:*                          
udp6       0      0 localhost:323           [::]:*                             
Active UNIX domain sockets (servers and established)

显示系统网络状态中的UDP连接信息

[root@liuwei ~]# netstat -nu
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State

显示系统网络状态中的UDP连接端口号使用信息

[root@liuwei ~]# netstat -apu
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
udp        0      0 0.0.0.0:bootpc          0.0.0.0:*                           1116/dhclient       
udp        0      0 localhost:323           0.0.0.0:*                           742/chronyd         
udp6       0      0 localhost:323           [::]:*                              742/chronyd

显示网卡当前状态信息

[root@liuwei ~]# netstat -i
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
bond0            1500        0      0      0 0             0      0      0      0 BMmU
eth0             1500   421821      0      0 0        364722      0      0      0 BMRU
lo              65536        0      0      0 0             0      0      0      0 LRU

显示网络路由表状态信息

[root@liuwei ~]# netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         _gateway        0.0.0.0         UG        0 0          0 eth0
link-local      0.0.0.0         255.255.0.0     U         0 0          0 eth0
172.24.112.0    0.0.0.0         255.255.240.0   U         0 0          0 eth0

找到某个服务所对应的连接信息

[root@liuwei ~]# netstat -ap | grep ssh
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN      1331/sshd           
tcp        0     52 iZuf6ih4q2o15k68600:ssh 58.214.121.96:21704     ESTABLISHED 265151/sshd: root [ 
unix  3      [ ]         STREAM     CONNECTED     185981812 265219/sshd: root@p  
unix  3      [ ]         STREAM     CONNECTED     185981813 265151/sshd: root [

-------------------------------------------

个性签名:代码过万,键盘敲烂!!!