时间:2014-12-30 15:59:47 作者:qipeng 来源:系统之家 1. 扫描二维码随时看资讯 2. 请使用手机浏览器访问: https://m.xitongzhijia.net/xtjc/20141230/33733.html 手机查看 评论 反馈
输出:
代码如下:
[root@localhost ~]# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:smux *:* LISTEN
tcp 0 0 *:svn *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
udp 0 0 localhost:syslog *:*
udp 0 0 *:snmp *:*
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 708833 /tmp/ssh-yKnDB15725/agent.15725
unix 2 [ ACC ] STREAM LISTENING 7296 /var/run/audispd_events
[root@localhost ~]#
实例9:显示所有已建立的有效连接
命令:netstat -n
输出:
代码如下:
[root@localhost ~]# netstat -n
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 268 192.168.120.204:22 10.2.0.68:62420 ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] DGRAM 1491 @/org/kernel/udev/udevd
unix 4 [ ] DGRAM 7337 /dev/log
unix 2 [ ] DGRAM 708823
unix 2 [ ] DGRAM 7539
unix 3 [ ] STREAM CONNECTED 7287
unix 3 [ ] STREAM CONNECTED 7286
[root@localhost ~]#
实例10:显示关于以太网的统计数据
命令:netstat -e
输出:
代码如下:
[root@localhost ~]# netstat -e
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode
tcp 0 248 192.168.120.204:ssh 10.2.0.68:62420 ESTABLISHED root 708795
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] DGRAM 1491 @/org/kernel/udev/udevd
unix 4 [ ] DGRAM 7337 /dev/log
unix 2 [ ] DGRAM 708823
unix 2 [ ] DGRAM 7539
unix 3 [ ] STREAM CONNECTED 7287
unix 3 [ ] STREAM CONNECTED 7286
[root@localhost ~]#
说明:
用于显示关于以太网的统计数据。它列出的项目包括传送的数据报的总字节数、错误数、删除数、数据报的数量和广播的数量。这些统计数据既有发送的数据报数量,也有接收的数据报数量。这个选项可以用来统计一些基本的网络流量)
实例11:显示关于路由表的信息
命令:netstat -r
输出:
代码如下:
[root@localhost ~]# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.120.0 * 255.255.255.0 U 0 0 0 eth0
192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
[root@localhost ~]#
实例12:列出所有 tcp 端口
命令:netstat -at
输出:
代码如下:
[root@localhost ~]# netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:smux *:* LISTEN
tcp 0 0 *:svn *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 284 192.168.120.204:ssh 10.2.0.68:62420 ESTABLISHED
[root@localhost ~]#
实例13:统计机器中网络连接各个状态个数
命令:netstat -a | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’
输出:
代码如下:
[root@localhost ~]# netstat -a | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’
ESTABLISHED 1
LISTEN 3
[root@localhost ~]#
实例14:把状态全都取出来后使用uniq -c统计后再进行排序
命令:netstat -nat |awk ‘{print $6}’|sort|uniq -c
输出:
代码如下:
[root@andy ~]# netstat -nat |awk ‘{print $6}’|sort|uniq -c
14 CLOSE_WAIT
1 established)
578 ESTABLISHED
1 Foreign
43 LISTEN
5 TIME_WAIT
[root@andy ~]# netstat -nat |awk ‘{print $6}’|sort|uniq -c|sort -rn
576 ESTABLISHED
43 LISTEN
14 CLOSE_WAIT
5 TIME_WAIT
1 Foreign
1 established)
[root@andy ~]#
发表评论
共0条
评论就这些咯,让大家也知道你的独特见解
立即评论以上留言仅代表用户个人观点,不代表系统之家立场