1)如何在 Linux 上使用 ip 命令检查可用的网络接口
在不带任何参数的情况下运行 ip
命令时,它会提供大量信息,但是,如果仅需要可用的网络接口,请使用以下定制的 ip
命令。
-
# ip a |awk '/state UP/{print $2}'
-
eth0:
-
eth1:
2)如何在 Linux 上使用 ip 命令检查网络接口的 IP 地址
如果只想查看 IP 地址分配给了哪个接口,请使用以下定制的 ip
命令。
-
# ip -o a show | cut -d ' ' -f 2,7
-
或
-
ip a |grep -i inet | awk '{print $7, $2}'
-
lo 127.0.0.1/8
-
192.168.1.101/24
-
192.168.1.102/24
3)如何在 Linux 上使用 ip 命令检查网卡的 MAC 地址
如果只想查看网络接口名称和相应的 MAC 地址,请使用以下格式。
检查特定的网络接口的 MAC 地址:
-
# ip link show dev eth0 |awk '/link/{print $2}'
-
00:00:00:55:43:5c
检查所有网络接口的 MAC 地址,创建该脚本:
-
# vi /opt/scripts/mac-addresses.sh
-
#!/bin/sh
-
ip a |awk '/state UP/{print $2}' | sed 's/://' | while read output;
-
do
-
echo $output:
-
ethtool -P $output
-
done
运行该脚本获取多个网络接口的 MAC 地址:
-
# sh /opt/scripts/mac-addresses.sh
-
eth0:
-
Permanent address: 00:00:00:55:43:5c
-
eth1:
-
Permanent address: 00:00:00:55:43:5d
4)如何在 Linux 上使用 ethtool 命令检查网络接口速度
如果要在 Linux 上检查网络接口速度,请使用 ethtool
命令。