Ubuntu Stream 8 网络设置修改指南
一、先确认网络管理方式
ip link(常见如 eth0、ens33、enp0s3)。二、使用 Netplan 配置(推荐)
sudo nano /etc/netplan/01-netcfg.yamlnetwork:
version: 2
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]
network:
version: 2
ethernets:
eth0:
dhcp4: yes
sudo netplan apply(远程操作建议先用 sudo netplan try 以避免断连)。三、使用 ifupdown 配置(/etc/network/interfaces)
sudo nano /etc/network/interfacesauto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto lo
iface lo inet loopback
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 ifdown eth0 && sudo ifup eth0,远程慎用以免断连)。四、使用 NetworkManager 配置(nmcli/nmtui)
nmcli connection show(记下有线连接名称,如“Wired connection 1”)nmcli connection modify "Wired connection 1" ipv4.addresses 192.168.1.100/24
nmcli connection modify "Wired connection 1" ipv4.gateway 192.168.1.1
nmcli connection modify "Wired connection 1" ipv4.method manual
nmcli connection modify "Wired connection 1" ipv4.dns "8.8.8.8 8.8.4.4"
nmcli connection up "Wired connection 1"
sudo nmtui(编辑连接 → IPv4 设置为“手动” → 填写地址/网关/DNS → 保存并激活)。五、验证与常见问题
ip addr show dev eth0ip routeping -c 4 网关IP、ping -c 4 8.8.8.8、nslookup example.comnetplan apply;ifupdown 用 systemctl restart networking)。ifconfig 在新系统可能未安装,改用 ip addr;临时改 IP 可用 ip addr add 192.168.1.100/24 dev eth0,但重启后失效,需写入对应配置文件。