全新安装 Ubuntu 18.04 LTS 后,我已按照此处在线提供的说明将 netplan 配置为使用静态 IP 地址:
https://www.tecmint.com/ifconfig-vs-ip-command-comparing-network-configuration/
问题是网关 IP 地址似乎被忽略了。这是 yaml 文件(/etc/netplan/50-cloud-init.yaml):
network:
version: 2
renderer: networkd
ethernets:
ens160:
dhcp4: no
dhcp6: no
addresses: [172.20.0.109/24]
gateway4: 172.20.3.254
nameservers:
addresses: [172.20.0.5,172.20.0.6]
这是networkctl status ens160
(执行后sudo netplan apply
)的输出,您可以看到网关丢失:
● 2: ens160
Link File: /lib/systemd/network/99-default.link
Network File: /run/systemd/network/10-netplan-ens160.network
Type: ether
State: routable (configured)
Path: pci-0000:03:00.0
Driver: vmxnet3
Vendor: VMware
Model: VMXNET3 Ethernet Controller
HW Address: 00:50:56:a9:bc:e5 (VMware, Inc.)
Address: 172.20.0.109
fe80::250:56ff:fea9:bce5
DNS: 172.20.0.5
172.20.0.6
这是文件网络文件(/run/systemd/network/10-netplan-ens160.network):
[Match]
Name=ens160
[Network]
Address=172.20.0.109/24
Gateway=172.20.3.254
DNS=172.20.0.5
DNS=172.20.0.6
这是的输出route -n
:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.20.0.0 0.0.0.0 255.255.255.0 U 0 0 0 ens160