通过 ifconfig
命令可以查看网卡的状态信息,包括 IP 地址、MAC 地址、网络状态等。以下是详细的使用方法:
在终端直接输入以下命令查看所有网卡的状态:
ifconfig
输出示例:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
ether 00:1a:2b:3c:4d:5e txqueuelen 1000 (Ethernet)
RX packets 12345 bytes 12345678 (12.3 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6789 bytes 9876543 (9.8 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 456 bytes 45678 (45.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 456 bytes 45678 (45.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
flags
:网卡状态标志。
UP
:网卡已启用。RUNNING
:网卡正在运行。BROADCAST
:支持广播。MULTICAST
:支持多播。LOOPBACK
:本地回环接口(如 lo
)。inet
:IPv4 地址。ether
:MAC 地址(物理地址)。RX
/ TX
:接收(Receive)和发送(Transmit)的数据包统计。
packets
:数据包数量。bytes
:总字节数。errors/dropped
:错误或丢弃的数据包(非零值可能表示网络问题)。指定网卡名称(如 eth0
)查看其状态:
ifconfig eth0
UP
(如 flags=4163<UP,...>
),则表示已启用。UP
,可能网卡未激活。启用方法:
bash
sudo ifconfig eth0 up
bash
ifconfig -a | grep -A 1 "flags"
bash
ifconfig | grep -E 'inet|ether'
ip
命令(更推荐,ifconfig
已逐步被淘汰):
bash
ip addr show # 查看所有网卡
ip link show # 查看链路状态
ifconfig
命令不存在?
net-tools
。安装方法:
bash
sudo apt install net-tools # Debian/Ubuntu
sudo yum install net-tools # CentOS/RHEL
无线网卡名称不同?
wlan0
、wlp3s0
等命名,用 iwconfig
查看无线信息。通过以上方法,你可以快速检查网卡的连接状态、IP 配置和流量统计。如果遇到问题,优先尝试使用 ip
命令(现代 Linux 系统的默认工具)。