ifconfig 在 Debian 里用法和在其他 Linux 发行版基本一致,但需要注意一个常见问题:新版 Debian 默认可能没有安装它。下面我按实际使用场景给你说明。
从 Debian 9(Stretch)及以后版本开始,ifconfig 被逐步弃用,官方推荐使用 ip 命令。
ifconfig 属于 net-tools 软件包,Debian 默认 不再预装。
检查是否安装:
which ifconfig
如果没输出,说明没装。
sudo apt update
sudo apt install net-tools
安装完成后即可使用。
ifconfig
或(不解析 DNS,速度更快):
ifconfig -a
示例输出:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0
inet6 fe80::20c:29ff:fe12:3456 prefixlen 64
ether 00:0c:29:12:34:56 txqueuelen 1000
ifconfig eth0
sudo ifconfig eth0 up
sudo ifconfig eth0 down
⚠️ 注意:只是临时生效,重启后失效。
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
sudo ifconfig eth0:1 192.168.1.101
sudo ifconfig eth0:1 down
sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether 00:11:22:33:44:55
sudo ifconfig eth0 up
ip 命令替代(现代做法)Debian 官方更推荐:
ip addr # 查看 IP
ip link # 查看网卡状态
ip link set eth0 up
ip addr add 192.168.1.100/24 dev eth0
ifconfig 不能保存配置,永久配置用:
编辑:
sudo nano /etc/network/interfaces
示例:
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
重启网络:
sudo systemctl restart networking
✅ 临时查看 / 调试 → ifconfig 可以
✅ 新系统 / 脚本 / 长期管理 → 用 ip
❌ ifconfig 不再被维护
如果你愿意,我可以:
ifconfig vs ip