Wednesday, May 07, 2025

Configuring TUN/TAP virtual network interface for use with QEMU on Xubuntu 24.04

Configuring TUN/TAP virtual network interface for use with QEMU on Xubuntu 24.04

I am planning to run qemu-system-ppc to play around QEMU and PPC with networking support. The quest and U-Boot will need to interact with external services, namely, tftp. The recommended network is to have TUN/TAP virtual network interface configured on the host. My host is Xubuntu 24.04/Ubuntu 24.04.

Let's start by creating tap0 using systemd
u1@m18:~$ sudo nvim /etc/systemd/system/tap0.service
Copy/paste content below
[Unit]
Description=Create TAP interface tap0
Before=network-pre.target
Wants=network-pre.target
DefaultDependencies=no
[Service]
Type=oneshot
ExecStart=/sbin/ip tuntap add dev tap0 mode tap user u1
ExecStartPost=/sbin/ip link set tap0 up
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
view raw tap0.service hosted with ❤ by GitHub
Change u1 to the user who needs access to tap0

Run command below to create tap0. This should also presist after reboot
u1@m18:~$ sudo systemctl daemon-reexec
u1@m18:~$ sudo systemctl enable --now tap0.service
Create a backup of existing netplan configuration
u1@m18:~$ mkdir ~/backup
u1@m18:~$ cd /etc/netplan
u1@m18:~$ sudo mv * ~/backup
Create new netplan configuration, let us call it 01-netcfg.yaml
u1@m18:~$ sudo touch /etc/netplan01-netcfg.yaml
u1@m18:~$ sudo chmod 600 /etc/netplan/01-netcfg.yaml
u1@m18:~$ sudo nvim /etc/netplan/01-netcfg.yaml
Copy/paste gist below into 01-netcfg.yaml.
network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: no
dhcp6: no
tap0:
optional: true
bridges:
br0:
interfaces: [ens33, tap0] # Added tap0 here
dhcp4: yes
dhcp6: no
parameters:
stp: true
forward-delay: 4
Note that ens33 is my interface name, so update that as appropriate.

Now disable Network Manager and enable networkd. The command below will reconfure your network, so you need to be on the console and not via ssh.
u1@m18:~$ sudo systemctl stop NetworkManager.service
u1@m18:~$ sudo systemctl disable NetworkManager.service
u1@m18:~$ sudo systemctl start systemd-networkd.service
u1@m18:~$ sudo systemctl enable systemd-networkd.service
Now apply netplan configuration
u1@m18:~$ sudo netplan apply
Running QEMU below and issuing dhcp at U-boot prompt should allow the guest to get IP address from DHCP server. Of course, I am assuming that there is DHCP server in the network.
u1@m18:~$ qemu-system-ppc -M mpc8544ds -cpu mpc8540 -m 512 -nographic -netdev tap,id=net0,ifname=tap0,script=no,downscript=no -device e1000,netdev=net0 -serial mon:stdio

No comments:

Configuring TUN/TAP virtual network interface for use with QEMU on Xubuntu 24.04

Configuring TUN/TAP virtual network interface for use with QEMU on Xubuntu 24.04 I am planning to run qemu-system-ppc to play around QEMU ...