I would like to change the netmask of an ubuntu 19.04 using netplan. I edited the only yaml file that I had, that is \etc\netplan\50-cloud-init.yaml

            addresses: []
            dhcp4: no
                addresses: [,]
            optional: true
    version: 2

but if i give the command ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:50:56:bc:ff:52 brd ff:ff:ff:ff:ff:ff
    inet brd scope global ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:febc:ff52/64 scope link
       valid_lft forever preferred_lft forever

I would like the netmask to be . where is the netmask setting?


What is typically called the 'netmask' is the older way of defining the netmask. The netmask however is able to be converted to CIDR ranges, which is easier for some people to discuss/understand in documents where the netmask isn't calculated in their heads easily. As such, for Netplan, the netmask is defined via CIDR ranges attached to the IP address definition. (The University of Wisconsin has a nice thorough CIDR conversion table for netmask to CIDR if you wish to review this in depth or keep this for your records)

The /24 on the end of your address indicates the CIDR prefix which in turn correlates to the netmask definitions. The netmask of /24 is

You want that mask to be which correlates to a /16 CIDR range, so specify a /16 instead of a /24, and update your gateway4 accordingly.

Then, run sudo netplan apply afterwards, and it should apply. (Or reboot the system).

  • And please follow any changes with sudo netplan generate and sudo netplan apply . – chili555 Oct 31 at 13:57
  • @chili555 sudo netplan apply should be sufficient to regenerate, at least in modern systems, including 19.10. – Thomas Ward Oct 31 at 14:02
  • perfect. I was going to answer myself but you've been amazing. thanks. – Malkavian Oct 31 at 15:22

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.