在 Debian 里,ifconfig 属于比较“老”的命令,现在默认 不一定自带。下面分情况说明怎么用。
ifconfigifconfig 在 net-tools 包里:
sudo apt update
sudo apt install net-tools
安装完成后就可以用了。
ifconfig
或只看某个网卡,例如 eth0:
ifconfig eth0
sudo ifconfig eth0 up
sudo ifconfig eth0 down
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
ifconfig 不能设置网关,需要配合
route:
sudo route add default gw 192.168.1.1
sudo ifconfig eth0 promisc
sudo ifconfig eth0 -promisc
⚠️ ifconfig 修改的都是临时的,重启失效
Debian 推荐用 ip / networkctl / /etc/network/interfaces:
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
Debian 官方更推荐用 ip 命令:
ip addr # 查看 IP
ip link set eth0 up
ip addr add 192.168.1.100/24 dev eth0
ip route add default via 192.168.1.1
✅ 老系统 / 习惯用 ifconfig
sudo apt install net-tools
ifconfig
✅ 新系统 / 推荐做法
ip addr
如果你愿意,可以告诉我:
我可以给你一套最适合你环境的配置方案。