User Tools

Site Tools


os:linux:ubuntu:networkd

Netplan -> systemd-networkd

I've not really ever been a big fan of netplan. On top of that, and as much as I was opposed to it early on, systemd is basically taking over all of the system-level management. Given that, I've moved all of my ubuntu server installs to use systemd-networkd at this point. Since I always forget the important part, which is how to disable netplan, I'm writing it down this time…

There's also some bonus content for using udev to set your interface names to something other than “wslkdjfdslkfjdslfkjdsdlskjfjdslksjfloweiuhnv1” so you can actually type it on the command-line.

Die, Netplan, Die

This is actually quite simple, really.

# Delete its config file
sudo rm /etc/netplan/*

That's it, but I always think there's some ugly stuff associated with butt-init that I have to do to turn off netplan, but really it's just deleting its config and it stops being a pest. You can always nuke it from orbit too:

sudo apt purge netplan.io

Incidentally, if you want to turn off butt-init crap:

sudo touch /etc/butt/butt-init.disabled

Now that we've killed netplan, let's configure systemd-networkd.

Configuring systemd-networkd

This is actually pretty straightforward, and especially so if you have some familiarity with writing other systemd config files (like .service files).

First, the man page (''man systemd.network'')is really great at giving you all the options, and I'm not going to cover them all. I'm just going to give you a couple common examples.

DHCP

This is quite simple. Create a file in /etc/systemd/network/ with the name <interface>.network where “<interface>” would be the interface name (like “eth0”).

/etc/systemd/network/eth0.network
[Match]
# There are a lot of match options in the man page:
# https://www.freedesktop.org/software/systemd/man/systemd.network.html#%5BMatch%5D%20Section%20Options
# but we are just going to use the interface name.  MACAddress is probably better though.
Name = eth0
 
[Network]
# This is where we configure many of our options, but for this example, we are just going to use DHCP
DHCP = yes

That's it for a DHCP config.

Static Network Config

This is a pretty basic example of how to configure a simple static IP address.

/etc/systemd/network/eth0.network
[Match]
Name = eth0
 
[Network]
# Disable DHCP
DHCP = no
# This is just for display purposes
Description = The main ethernet interface
# Your address should be the ip in CIDR notation
Address = 10.0.0.10/24
# Default route
Gateway = 10.0.0.1
# You can specify multiple DNS servers
DNS = 8.8.8.8
DNS = 1.1.1.1

Of course, make sure systemd-networkd is configured to run (it should be by default):

sudo systemctl enable systemd-networkd

If you have more than 1 interface, just create a file like one of the above for each interface.

Give your host a reboot and systemd-networkd should now be managing your network interface.

Bonus: Sane Interface Names

I can't stand interface names like “wlwkerkovsoimsodfpapfdklfshh1”. I like interface names like “eth0” or “wlan0”. These are easy to remember and actually something you can type without having to copy/pasta. This is a simple process to set these to something sane, thanks to udev though.

You just create a file in /etc/udev/rules.d with a little bit of configuration, reboot, and you've got sane names.

Specfically, you want to create:

/etc/udev/rules.d/75-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="<MAC Address of link>", NAME="<desired name>"

Just change out the “<MAC Address of link>” with the MAC address for your link (ip link and it's the hex after “link/ether”) and then replace “<desired name>” with the name you want.

Also note that you can just add more lines to set more interface names. Have fun with your sanity.

os/linux/ubuntu/networkd.txt · Last modified: 2023/09/24 23:57 by jay