Network interface management on Linux made easy with Netplan

So I recently had to use a StarTech ethernet USB adapter to get two extra ports for networking stuff I’m doing. So those two plus my laptop internal port I have three ports in total. The StarTech adapter worked right out of the box and can definitely recommend it. You can find it on their website with the item number USB32000SPT.

I’m using Ubuntu with the Gnome, but the Gnome network settings only allow me to use a single interface at a time, even though the other interfaces was visible. To fix this I used the dhclient to get ip’s assigned to my two new interfaces and now I have all three interfaces connected. Even the Gnome network settings acknowledge them as all being connected, but if I try to change anything in there it disconnects the two others than the one being configured. So the Gnome network settings are out of the picture from now on. Next I was pretty annoyed by the constant need to call dhclient <interface name> every time I rebooted my machine, and also the interface names was long and hard to remember. So I did some searching and found some different solutions to my problem. There were some more old school solutions such as using udev, which worked but seemed a bit too out dated and the configuration format, in my opinion is bad. So I looked a bit further and stumbled across Netplan.

Netplan is a tool that can help you set up all kinds of network stuff for you by just making a YAML configuration file. Well I’m not going to explain the tool any further as they do it so well themselves on their website, so I’m just going to show how I used it to set up my interface with persistent names and dhcp4 enabled.

First of I found the YAML config file in /etc/netplan/…, which in my case was /etc/netplan/01-netcfg.yaml, and then edited the file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
network:
version: 2
renderer: networkd
ethernets:
eth0:
match:
macaddress: "00:0a:cd:3e:17:9a"
dhcp4: yes
set-name: eth0
eth1:
match:
macaddress: "00:0a:cd:3e:17:9b"
dhcp4: yes
set-name: eth1
eth2:
match:
macaddress: "00:0a:cd:3e:17:9c"
dhcp4: yes
set-name: eth2

and then I ran netplan apply with root permission to apply the configuration on my machine. This is also a nice thing about Netplan, as it’s possible to make the changes without having to reboot. If you want to know more about the configuration options take a look at the Netplan references page.

As you can see I took my three interfaces and gave them the names eth0, eth1, and eth2 and also enabled dhcp for each of them. The interfaces are identified by the macaddress.

But enabling dhcp for them all gave me three default routes and this was not always desirable for me, as these three interfaces sometimes are connected to the same network. So in this case I use a bond to solve the problem and use eth0 as the primary interface. You can read more about what bonds are here. In my case I added the following configuration to my Netplan config file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
network:
version: 2
renderer: networkd
# ... ethernets here

# Use a bond for when the interfaces are on the same network.
bonds:
bond0:
dhcp4: yes
interfaces:
- eth0
- eth1
- eth2
parameters:
mode: active-backup
primary: eth0

And that’s pretty much it. Hope this was somewhat helpful for you.

Configuring DPDK projects with CMake
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×