Sedebian 网络配置指南
名称澄清与适用范围
快速判断当前网络管理方式
方法一 使用 /etc/network/interfaces(传统方式)
sudo nano /etc/network/interfaces
写入:auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
sudo nano /etc/network/interfaces
写入(按需替换地址、网关、DNS):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
sudo systemctl restart networking
# 或
sudo /etc/init.d/networking restart
ip addr show eth0
ping -c 4 8.8.8.8
ping -c 4 www.google.com
sudo ifdown eth0 && sudo ifup eth0(远程操作慎用,避免断连)。方法二 使用 NetworkManager(nmcli)
sudo systemctl enable --now NetworkManager
nmcli connection show
nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.100/24
nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.1
nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8"
nmcli con mod "Wired connection 1" ipv4.method manual
nmcli con up "Wired connection 1"
nmcli con mod "Wired connection 1" ipv4.method auto
nmcli con up "Wired connection 1"
nmcli con show "Wired connection 1" | grep ipv4
ping -c 4 8.8.8.8
ping -c 4 www.google.com
方法三 使用 netplan(若系统提供)
sudo nano /etc/netplan/01-netcfg.yaml
示例(静态 IP):network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
sudo netplan apply
# 或(生成配置预览)
sudo netplan try
ip addr show eth0
ping -c 4 8.8.8.8
ping -c 4 www.google.com
常见问题与排查
resolvectl status 查看解析状态。