在 Debian 系统中,ifconfig 是一个已过时但仍可用的网络配置工具,它来自 net-tools 软件包。现代 Debian 更推荐使用 ip 命令(来自 iproute2)。
下面分情况说明 如何“启动”网络接口。
which ifconfig
如果没有,安装:
sudo apt update
sudo apt install net-tools
ifconfig -a
或
ip a
你可能会看到:
eth0ens33wlan0losudo ifconfig eth0 up
或等价命令:
sudo ip link set eth0 up
⚠️ 注意:
up 只是“启用接口”,不会自动获取 IP 地址。
sudo dhclient eth0
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
sudo route add default gw 192.168.1.1
/etc/network/interfaces编辑:
sudo nano /etc/network/interfaces
示例(DHCP):
auto eth0
iface eth0 inet dhcp
或静态 IP:
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
nmcli device status
nmcli device connect eth0
ifconfig: command not found→ 安装 net-tools
eth0: ERROR while getting interface flags→ 接口名不对,用 ip a 确认
→ 没配置 IP / 没设置网关 / 没 DNS
| 场景 | 推荐命令 |
|---|---|
| 临时启用接口 | ip link set eth0 up |
| 获取 IP | dhclient eth0 |
| 永久配置 | /etc/network/interfaces |
| 新系统 | 用 ip 替代 ifconfig |
如果你愿意,可以告诉我:
我可以给你最合适的一套配置方案。