Ubuntu-22.04-LTS

Ubuntu netplan gateway4 has been deprecated

Ubuntu

WARNING: “gateway4 has been deprecated, use default routes instead.” will show when running the netplan command on Ubuntu 22.04 LTS. With the new Ubuntu 22.04 LTS version also came a new version of netplan. This also introducted the deprecation of gateway4 and gateway6. Netplan is the new way to configure network settings on Ubuntu. Netplan uses yaml files for the configuration. The gateway4 and gateway6 options will still work for now. Although the default subiquity installation of Ubuntu 22.04 LTS still uses the gateway4 and gate6 options we should use the route: options now.

In this post I will explain which options to use to be prepared for future versions of netplan.

More information about netplan can also be found in the documentation.

Gateway4 has been deprecated, use default routes instead

As the warning message clearly states we need to use the default routes option. Below is an example of the default routes option instead of gateway4:

network:
  ethernets:
    ens160:
      addresses:
      - 10.10.20.6/24
      nameservers:
        addresses:
        - 10.10.20.71
      routes:
          - to: default
            via: 10.10.20.1
  version: 2

As you can see the gateway4 options has been replaced with the routes: block. In the routes: block we explain two options. The to: and via: options. Both options are obvious. The to: states where to route and the via: states where to route via.

Gateway6 has been deprecated, use default routes instead

As for IPv6 the gateway6 options has also been deprecated. Here we need to use the same options as with IPv4. For example:

network:
  ethernets:
    ens160:
      addresses:
      - 10.10.20.6/24
      - 2001:678:e20:20::6/64
      nameservers:
        addresses:
        - 10.10.20.71
      routes:
          - to: default
            via: 10.10.20.1
          - to: default
            via: 2001:678:e20:20::1
  version: 2

The routes: block for IPv6 is the same as for IPv4 only with the correct IPv6 addresses.

Conclusion on gateway4 has been deprecated, use default routes instead

Using the new routes: options in the netplan yaml configuration should be easy to use. Although most people will need to get used to the new options. The default subiquity installation of Ubuntu 22.04 LTS still uses the gateway4 and gateway6 options at the time of writing this. I hope it will soon change over so we can get rid of the warnings when executing the netplan commands.

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *