在 Debian 中,ifconfig 本身只是用来查看和配置网络接口的命令,它不能直接“联网”,但可以用来启用网卡、配置 IP、网关等,从而让系统联网。
下面按常见场景说明 Debian 如何用 ifconfig 联网。
新版本 Debian 默认没有 ifconfig:
sudo apt update
sudo apt install net-tools
eth0ifconfig -a
sudo ifconfig eth0 up
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
sudo route add default gw 192.168.1.1
编辑:
sudo nano /etc/resolv.conf
添加:
nameserver 8.8.8.8
nameserver 114.114.114.114
ping 8.8.8.8
ping www.baidu.com
✅ 如果能 ping 通,说明已联网。
⚠️ ifconfig 不支持 DHCP
需要配合:
sudo dhclient eth0
然后再:
ifconfig eth0
重启后失效。
Debian 使用:
/etc/network/interfacesNetworkManagersystemd-networkd示例(/etc/network/interfaces):
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
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 是否支持 |
|---|---|
| 查看网卡 | ✅ |
| 启用/禁用网卡 | ✅ |
| 配置 IP | ✅ |
| 配置网关 | ❌(需 route) |
| DHCP | ❌(需 dhclient) |
| 永久生效 | ❌ |
如果你愿意,可以告诉我:
我可以给你一份完全对应的配置示例。