Tap networking in ubuntu for qemu

I’m using ubuntu server 20.04 and I’m trying to set up a bridge connection for qemu to tap into. I updated the kernel to 5.14 just to see if that changed anything and it didn’t. The qemu stuff works on windows just fine its only ubuntu that the vm doesn’t get a ip so I think I have done something incorrectly on the networking side. Any recommendations would be really appreciated

my start script v1:

TAPDEV="$1"
BRIDGEDEV=“br0”
ip tuntap add $TAPDEV mode tap
ip link set dev $TAPDEV up
ip link set $TAPDEV master br0

my start script v2

TAPDEV="$1"
BRIDGEDEV=“br0”
tunctl -t $TAPDEV -u ‘user’
brctl addif br0 $TAPDEV
ifconfig $TAPDEV up
ifconfig br0 up
brctl show

this is what I have after running my tap up script:

user@mac-emulation:~/Documents/Test PPC/tap-scripts$ sudo ./tap-up.txt tap1
user@mac-emulation:~/Documents/Test PPC/tap-scripts$ ip addr
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
link/ether 00:50:56:b0:a8:8c brd ff:ff:ff:ff:ff:ff
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:50:56:b0:a8:8c brd ff:ff:ff:ff:ff:ff
inet 10.5.1.118/20 brd 10.5.15.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:feb0:a88c/64 scope link
valid_lft forever preferred_lft forever
16: tap1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel master br0 state DOWN group default qlen 1000
link/ether 26:21:90:a1:ed:fd brd ff:ff:ff:ff:ff:ff

my stop script:

TAPDEV="$1"
BRIDGEDEV=“br0”
sudo ip link delete $TAPDEV

i used netplan to create the bridge:

network:
ethernets:
ens160:
dhcp4: true
dhcp6: false
bridges:
br0:
interfaces: [ ens160 ]
dhcp4: yes

this is my launch arguments just in case:

./qemu-system-ppc -L pc-bios -boot c -cpu “g4” -M mac99,accel=tcg -m 256 -prom-env “auto-boot?=true” -prom-env “boot-args=-v” -prom-env “vga-ndrv?=true” -drive file=MacOS9.2.img,format=raw,media=disk -device sungem,netdev=network01,mac=52:54:00:12:34:56 -netdev tap,id=network01,script=./tap-scripts/tap-up.txt,downscript=./tap-scripts/tap-down.txt -device VGA,edid=on -g 1024x768x32 -device usb-tablet -rtc base=localtime -vnc :1

no-carrier on tap1 tells me that qemu is not bothering to use the nic,…in real network cards it means nothing’s plugged into the other end, in tap interfaces it means the device socket is still closed. There’s a few further things I’d test/try out…

  • what if you used a Linux image in guest?
  • what if you used e1000 or pcnet instead of sungem
  • do you see any DHCP requests coming from the tap1 interface in tcpdump -ni tap1; what are they going out on ens160 and getting any replies?
  • maybe you have iptables forwarding disabled and [sysctls configured to use it on bridge traffic](Net.bridge.bridge-nf-call and sysctl.conf - Libvirt Wiki] in which case tcpdump will show DHCP requests coming in on tap1 and not going out on ens160 , or vice-versa. (I don’t think your VM was up when you got no-carrier, so it’s possible drivers are fine, and other host is just being firewalled).
1 Like

9: tap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UNKNOWN group default qlen 1000
link/ether 0a:b0:b2:28:55:cf brd ff:ff:ff:ff:ff:ff
inet6 fe80::8b0:b2ff:fe28:55cf/64 scope link
valid_lft forever preferred_lft forever

that’s from running state and does not appear to have no-carrier now, but i did notice this little error when starting qemu

TUNSETIF: Device or resource busy

  • what if you used a Linux image in guest?

X: i installed mint and it also failed to get ip or any networking so it must be something wrong outside the vm and in the bridge

  • what if you used e1000 or pcnet instead of sungem

X: os9 seems to only support sungem, i tried the other two but they must need drivers to function

  • do you see any DHCP requests coming from the tap1 interface in tcpdump -ni tap1 ; what are they going out on ens160 and getting any replies?

X:im getting lots of arp packets from my main network but this seemed interesting

07:13:52.531867 STP 802.1d, Config, Flags [none], bridge-id 1000.18:e8:29:20:c0:f5.8003, length 43

i don’t see any dhcp requests coming from tap0 or ens160, maybe qemu is never jacking into the tap interface but it doesn’t say no-carrier so its connected?

  • maybe you have iptables forwarding disabled and [sysctls configured to use it on bridge traffic](Net.bridge.bridge-nf-call and sysctl.conf - Libvirt Wiki] in which case tcpdump will show DHCP requests coming in on tap1 and not going out on ens160 , or vice-versa. (I don’t think your VM was up when you got no-carrier, so it’s possible drivers are fine, and other host is just being firewalled).

X: I don’t get the errors described and i checked /etc/sysconfig/bridge.conf and the lines are there like it says they should be, and running sysctl -p doesn’t give me the key error

Bridges in Linux come with “spanning tree protocol” aka. stp enabled by default (…or is it that most distros enable them? you can disable this as a once off, I’m doubtful it’s what’s causing you issues).

TUNSETIF: Device or resource busy

This is omenous, putting on my rubber ducky hat, it tells me your scripts, or your command line are wrong and you’re opening the tap interface twice somehow.

(sorry, got to head out to work… check the qemu man page as horrible as it is to read, and as lacking in examples as it might be, it may have more details on scripts to use).

So i used wireshark to better look at packets and I did see the dhcp happening on tun0 and on br0! However the offer never gets to tap0, capture in picture is of br0

10.5.1.1 is router, 10.5.1.136 is host ip

So it’s probably something to do with iptables? Internal linux networking is French to me haha, but i guess i need to allow these type of requests to my tap devices? (i do plan on making multiple)

i can ping through the tap interface with this command:

why wolnt dhcp requests get to the vm! iv tryed asieinging static ip to vm and it still wolnt pass traffic

the top is when i had static ip assiegned, it couldnt even find the router at 10.5.1.1, the bottom is when i switched it back to dhcp