网络 - Linux Ubuntu Server 20.04 LTS:'Network Unreachable'

分享于 

3分钟阅读

ubuntu

  繁體

问题:

上个月它还工作正常,但是现在无法连接到互联网,我尝试ping路由器,192.168.1.254和8.8.8.8,但都说网络不可访问,我尝试在sudo nano /etc/network/interfaces中查找,但是它只是一个空文件,里面没有内容,


*-network = DISABLED


description: Ethernet Interface


product: PCI Express Gigabit Ethernet Controller


vendor: Realtek Semiconductor Ltd


physical id: 0


bus info: pci@0000:04:00.0


version: 06


serial: c8:60:00:9e:bf:d1


width: 64 bits


clock: 33mhz


capabilities: pm msi pciexpress msix vpd bus_master cap_list 


ethernet_physical


configuration: broadcast=yes driver=r8169 latency=0 link=no multicast=yes


resources: irq:18 ioport:d000(size=256) memory: f0304000-f0304fff memory: 


f0300000-f0303fff



这是我输入'sudo lshw -C network' 时产生的

这是cat /etc/netplan/*.yaml


network:


 ethernets:


 enp7s0:


 addresses:


 - 192.168.1.200/24


 gateway4: 192.168.1.254


 nameservers:


 addresses:


 -8.8.8.8


 -8.8.4.4


 version: 2



'ip a'


1: io: <LOOPBACK.UP.LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN grou 


 default qlen 1000


 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00


 inet 127.0.0.1/8 scope host lo


 valid_lft forever preferred_lft forever


 inet6 ::1/128 scope host


 valid_lft forever preferred_lft forever


2: enp4s0: <BROADCAST.MULTICAST> mtu 1500 qdisc noop state DOWN group default 


 qlen 1000


 link/ether c8:60:00:9e:bf:d1 brd ff:ff:ff:ff:ff:ff




答案1:

可能有两个问题。

.yaml文件

/etc/netplan/*.yaml代码替换你的.yaml,保持精确的间距,缩进和无制表符。

sudo -H gedit /etc/netplan/*.yaml #用正确的文件名替换*


network:


 version: 2


 renderer: networkd


 ethernets:


 enp4s0:


 addresses:


 - 192.168.1.200/24


 gateway4: 192.168.1.254


 nameservers:


 addresses:


 - 8.8.8.8


 - 8.8.4.4



然后执行:

sudo netplan --debug generate

sudo netplan apply

reboot #必需