Netplan Gateway is Deprecated Use Default Routes on Ubuntu | Best Solution

Posted on

Netplan Gateway is Deprecated Use Default Routes on Ubuntu | Best Solution

Netplan Gateway is Deprecated Use Default Routes on Ubuntu | Best Solution

When configuring network settings on Ubuntu servers, you might encounter a warning message related to Netplan and the use of gateways. Specifically, you may see the error "Netplan Gateway is Deprecated Use Default Routes on Ubuntu." This article will guide you through understanding and resolving this deprecation, providing a clear solution and exploring alternative approaches. The best solution is to migrate from gateway definitions to route definitions.

Netplan is a network configuration utility developed by Canonical, the company behind the Ubuntu operating system. It simplifies network configuration by using YAML files to describe the desired network setup. These configurations are then applied to the underlying network management system.

Understanding the Deprecation

The "Netplan Gateway is Deprecated Use Default Routes on Ubuntu" message indicates that the gateway4 and gateway6 options in Netplan configurations are no longer the preferred method for defining default gateways. Instead, you should use the routes option. This change promotes a more flexible and explicit way to define network routes.

The error message typically looks like this:

** (generate:1952): WARNING **: ...: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

** (generate:1952): WARNING **: ...: `gateway6` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

In older Netplan configurations, you might have defined gateways directly. However, the recommended approach now is to define the routes themselves, providing more granular control over network traffic.

What are Default Routes Instead of Gateway4 and Gateway6?

The routes option utilizes the to: and via: parameters to define network routes. to: specifies the destination network, and via: specifies the gateway through which to reach that network. A default route (to: default) indicates the gateway to use for any traffic that doesn’t match a more specific route.

Here’s an example of how to replace gateway4 with the routes option in a Netplan configuration file on Ubuntu:

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

In this example:

  • ens160 is the name of the network interface.
  • addresses defines the IP address and subnet mask for the interface.
  • nameservers specifies the DNS server addresses.
  • routes defines a default route (to: default) that uses 10.10.20.1 as the gateway (via: 10.10.20.1).

For IPv6 (gateway6), the configuration would look like this:

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

Here, we’ve added an IPv6 address and a corresponding default route for IPv6 traffic, using 2001:678:e20:20::1 as the IPv6 gateway.

After making these changes, you need to apply the new configuration using the following command:

sudo netplan apply

This command will apply the changes you made in the Netplan configuration file and update the network settings. If you see an error, use sudo netplan --debug apply to see verbose output and troubleshoot.

You have now resolved the "Netplan Gateway is Deprecated Use Default Routes on Ubuntu" warning.

It is highly recommended to visit the official Netplan examples for more in-depth information and various configuration scenarios.

Alternative Solutions to "Netplan Gateway is Deprecated Use Default Routes on Ubuntu"

While the recommended approach is to migrate to using the routes option, there are alternative ways to manage network configurations on Ubuntu, though they might not be as directly related to resolving the deprecation warning.

1. Using ip command directly:

Instead of relying solely on Netplan, you can use the ip command to directly manipulate the routing table. This provides a more immediate, albeit less persistent, way to manage routes.

Explanation:

The ip command is a powerful utility for managing network interfaces, addresses, and routes. You can use it to add, delete, or modify routes directly in the kernel’s routing table. This approach bypasses Netplan altogether, giving you finer-grained control. However, these changes are not persistent across reboots unless you create a script to re-apply them at startup.

Example:

To add a default route using the ip command, you would use the following syntax:

sudo ip route add default via 10.10.20.1 dev ens160
  • ip route add default: Adds a default route.
  • via 10.10.20.1: Specifies the gateway IP address.
  • dev ens160: Specifies the network interface to use.

To delete a default route, you can use:

sudo ip route del default via 10.10.20.1 dev ens160

To make these changes persistent, you could add these commands to a script that runs at boot time (e.g., using systemd). However, using Netplan is the recommended, more manageable way for persistent network configuration.

2. Using ifupdown (if applicable and supported):

In older Ubuntu versions or in specific environments, the ifupdown tool might be used for network configuration. While less common now, it’s worth mentioning as an alternative.

Explanation:

ifupdown is an older network management tool that uses the /etc/network/interfaces file for configuration. It’s typically used with static IP addresses or DHCP. While Netplan is the default on modern Ubuntu systems, you might encounter situations where ifupdown is still in use (e.g., in some server environments, or when explicitly configured). However, ifupdown and Netplan are generally incompatible, so attempting to use both can lead to conflicts and unpredictable network behavior.

Example (using /etc/network/interfaces):

To configure a static IP address and default gateway using ifupdown, you would edit the /etc/network/interfaces file (usually as root):

auto ens160
iface ens160 inet static
    address 10.10.20.6
    netmask 255.255.255.0
    gateway 10.10.20.1
    dns-nameservers 10.10.20.71

Then, you would bring the interface up with:

sudo ifdown ens160 && sudo ifup ens160

Important Notes:

  • Compatibility: Netplan and ifupdown are not designed to be used together. If Netplan is managing your network, avoid directly modifying /etc/network/interfaces as it can cause conflicts.
  • Modern Ubuntu: On recent Ubuntu releases, Netplan is the default network configuration tool. ifupdown is generally not used unless explicitly configured.
  • Deprecation: The "Netplan Gateway is Deprecated Use Default Routes on Ubuntu" warning specifically applies to Netplan configurations. Using ifupdown does not address this Netplan-related issue. It’s an entirely different way of managing the network.

While these alternative methods exist, the recommended and most maintainable solution to the "Netplan Gateway is Deprecated Use Default Routes on Ubuntu" warning is to update your Netplan configuration files to use the routes option as described in the primary solution. This ensures compatibility with the latest Ubuntu versions and takes advantage of Netplan’s flexibility and features.

Conclusion

In conclusion, this article has provided a comprehensive guide to resolving the "Netplan Gateway is Deprecated Use Default Routes on Ubuntu" warning. By understanding the deprecation and migrating to the routes option with to: and via: parameters, you can ensure your network configuration is up-to-date and compliant with the latest Ubuntu recommendations. While alternative solutions like using the ip command directly or, in rare cases, ifupdown exist, updating your Netplan configuration remains the most effective and recommended approach. The Netplan Gateway is Deprecated Use Default Routes on Ubuntu message is easily solved with the right configurations. Remember to apply the changes with sudo netplan apply after modifying your YAML files. Addressing Netplan Gateway is Deprecated Use Default Routes on Ubuntu ensures your network configuration aligns with current standards.

You may be interested in these articles:

How To Check Internet Speed in Linux Terminal

How To Install CloudPanel on Ubuntu and Debian

How To Install Virtualmin GPL on Linux

Leave a Reply

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