1. 查看当前系统每IP连接数
[root@oldboy ~]# netstat -an Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 192.168.0.109:22 192.168.0.102:49801 ESTABLISHED tcp 0 0 :::22 :::* LISTEN udp 0 0 0.0.0.0:68 0.0.0.0:* Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path unix 5 [ ] DGRAM 9255 /dev/log unix 2 [ ACC ] STREAM LISTENING 9766 /var/lib/mysql/mysql.sock unix 2 [ ACC ] STREAM LISTENING 7096 @/com/ubuntu/upstart unix 2 [ ] DGRAM 7497 @/org/kernel/udev/udevd unix 2 [ ] DGRAM 13757 unix 2 [ ] DGRAM 11955 unix 2 [ ] DGRAM 9802 unix 3 [ ] DGRAM 7515 unix 3 [ ] DGRAM 7514 # 过滤其中状态为ESTABLISHED的记录 [root@oldboy ~]# netstat -an|grep "ESTABLISHED" tcp 0 0 192.168.0.109:22 192.168.0.102:49801 ESTABLISHED # 过滤ip [root@oldboy ~]# netstat -an|grep "ESTABLISHED"|awk '{print $4}' 192.168.0.109:22 [root@oldboy ~]# netstat -an|grep "ESTABLISHED"|awk '{print $4}'|awk -F: '{print $1}' 192.168.0.109 # 多个ip则排序后再计数 [root@oldboy ~]# netstat -an|grep "ESTABLISHED"|awk '{print $4}'|awk -F: '{print $1}'|sort -n 192.168.0.109 [root@oldboy ~]# netstat -an|grep "ESTABLISHED"|awk '{print $4}'|awk -F: '{print $1}'|sort -n|uniq -c 1 192.168.0.109
2. 请列出以下服务使用的端口