Converting a Debian ifupdown network configuration to netplan
The network configuration system on Debian has always been ifupdown. For some time now Netplan has appeared and seems to be used more and more. I know many people regret this forced change, but that is not the point of this note.
1. Install Netplan first
Section titled “1. Install Netplan first”apt updateapt install netplan.io2. Then prepare the Netplan configuration
Section titled “2. Then prepare the Netplan configuration”Get the name and the MAC address of the interfaces:
ip linkHere is an example at OVHcloud, with an instance connected to a VRACK on top of the external network. Put in the assigned IPv6 if there is one, the MAC addresses and the right network interface names:
/etc/netplan/50-cloud-init.yaml:
network: version: 2 ethernets: ens3: accept-ra: false addresses: - 2001:xxx/56 dhcp4: true match: macaddress: xxx1 mtu: 1500 nameservers: addresses: - 213.186.33.99 search: [] routes: - to: ::/0 via: 2001:xxx::1 set-name: ens3 ens7: dhcp4: true dhcp4-overrides: use-routes: false match: macaddress: xxx2 set-name: ens73. File permissions, enabling networkd and testing
Section titled “3. File permissions, enabling networkd and testing”Fix the permissions of the yaml file (netplan refuses a world readable file):
chmod 0600 /etc/netplan/50-cloud-init.yamlValidate the syntax and generate the networkd configuration (without applying anything):
netplan generateEnable systemd-networkd before the test. Otherwise netplan try warns that networkd is not started, falls back to a "hard restart", and its automatic rollback is not reliable:
systemctl enable --now systemd-networkdTest the configuration:
netplan tryIt offers to apply it: confirm if you have not lost the connection. Otherwise touch nothing, it reverts to the old configuration on its own once the timer runs out.
4. Check the configuration
Section titled “4. Check the configuration”First check that networkd is indeed enabled at boot (otherwise the network will not come back on the next reboot):
systemctl is-enabled systemd-networkd # must answer: enabledThen the state of the interfaces:
netplan status --all Online state: offline DNS Addresses: 213.186.33.99 xxx xxx DNS Search: openstacklocal
● 1: lo ethernet UNKNOWN/UP (unmanaged) MAC Address: 00:00:00:00:00:00 Addresses: 127.0.0.1/8 ::1/128
● 2: ens3 ethernet UP (networkd: ens3) MAC Address: xxx Addresses: xxx/32 (dynamic, dhcp) 2001:xxx/56 fe80::xxx/64 (link) Routes: default via xxx from xxx metric 100 (dhcp) xxx from xxx metric 100 (dhcp, link) 213.186.33.99 via xxx from xxx metric 100 (dhcp) 2001:xxx::/56 metric 256 fe80::/64 metric 256 default via 2001:xxx::1 metric 1024 (static)
● 3: ens7 ethernet UP (networkd: ens7) MAC Address: xxx Addresses: xxx/16 (dynamic, dhcp) fe80::xxx/64 (link) Routes: xxx/16 from xxx metric 100 (link) xxx from xxx metric 100 (dhcp, link) xxx from xxx metric 100 (dhcp, link) fe80::/64 metric 2565. Purge the old configuration
Section titled “5. Purge the old configuration”apt purge ifupdownapt purge resolvconf6. (optional) Install support for the resolvers known to systemd-networkd
Section titled “6. (optional) Install support for the resolvers known to systemd-networkd”If systemd-networkd is not installed, the /etc/resolv.conf file is a normal file that must contain the right DNS to use, for example:
nameserver 213.186.33.99That file will therefore not be updated from whatever the netplan says, because we had to remove resolvconf, which is of no use any more.
So we install the new systemd-resolved package, which takes care of pointing resolv.conf at itself and uses the DNS servers it received on its side:
apt install systemd-resolvedTo look at the DNS configuration:
networkctl status● Interfaces: 1, 2, 3 State: routableOnline state: online Address: xxx on ens3 xxx on ens7 2001:xxx on ens3 fe80::xxx on ens3 fe80::xxx on ens7 Gateway: xxx on ens3 2001:xxx::1 on ens3 DNS: 213.186.33.99 xxx xxx