Ubuntu 18.04 netplan on multiples interfaces

Ubuntu 18.04 deprecated ifupdown package to configure the network. Instead, they moved to a much more modern application called netplan.

Today I needed to modernize my machine configuration, and I moved from ifupdown configuration to netplan.

I had the following file:

# cat /etc/network/interfaces
# The primary network interface
auto eth0
iface eth0 inet static
 address 9.3.3.XX
 netmask 255.255.255.0
 network 9.3.3.0
 broadcast 9.3.3.255
 gateway 9.3.3.XX
 # dns-* options are implemented by the resolvconf package, if installed
 dns-nameservers 9.3.1.YY
 dns-search foo.bar.ibm.com

auto eth2
iface eth2 inet static
 address 10.1.1.8
 netmask 255.255.255.0
 mtu 9000

auto eth4
iface eth4 inet static
 address 192.168.1.8
 netmask 255.255.255.0
 mtu 9000

Moving to netplan is quite simple, I just moved to:

# cat /etc/netplan/01-netcfg.yaml
network:
 version: 2
 renderer: networkd
 ethernets:
 eth0:
 dhcp4: no
 addresses: [9.3.3.XX/24]
 gateway4: 9.3.3.X
 nameservers:
 addresses: [9.3.1.YY, 8.8.8.8]

eth4:
 addresses: [10.1.1.8/24]
 mtu: 9000

eth2:
 addresses: [192.168.1.8/24]
 mtu: 9000

After this move, you just need to run netplan apply and you should start to use the newer mechanism.

You can also migrate the scripts from ifupdown to netplan meachnism automatically using netplan ifupdown-migrate command.

PS: If you see errors like `uknown key addrress` means you have something on that block. For example, if I write addresseZ instead of addresses on eth2 block, then I will see the following error points to theĀ  ‘eth2‘ line (Line XX below), but in fact, the error would be on line XX + 1 instead of XX

Error in network definition //etc/netplan/01-netcfg.yaml line XX column Y: unknown key addresss

Advertisements