linux netstat 命令简介

常用选项:

        -r, --route              显示路由表
        -i, --interfaces         显示接口信息表-s, --statistics         显示网络协议汇总信息
        -n, --numeric            不解析域名-p, --programs           为端口显示pid或者软件名称
-o, --timers 显示计时器 -c, --continuous 连续显示 -l, --listening 显示正在监听的服务端口 -a, --all 显示所有端口(默认只显示: connected 的端口)

常用示例:

#查看路由器表
[root@localhost ~]# netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 10.10.0.1 0.0.0.0 UG 0 0 0 ens192 10.10.0.0 0.0.0.0 255.255.0.0 U 0 0 0 ens192 172.31.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
#查看正在监听的tcp端口,并显示对应的监听程序
[root@localhost ~]# netstat -ntpl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15614/nginx: master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6596/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6245/master tcp6 0 0 :::22 :::* LISTEN 6596/sshd tcp6 0 0 ::1:25 :::* LISTEN 6245/master
#查看正在监听的udp端口,并显示对应的监听程序
[root@localhost ~]# netstat -nupl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp 0 0 127.0.0.1:323 0.0.0.0:* 5711/chronyd udp6 0 0 ::1:323 :::* 5711/chronyd
#显示所有tcp连接及监听端口
[root@localhost ~]# netstat -ant Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 96 10.10.0.110:22 172.17.1.128:56848 ESTABLISHED tcp 0 0 10.10.0.110:22 172.17.1.128:62703 ESTABLISHED tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN
#显示所有udp连接及监听端口及连接的程序
[root@localhost ~]# netstat -anup Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp 0 0 10.10.0.110:32932 114.114.114.114:53 ESTABLISHED 18481/nginx: worker udp 0 0 127.0.0.1:323 0.0.0.0:* 5711/chronyd udp6 0 0 ::1:323 :::* 5711/chronyd

  可以按照实际情况有选择的选择命令选项,达到想要查看的目的。

猜你喜欢

转载自www.cnblogs.com/yyxianren/p/10820800.html