Debian’s cloud-images are using systemd-networkd as their default network stack in Bookworm. A slim and feature rich networking daemon that comes included with Systemd itself. Debian’s cloud-images are deploying Netplan on top of this as an easy-to-use, declarative control layer.
If you want to experiment with systemd-networkd and Netplan on Debian, this can be done easily in QEMU using the official images. To start, you need to download the relevant .qcow2
Debian cloud-image from: https://cloud.debian.org/images/cloud/bookworm/latest/
$ wget https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2
Prepare a cloud image
Next, you need to prepare some configuration files for cloud-init and Netplan, to prepare a data-source (seed.img
) for your local cloud-image.
$ cat > meta.yaml <<EOF
instance-id: debian01
local-hostname: cloudimg
EOF
$ cat > user.yaml <<EOF
#cloud-config
ssh_pwauth: true
password: test
chpasswd:
expire: false
EOF
$ cat > netplan.yaml <<EOF
network:
version: 2
ethernets:
id0:
match:
macaddress: "ca:fe:ca:fe:00:aa"
dhcp4: true
dhcp6: true
set-name: lan0
EOF
Once all configuration is prepared, you can create the local data-source image, using the cloud-localds
tool from the cloud-image-utils
package:
$ cloud-localds --network-config=netplan.yaml seed.img user.yaml meta.yaml
Launch the local VM
Now, everything is prepared to launch a QEMU VM with two NICs and do some experimentation! The following command will launch an ephemeral environment for you, keeping the original Debian cloud-image untouched. If you want to preserve any changes on disk, you can remove the trailing -snapshot
parameter.
$ qemu-system-x86_64 \
-machine accel=kvm,type=q35 \
-cpu host \
-m 2G \
-device virtio-net-pci,netdev=net0,mac=ca:fe:ca:fe:00:aa \
-netdev user,id=net0,hostfwd=tcp::2222-:22 \
-nic user,model=virtio-net-pci,mac=f0:0d:ca:fe:00:bb \
-drive if=virtio,format=qcow2,file=debian-12-generic-amd64.qcow2 \
-drive if=virtio,format=raw,file=seed.img -snapshot
We set up the default debian
user account through cloud-init’s user-data configuration above, so you can now login to the system, using that user with the (very unsafe!) password “test”.
$ ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" -p 2222 debian@localhost # password: test
Experience Netplan and systemd-networkd
Once logged in successfully, you can execute the netplan status
command to check the system’s network configuration, as configured through cloud-init’s netplan.yaml
passthrough. So you’ve already used Netplan at this point implicitly and it did all the configuration of systemd-networkd for you in the background!
debian@cloudimg:~$ sudo netplan status -a
Online state: online
DNS Addresses: 10.0.2.3 (compat)
DNS Search: .
● 1: lo ethernet UNKNOWN/UP (unmanaged)
MAC Address: 00:00:00:00:00:00
Addresses: 127.0.0.1/8
::1/128
Routes: ::1 metric 256
● 2: enp0s2 ethernet DOWN (unmanaged)
MAC Address: f0:0d:ca:fe:00:bb (Red Hat, Inc.)
● 3: lan0 ethernet UP (networkd: id0)
MAC Address: ca:fe:ca:fe:00:aa (Red Hat, Inc.)
Addresses: 10.0.2.15/24 (dhcp)
fec0::c8fe:caff:fefe:aa/64
fe80::c8fe:caff:fefe:aa/64 (link)
DNS Addresses: 10.0.2.3
Routes: default via 10.0.2.2 from 10.0.2.15 metric 100 (dhcp)
10.0.2.0/24 from 10.0.2.15 metric 100 (link)
10.0.2.2 from 10.0.2.15 metric 100 (dhcp, link)
10.0.2.3 from 10.0.2.15 metric 100 (dhcp, link)
fe80::/64 metric 256
fec0::/64 metric 100 (ra)
default via fe80::2 metric 100 (ra)
As you can see from this output, the lan0
interface is configured via the “id0” Netplan ID to be managed by systemd-networkd. Compare this data to the netplan.yaml
file above, the networkctl
output, the local Netplan configuration in /etc/netplan/
and the auto-generated systemd-networkd configuration.
debian@cloudimg:~$ networkctl IDX LINK TYPE OPERATIONAL SETUP 1 lo loopback carrier unmanaged 2 enp0s2 ether off unmanaged 3 lan0 ether routable configured 3 links listed.
debian
@cloudimg:~$ cat /etc/netplan/50-cloud-init.yaml # [...] network: ethernets: id0: dhcp4: true dhcp6: true match: macaddress: ca:fe:ca:fe:00:aa set-name: lan0 version: 2
debian
@cloudimg:~$ ls -l /run/systemd/network/ total 8 -rw-r--r-- 1 root root 78 Jul 5 15:23 10-netplan-id0.link -rw-r--r-- 1 root root 137 Jul 5 15:23 10-netplan-id0.network
Now you can go ahead and try something more advanced, like link aggregation, using the second NIC that you configured for this QEMU VM and explore all the possibilities of Netplan on Debian, by checking the Netplan YAML documentation.