网络信息统计netstat|ss|ip

1:netstate[弃用]

netstat的作用:

需求 原命令 新命令
1:网络连接 netstat -a ss
2:路由表 netstat -r ip route
3:统计接口 netstat -v ip -s link
4:伪连接 netstat -M ss
5:组播成员 netstat -g ip maddr

2:ss:Socket Statistics :获取socket统计信息

1:查询ss是否安装
[root@localhost ~]# rpm -qf /usr/sbin/ss
iproute-3.10.0-13.el7.x86_64
[root@localhost ~]# rpm -q iproute
iproute-3.10.0-13.el7.x86_64


2:查看当前服务器的网络连接统计
[root@localhost ~]# ss -s
Total: 434 (kernel 459)
TCP:   6 (estab 2, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 0

Transport Total     IP        IPv6
*         459       -         -        
RAW       1         0         1        
UDP       2         2         0        
TCP       6         4         2        
INET      9         6         3        
FRAG      0         0         0

3:查看所有打开的网络端口
[root@localhost ~]# ss -l
[root@localhost ~]# ss -pl | grep sshd           ### -p列出具体的程序名称
tcp    LISTEN     0      128                  *:ssh                   *:*        users:(("sshd",1618,3))
tcp    LISTEN     0      128                 :::ssh                  :::*        users:(("sshd",1618,4))

###   1618为pid

4:查看这台服务器的所有socket连接
[root@localhost ~]# ss -a
[root@localhost ~]# ss -ta|ua|wa|xa     ### TCP/UDP/RAW/UNIX sockets

3:net-tools与iproute2对比

作用 net-tools用法 iproute2用法
展示本机所有网络接口 ifconfig ip link show
2:开启某给网络接口 ifconfig eth0 up ip link set up eth0
3:停止某个网络接口 ifconfig eth0 down ip link set down eth0
4:给网络接口设置网络Ip地址 ifconfig eth0 10.0.0.1/24 ip addr add 10.0.0.1/24 dev eth0
5:删除网络Ip地址 ifconfig eth0 0 ip addr del 10.0.0.1/24 dev eth0
6:显示某个网络接口的IP地址 ifconfig eth0 ip addr show dev eth0
7:显示路由表 route -n ip route show
8:添加默认网关 route add default gw 192.168.1.2 eth0 ip route add default via 192.168.1.2 eth0
9:删除默认网关 route del default gw 192.168.1.2 eth0 ip route del default via 192.168.1.2 eth0
10:展示arp表 arp -an ip neigh
11:添加ARP项 arp -s 192.168.1.100
00 :0c:29:c0:5d:ef
ip neigh add 192.168.1.100 lladdr
00 :0c:29:c0:5d:ef
12:删除arp项 arp -d 192.168.1.100 ip neigh del 192.168.1.100 dev eth0
13:查看组播信息 ipmaddr show dev eth0 ip maddr list dev eth0 ###注意格式
14:展示socket状态 netstat -l ss -l

查看man帮助,详细信息

[root@localhost ~]# man ip route