在 Debian 系统中,ifconfig 主要用于查看网络接口信息,但不能直接用来做持久化网络配置。下面分情况说明:
ifconfig 属于 net-tools 工具包,配置是临时的,重启后失效。
sudo apt update
sudo apt install net-tools
ifconfig
或
ifconfig -a
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
sudo ifconfig eth0 down
sudo ifconfig eth0 up
sudo route add default gw 192.168.1.1
/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 8.8.4.4
auto eth0
iface eth0 inet dhcp
sudo systemctl restart networking
或
sudo ifdown eth0 && sudo ifup eth0
nmcli device status
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 | ifconfig | ip addr |
| 启用网卡 | ifconfig up | ip link set eth0 up |
| 配置 IP | ifconfig | ip addr add |
| 是否推荐 | 否 | ✅ 推荐 |
✅ 临时测试 → 用 ifconfig
✅ 正式配置 → 修改 /etc/network/interfaces 或使用 NetworkManager
❌ 不建议 用 ifconfig 做永久网络配置
如果你愿意,可以告诉我:
我可以给你一份完全适合你环境的配置示例。