With the latest release of Ubuntu, the method of defining a default gateway in Netplan has changed. Jack Wallen shows you how to use the new routes option.
When Ubuntu migrated from the traditional method of managing network controllers, it sent users and admins into a tizzy to quickly learn the new method. That method was (and is) netplan. It’s actually quite an elegant solution for a fairly complex problem. Not only is everything handled in one convenient file, everything is laid out in JSON format—which most admins know quite well.
SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)
But coinciding with the release of Ubuntu 22.04 (Jammy Jellyfish), Netplan has deprecated an option that, at first, might bring about some grumblings within the community. However, the new method offers a much more convenient and intelligent way of defining routes, one of which is included the default gateway.
If you don’t know, the default gateway is that crucial address that allows a machine to reach the outside world. Without the gateway defined, there’d be no WAN. So, when you first deploy Ubuntu Server 22.04, you’re going to need to know how to define that default gateway.
Let me show you how.
What you’ll need
The only things you’ll need to make this work are a running instance of Jammy Jellyfish (either as a server or desktop) and a user with sudo privileges. Are you ready? Let’s hit the gate.
How to define a default gateway in Netplan
The old method of defining your default gateway in Netplan was simple. Open the Netplan configuration file (on my instance, that file is named 00-installer-config.yaml but YMMV) and you should see the line:
gateway4: 192.168.1.1
Therein lies the issue, as gateway4
has been deprecated. In its favor is the routes
option. This option isn’t new. In fact, you could use this same method back in 20.04. However, the easier path to a default gateway was to use the now-deprecated gateway4
entry.
With the routes option, you can set static routes to subnets (which is how it has been primarily used). Now, however, this is the default option even for your gateway address.
Let’s say your gateway address is 192.168.1.1. To define that in Netplan, open the file for editing (altering the command if your configuration file has a different name) with the command:
sudo nano /etc/netplan/00-installer-config.yaml
Locate the stanza for the network interface you want to change. For me, that stanza is ens5. In that stanza, to configure the default gateway, you’d add (or edit) the following lines right above the nameservers section:
routes:
- to: default
via: 192.168.1.1
Save and close the file. Apply the configuration with the command:
sudo netplan apply
You should now be able to reach the outside world from that server.
And that’s how you configure the default gateway, using Netplan, in the latest release of Ubuntu Linux (22.04). If you’ve tried to configure a static IP in your Jammy server deployments, and can’t figure out why they’re unable to get beyond your LAN, this might well be the reason. And now you know how to fix the problem.
Happy networking!
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.