I need a Linux VM on my FreeBSD machine for a bunch of FPGA dev work. Thanks to a bunch of folks on the Internet, we have a pretty quick and dirty way of getting Linux setup via bhyve.
Because I was trying to do things via wireless networking, I couldn’t use the most common and easy method for networking to just use dhcp and a bridge(4) with tap(4) on my laptop. I asked a few people in the FreeBSD Discord, trolled FuzzyKaren’s great Kubernetes blog (https://productionwithscissors.run/) and browsed a few FreeBSD forums to come up with something so simple.
Use the UEFI install method for your linux VM, I used the FreeBSD Handbook and a ZFS zvol for it storage. https://www.cyberciti.biz/faq/how-to-install-linux-vm-on-freebsd-using-bhyve-and-zfs/
I reconfigured the networking in the Ubuntu VM to be statically assigned to 10.0.0.2/24 with a gateway of 10.0.0.1 (and using my home dns server at 192.168.1.1). I setup the tap0 interface being used with:
gateway_enable="YES"
# tap interfaces for ubuntu VM
cloned_interfaces="tap0"
ifconfig_tap0="inet 10.0.0.1 netmask 255.255.255.0"
This bit will let your laptop and your Bhyve VM see each other, but you’ll need a small amount of PF to get to the Internet:
wlan_if="wlan0"
# create all VM interfaces in this subnet
vm_net="10.0.0.0/24"
vm_ubuntu="10.0.0.2"
nat on $wlan_if from $vm_ubuntu to !$vm_net -> $wlan_if
pass out all
pass in all