Hello all,
I am trying to use QEMU to emulate a x86_64 machine to run OpenBSD 6.9 inside FreeBSD 12.2-RELEASE with two tap interfaces. Hardware is an Intel Xeon E5450, 8GB DDR2, SATA SSD. This CPU doesn't have EPT support so I can't use bhyve and I don't want to use VirtualBox. I would like, if at all possible, use QEMU.
I added the following to /boot/loader.conf:
to /etc/sysctl.conf:
to /etc/devfs.conf:
to /etc/rc.conf:
It's my desire to have both tap0 and tap1 connected to the QEMU-emulated OpenBSD instance in order to set it up as a gateway, firewall and so on. tap0 should connect to bridge0 (LAN) and tap1 should connect to bridge1 (WAN).
I first tried installing QEMU 5.x from ports but later settled for the generic pkg install to save on time. I also pkg install(ed) qemu-utils.
Playing around with QEMU demonstrated that qemu-system-x86_64 was fully capable of setting the desired network configuration when suitable scripts were present under /usr/local/etc/qemu-ifup and /usr/local/etc/qemu-ifdown. I copied the scripts from here:
As you'll no doubt notice, I relied heavily on that guide from 2009.
The closest I've come to anything resembling success so far is by running the machine with the config files as noted above, manually removing the bridges and tap interfaces after boot (redundant, I know) and invoking QEMU with:
To view the QEMU machine I run:
I then input "set tty com0" at the OpenBSD boot terminal to enable the serial console and everything seems great, I can install OpenBSD, list network interfaces with ifconfig and set IPs for example, but I can't reach the host network, the internet or even ping outside the emulated machine. Running a jail tied to em0 (the interface attached to bridge0, beside tap0) and trying to ping from either side (jail -> obsd or the other way around), with IPs set to the same subnet inside the jail and OpenBSD, produces no results.
What am I missing?
Thank you very much.
EDIT:
I am trying to use QEMU to emulate a x86_64 machine to run OpenBSD 6.9 inside FreeBSD 12.2-RELEASE with two tap interfaces. Hardware is an Intel Xeon E5450, 8GB DDR2, SATA SSD. This CPU doesn't have EPT support so I can't use bhyve and I don't want to use VirtualBox. I would like, if at all possible, use QEMU.
I added the following to /boot/loader.conf:
Bash:
if_tap_load="YES"
if_bridge_load="YES"
to /etc/sysctl.conf:
Bash:
net.link.tap.user_open=1
net.link.tap.up_on_open=1
to /etc/devfs.conf:
Bash:
own tap0 root:wheel
own tap1 root:wheel
to /etc/rc.conf:
Bash:
cloned_interfaces="bridge0"
autobridge_interfaces="bridge0"
autobridge_bridge0="tap* em0"
It's my desire to have both tap0 and tap1 connected to the QEMU-emulated OpenBSD instance in order to set it up as a gateway, firewall and so on. tap0 should connect to bridge0 (LAN) and tap1 should connect to bridge1 (WAN).
I first tried installing QEMU 5.x from ports but later settled for the generic pkg install to save on time. I also pkg install(ed) qemu-utils.
Playing around with QEMU demonstrated that qemu-system-x86_64 was fully capable of setting the desired network configuration when suitable scripts were present under /usr/local/etc/qemu-ifup and /usr/local/etc/qemu-ifdown. I copied the scripts from here:
As you'll no doubt notice, I relied heavily on that guide from 2009.
Bash:
#!/bin/sh
#
#/usr/local/etc/qemu-ifup
IFNAME=em0
for BRIDGE in $(ifconfig -a | grep '^bridge' | cut -d: -f1)
do
if [ -n "$(ifconfig "$BRIDGE" | grep -w "member: $IFNAME")" ]
then
echo "${##*/}: Adding $1 as a member of $BRIDGE"
/sbin/ifconfig "$BRIDGE" addm "$1" up
exit
fi
done
BRIDGE="$(/sbin/ifconfig bridge create)"
/sbin/ifconfig "$BRIDGE" addm "$IFNAME" addm "$1" up
echo "${0##*/}: Created $BRIDGE and added $1 as a member"
Bash:
#!/bin/sh
#
# /usr/local/etc/qemu-ifdown
#
for BRIDGE in $(ifconfig -a | grep '^bridge' | cut -d: -f1)
do
if [ -n "$(ifconfig "$BRIDGE" | grep -w "member: $1")" ]
then
if [ "$(ifconfig "$BRIDGE" | grep -c -w "member:")" -le 2 ]
then
echo "${0##*/}: Destroying $BRIDGE"
/sbin/ifconfig "$BRIDGE" destroy
fi
echo "${0##*/}: Destroying $1"
/sbin/ifconfig "$1" destroy
fi
done
The closest I've come to anything resembling success so far is by running the machine with the config files as noted above, manually removing the bridges and tap interfaces after boot (redundant, I know) and invoking QEMU with:
Bash:
qemu-system-x86_64 \
-m 1024 \
-cdrom install69.iso \
-drive if=virtio,format=raw,file=obsd-x64.raw \
-netdev tap,id=nd0,ifname=tap0 -device virtio-net,netdev=nd0 \
-netdev tap,id=nd1,ifname=tap1 -device virtio-net,netdev=nd1 \
-nographic \
-serial tcp::4450,server,telnet,wait
To view the QEMU machine I run:
Code:
telnet localhost 4450
I then input "set tty com0" at the OpenBSD boot terminal to enable the serial console and everything seems great, I can install OpenBSD, list network interfaces with ifconfig and set IPs for example, but I can't reach the host network, the internet or even ping outside the emulated machine. Running a jail tied to em0 (the interface attached to bridge0, beside tap0) and trying to ping from either side (jail -> obsd or the other way around), with IPs set to the same subnet inside the jail and OpenBSD, produces no results.
What am I missing?
Thank you very much.
EDIT:
I don't think I am using SLiRP though.Note - if you are using the (default) SLiRP user networking, then ping (ICMP) will not work, though TCP and UDP will. Don't try to use ping to test your QEMU network configuration!