在 Debian 里,ifconfig 本身只能查看和临时配置网络,不能“永久保存”配置。永久配置要靠 /etc/network/interfaces(传统方式)或 netplan / NetworkManager(新版本)。
下面按常见用法说明。
ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
✅ 立即生效
❌ 重启后失效
ifconfig
或
ip addr
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
ifconfig eth0 up
ifconfig eth0 down
route add default gw 192.168.1.1
编辑:
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
应用:
systemctl restart networking
或
ifdown eth0 && ifup eth0
nmtui
图形化配置,最简单。
nano /etc/netplan/01-netcfg.yaml
network:
version: 2
ethernets:
eth0:
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8]
netplan apply
/etc/network/interfacesNetworkManagerifconfig如果你告诉我:
我可以直接给你一份可直接复制用的配置。