Ubuntu 17.10 Server static IP netplan - how to set netmask

Netmask cannot be 255.255.255.1. Netmask for class C addresses can be:

Prefix size         | Subnet mask   
/24                 | 255.255.255.0 
/25                 | 255.255.255.128
/26                 | 255.255.255.192
/27                 | 255.255.255.224
/28                 | 255.255.255.240
/29                 | 255.255.255.248
/30                 | 255.255.255.252

Based on this you configuration in .yaml can be

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.0.97/25]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]

Or some appropriate netmask.

Please keep in mind that ip address of host and gateway must be in the same subnet.


You set the netmask with CIDR notation in the addresses, so /24 is 255.255.255.0, /25 is 255.255.255.128, /28 is 255.255.255.240, etc.

Here is a working example from https://netplan.io/examples

network:
  version: 2
  renderer: networkd
  ethernets:
    enp2s0:
      addresses:
        - 10.10.10.2/24
      dhcp4: no
      gateway4: 10.10.10.1
      nameservers:
          addresses: [8.8.8.8, 1.1.1.1]

Or like this:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp2s0:
      addresses: [10.10.10.2/25]
      dhcp4: no
      gateway4: 10.10.10.1
      nameservers:
          addresses: [8.8.8.8, 1.1.1.1]

Or with aliases:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp2s0:
      addresses: [10.10.10.2/25, 10.10.10.3/25]
      gateway4: 10.10.10.1
      nameservers:
          addresses: [8.8.8.8, 1.1.1.1]

And this also works:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp2s0:
      addresses:
        - 10.10.10.2/25
        - 10.10.10.3/25
      gateway4: 10.10.10.1
      nameservers:
          addresses: [8.8.8.8, 1.1.1.1]