Ubuntu netplan gateway4 has been deprecated

Ubuntu

Introduction

Ubuntu netplan gateway4 has been deprecated. will be the warning when updating your netplan yaml configuration in Ubuntu 22.04. Everything will still work fine for now. But the gateway4 option is deprecated. In this guide I will explain how to remove this error and use the new route option in Netplan.

Ubuntu Netplan Gateway4 Has Been Deprecated: What You Need to Know

Netplan, the network configuration tool in Ubuntu, has deprecated the gateway4 directive. This change impacts how users configure default routes in their network settings. In this post, we’ll explore the implications of this deprecation, how to adapt your configurations, and best practices for managing your network routes.

Understanding the Deprecation of Gateway4

The gateway4 directive in Netplan was commonly used to set the default gateway for IPv4 networks. Its deprecation means that users must adopt new methods for defining network routes.

Why Was Gateway4 Deprecated?

Netplan’s development team aims to streamline network configuration by encouraging more explicit and flexible methods for defining routes. This change helps prevent configuration errors and aligns with modern networking practices.

How to Configure Default Routes in Netplan

Instead of using gateway4, you can now define routes explicitly in your Netplan configuration. Here’s an example of how to set up a default route using the new syntax:

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 gateway6 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:
  version: 2
  ethernets:
    ens160:
      dhcp4: no
      addresses:
        - 192.168.1.100/24
      routes:
        - to: 0.0.0.0/0
          via: 192.168.1.1
          on-link: true
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

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.

Common Issues and Troubleshooting

  • Incorrect Route Syntax: Ensure you use the correct YAML syntax to avoid parsing errors.
  • Network Connectivity Problems: Double-check your IP addresses and gateway to ensure they are correctly configured.

Benefits of the New Routing Configuration

  • Explicit Configuration: More control over route definitions and network behavior.
  • Enhanced Flexibility: Ability to define multiple routes and more complex network topologies.

Conclusion

The deprecation of gateway4 in Netplan requires users to update their network configurations, but it also brings benefits in terms of clarity and flexibility. By following the steps outlined in this guide, you can seamlessly transition to the new configuration method and maintain optimal network performance.

For more guides head over the the Guides category.

One comment

Leave a Reply

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