版权声明:本文为博主原创文章,商业转载请联系作者获得授权,非商业转载请注明出处。 https://blog.csdn.net/liitdar/article/details/87973643
本文主要介绍在 Linux 中 netstat 命令的相关内容。
1 概述
1.1 what
此处选取 rsync man手册的相关介绍:
netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
详细描述如下:
Netstat prints information about the Linux networking subsystem.
2 用法
2.1 查看tcp连接信息
查看系统当前的 tcp 连接,命令如下:
netstat -anpot
上面命令中涉及的选项解释如下:
- -a, --all:Show both listening and non-listening (for TCP this means established connections) sockets.
- -n, --numeric:Shows numerical port numbers but does not affect the resolution of host or user names.
- -p, --program:Show the PID and name of the program to which each socket belongs.
- -o, --timers:Include information related to networking timers.
- -t,--tcp:Show TCP connections.
2.2 查看路由信息
查看系统当前的路由信息(包括网关),命令如下:
[root@node1 ~]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.120.2 0.0.0.0 UG 0 0 0 ens32
192.168.120.0 0.0.0.0 255.255.255.0 U 0 0 0 ens32
[root@node1 ~]#