在 Debian 中,ifconfig 属于 net-tools 工具包,而较新版本的 Debian 默认只装了 ip 命令(来自 iproute2)。下面分情况说明怎么用。
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 ifconfig eth0:0 192.168.1.101 netmask 255.255.255.0
sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether 00:11:22:33:44:55
sudo ifconfig eth0 up
Debian 官方更推荐使用 ip 命令:
ip addr # 查看 IP
ip link # 查看网卡状态
ip link set eth0 up
ip addr add 192.168.1.100/24 dev eth0
ifconfig 临时生效,重启后失效/etc/network/interfacesnmcli 或 GUI如果你愿意,可以告诉我你的 Debian 版本 和 使用场景(服务器 / 桌面 / 容器),我可以给你更合适的配置方式。