CentOS7命令查看网卡状态
1. 使用ifconfig命令
ifconfig
是传统的网络接口查看工具,需安装net-tools
包后使用:
sudo yum install net-tools ifconfig -a
输出结果中,RX/TX packets
显示收发数据包数量,inet
字段为IPv4地址,ether
为MAC地址。
2. 通过ip命令查询
现代Linux系统推荐使用ip
命令,可查看更详细的网络信息:
ip addr show # 显示所有接口IP地址 ip link show # 查看接口链路状态 ip -s link show eth0 # 查看指定接口统计信息
LOWER_UP
状态表示网卡已物理连接,NO-CARRIER
则提示未检测到信号。
3. nmcli网络管理工具
NetworkManager提供的nmcli
可显示连接状态:
nmcli device status nmcli connection show --active
结果中DEVICE
列显示接口名称,STATE
列展示连接状态(如connected/disconnected)。
4. 使用ethtool诊断
通过ethtool
可检测物理层状态:
ethtool eth0 | grep 'Link detected' ethtool -i eth0 # 查看驱动信息
输出Link detected: yes
表示网线连接正常,Speed
字段显示协商速率。
5. 查看网络接口配置文件
网络配置存储在/etc/sysconfig/network-scripts/
目录:
cat /etc/sysconfig/network-scripts/ifcfg-eth0
文件中的ONBOOT
参数控制是否开机启动,BOOTPROTO
定义IP获取方式。