Linux命令之netstat
程序员文章站
2022-05-31 11:14:20
...
Linux命令之netstat
学习netstat命令
查看帮助文档
**netstat -h**
[[email protected] ~]# netstat -h
-r, --route display routing table
-I, --interfaces=<Iface> display interface table for <Iface>
-i, --interfaces display interface table
-g, --groups display multicast group memberships
-s, --statistics display networking statistics (like SNMP)
-M, --masquerade display masqueraded connections
-v, --verbose be verbose
-W, --wide don't truncate IP addresses
-n, --numeric don't resolve names
--numeric-hosts don't resolve host names
--numeric-ports don't resolve port names
--numeric-users don't resolve user names
-N, --symbolic resolve hardware names
-e, --extend display other/more information
-p, --programs display PID/Program name for sockets
-o, --timers display timers
-c, --continuous continuous listing
-l, --listening display listening server sockets
-a, --all display all sockets (default: connected)
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
-Z, --context display SELinux security context for sockets
通过帮助文档我们大概能了解每个选项所能实现的功能
通过几个实例来看一下效果
netstat -a
这会显示系统所有的 tcp、udp 以及 unix 连接。
netstat -at
使用t选项只列出tcp连接
netstat -au
使用u选项只列出udp连接
netstat -ax
使用x选项只列出Unix socket连接
netstat -ap
列出进程ID/进程名称
netstat -an
列出端口号而不是服务名
netstat -l
使用l选项只输出监听端口。他不能与a一起使用,因为a选项是会输出所有端口。
netstat -c
持续输出结果
netstat -r
使用r输出网络路由信息
netstat -g
使用g 选项输出 IPV4以及IPV6 的多播组信息
netstat -s
使用 s 选项输出每个协议的统计信息,包括接收/发送的包数量
过滤某个端口
netstat -anp|grep 3306
统计连接数
netstat -anp|grep 3306|wc -l
上一篇: linux免密登录