在 Debian 里,ifconfig 命令来自 net-tools 包,但 Debian 默认已经不再推荐使用它,而是使用 ip 命令。下面分情况说明。
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
sudo route add default gw 192.168.1.1
查看路由:
route -n
/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
dns-nameservers 8.8.8.8 114.114.114.114
auto eth0
iface eth0 inet dhcp
重启网络:
sudo systemctl restart networking
查看设备:
nmcli device status
配置静态 IP:
nmcli con modify eth0 ipv4.method manual \
ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "8.8.8.8"
nmcli con up eth0
| 功能 | ifconfig | ip 命令 |
|---|---|---|
| 查看 IP | ifconfig | ip addr |
| 启动网卡 | ifconfig up | ip link set eth0 up |
| 添加 IP | ifconfig | ip addr add |
✅ 官方推荐:
ip addr
ip link
ip route
ifconfig -a
网卡可能未启动。
ip route如果你愿意,可以告诉我:
ip addr 输出)我可以帮你写一份 完全可用的配置方案 ✅