3

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
5

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.

$ ipcalc 172.20.0.109/24
Address:   172.20.0.109         10101100.00010100.00000000. 01101101
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   172.20.0.0/24        10101100.00010100.00000000. 00000000
HostMin:   172.20.0.1           10101100.00010100.00000000. 00000001
HostMax:   172.20.0.254         10101100.00010100.00000000. 11111110
Broadcast: 172.20.0.255         10101100.00010100.00000000. 11111111
Hosts/Net: 254                   Class B, Private Internet


$ ipcalc 172.20.0.109/22
Address:   172.20.0.109         10101100.00010100.000000 00.01101101
Netmask:   255.255.252.0 = 22   11111111.11111111.111111 00.00000000
Wildcard:  0.0.3.255            00000000.00000000.000000 11.11111111
=>
Network:   172.20.0.0/22        10101100.00010100.000000 00.00000000
HostMin:   172.20.0.1           10101100.00010100.000000 00.00000001
HostMax:   172.20.3.254         10101100.00010100.000000 11.11111110
Broadcast: 172.20.3.255         10101100.00010100.000000 11.11111111
Hosts/Net: 1022                  Class B, Private Internet
1
  • Thanks a lot Giovanni! With netmask 22 now I reach the gateway. – Davide Merlitti Jul 19 '18 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.