After a fresh installation of Ubuntu 18.04 LTS I have configured netplan to use a static IP address by following the instructions available online here:
https://www.tecmint.com/ifconfig-vs-ip-command-comparing-network-configuration/
The problem is that the gateway IP address seems to be ignored. This is the yaml file (/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]
This the output of networkctl status ens160
(after executing sudo netplan apply
) where you can see that the gateway is missing:
● 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
This is the file Network File (/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
This is the output of 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
You have a misconfigured network configuration because the gateway IP address is out of the current network (/24).
Assuming that the gateway ip address is correct, you probably need to configure a /22 instead of /24 network to be able to reach the gateway.
Check HostMin and HostMax with ipcalc utility to see how netmask affect network reachability.