在 Debian 系统中,ifconfig 属于 net-tools 工具包,但现代 Debian 默认推荐使用 ip 命令 或 systemd-networkd / NetworkManager 来配置网络。下面分情况说明。
Debian 10 及以后版本默认不再安装 ifconfig:
sudo apt update
sudo apt install net-tools
验证:
ifconfig
ifconfig -a
或
ip addr
示例网卡:eth0
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
sudo ifconfig eth0 up
sudo ifconfig eth0 down
ifconfig 不能配置网关,需要配合 route:
sudo route add default gw 192.168.1.1
查看路由:
route -n
ifconfig 也不能配置 DNS,需编辑:
sudo nano /etc/resolv.conf
示例:
nameserver 8.8.8.8
nameserver 114.114.114.114
⚠️ 注意:该文件可能被 NetworkManager 覆盖。
/etc/network/interfaces(传统方式)sudo nano /etc/network/interfaces
示例(静态 IP):
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 114.114.114.114
重启网络:
sudo systemctl restart networking
查看连接:
nmcli device status
配置静态 IP:
nmcli con modify eth0 ipv4.addresses 192.168.1.100/24
nmcli con modify eth0 ipv4.gateway 192.168.1.1
nmcli con modify eth0 ipv4.dns "8.8.8.8"
nmcli con modify eth0 ipv4.method manual
nmcli con up eth0
ifconfig 已逐渐被淘汰,建议学习 ip 命令:
ip addr add 192.168.1.100/24 dev eth0
ip link set eth0 up
ip route add default via 192.168.1.1
sudo apt install net-tools
ifconfig 是 临时配置,永久配置请使用:
/etc/network/interfaces如果你愿意,可以告诉我:
我可以给你一份完全针对你环境的配置示例。