在 Debian 中调用 ifconfig,需要注意一个现实情况:ifconfig 已经被逐步淘汰,默认 很多 Debian 版本(尤其是最小化安装)不再自带。
下面分情况说明如何调用和使用。
ifconfig 属于 net-tools 工具包,Debian 默认倾向于使用 iproute2(ip 命令)。
检查是否已安装:
which ifconfig
如果 没有输出,说明未安装。
sudo apt update
sudo apt install net-tools
安装完成后即可使用:
ifconfig
ifconfig
或(更详细):
ifconfig -a
ifconfig eth0
sudo ifconfig eth0 up
sudo ifconfig eth0 down
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
sudo route add default gw 192.168.1.1
ip 命令(替代 ifconfig)| 功能 | ifconfig | ip 命令 |
|---|---|---|
| 查看网卡 | ifconfig | ip addr |
| 启动网卡 | ifconfig up | ip link set eth0 up |
| 设置 IP | ifconfig | ip addr add 192.168.1.100/24 dev eth0 |
| 查看路由 | route | ip route |
示例:
ip addr
ip link set eth0 up
ip addr add 192.168.1.100/24 dev eth0
编辑:
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
✅ 临时查看/调试 → 可以安装 net-tools 用 ifconfig
✅ 长期维护 / 服务器 → 推荐使用 ip 命令
✅ 永久配置 → 修改 /etc/network/interfaces
如果你愿意,我可以: