Linux 统计主机网络连接数

本文档展示了主机的网络连接状态,通过`netstat`命令分析了TCP连接的分布,包括不同IP地址和链接状态的统计。同时,提供了最近的系统日志,日志中涉及网络设备进入 promiscuous 和 forwarding 模式,以及网络接口的状态变化。

文章目录


netstat -n | awk '/^tcp/ {n=split($(NF-1),array,":");if(n<=2)++S[array[(1)]];else++S[array[(4)]];++s[$NF];++N} END {for(a in S){printf("%-20s %s\n", a, S[a]);++I}printf("%-20s %s\n","TOTAL_IP",I);for(a in s) printf("%-20s %s\n",a, s[a]);printf("%-20s %s\n","TOTAL_LINK",N);}'

[root@master ~]#netstat -n | awk '/^tcp/ {n=split($(NF-1),array,":");if(n<=2)++S[array[(1)]];else++S[array[(4)]];++s[$NF];++N} END {for(a in S){printf("%-20s %s\n", a, S[a]);++I}printf("%-20s %s\n","TOTAL_IP",I);for(a in s) printf("%-20s %s\n",a, s[a]);printf("%-20s %s\n","TOTAL_LINK",N);}'
42334                1
6443                 1
192.168.10.1         1
192.168.10.65        16
192.168.10.66        3
192.168.10.67        3
127.0.0.1            161
10.96.0.1            1
10.244.0.10          1
10.244.0.8           1
TOTAL_IP             10
ESTABLISHED          183
TIME_WAIT            6
TOTAL_LINK           189

观察主机系统日志

[root@master ~]#dmesg -T  | tail -n 10
[Tue Jul 12 15:04:05 2022] device vetha2622729 entered promiscuous mode
[Tue Jul 12 15:04:05 2022] cni0: port 2(vetha2622729) entered blocking state
[Tue Jul 12 15:04:05 2022] cni0: port 2(vetha2622729) entered forwarding state
[Tue Jul 12 15:04:05 2022] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[Tue Jul 12 15:04:05 2022] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[Tue Jul 12 15:04:05 2022] cni0: port 3(veth9515c149) entered blocking state
[Tue Jul 12 15:04:05 2022] cni0: port 3(veth9515c149) entered disabled state
[Tue Jul 12 15:04:05 2022] device veth9515c149 entered promiscuous mode
[Tue Jul 12 15:04:05 2022] cni0: port 3(veth9515c149) entered blocking state
[Tue Jul 12 15:04:05 2022] cni0: port 3(veth9515c149) entered forwarding state

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值