ifconfig(interface config)是 Linux/Unix 中用于查看和配置网络接口的经典命令。虽然在新版 Linux 中逐渐被 ip 命令取代,但依然非常常用。
下面按常见用法 + 示例给你说明。
ifconfig
输出内容包括:
ifconfig eth0
ifconfig eth0 up
ifconfig eth0 down
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
ifconfig eth0:0 192.168.1.101
ifconfig eth0 broadcast 192.168.1.255
⚠️ 需要先禁用网卡
ifconfig eth0 down
ifconfig eth0 hw ether 00:11:22:33:44:55
ifconfig eth0 up
ifconfig eth0 promisc # 开启
ifconfig eth0 -promisc # 关闭
ifconfig -s
以表格形式显示接口统计信息。
新版系统可能未安装:
# CentOS / RHEL
yum install net-tools
# Ubuntu / Debian
apt install net-tools
ip addr
ip link
ip route
| 功能 | 命令 |
|---|---|
| 查看网卡 | ifconfig |
| 启停网卡 | ifconfig eth0 up/down |
| 配 IP | ifconfig eth0 IP netmask |
| 改 MAC | ifconfig eth0 hw ether |
如果你是服务器配置 / 虚拟机 / 嵌入式 / 排错场景,可以告诉我具体用途,我可以给你更针对性的命令示例。