vm-bhyve on a wifi only laptop with ipv4
========================================


Some notes on how to setup a vm-bhyve guest on a wifi only
laptop that can be accessed from the local network.

bhyve and vm-bhyve
------------------
Bhyve is the hypervisor/virtual machine manager for FreeBSD.
It has been available for several years. It is mature and solid.

vm-bhyve is a management system for FreeBSD bhyve virtual machines.
vm-bhyve eases the use of bhyve.

Wifi only laptop
----------------
The common way to run virtual machines is on a server with one or
more wired connections.

On a Wifi only laptop things become more a challenge. This is
because the network interface (wlan0 on FreeBSD) can only have
one ipv4 address.

My current setup
----------------
The notes below are about an Ubuntu guest.

Local network
............
The local network is the 192.168.2.0/24 network.
In this network are:
* the gateway to the internet
* the local nameserver
* the laptop

virtual network
..............
The vm's are in the 192.168.8.0/24 network.

rc.conf
......
Here are some lines from my /etc/rc.conf.
Maybe they are not all strictly necessary.

   gateway_enable="YES"
   pf_enable="YES"
   vm_enable="YES"
   cloned_interfaces="vm-public tun tap"

sysctl.conf
..........
Here are some lines from my /etc/sysctl.conf:

   net.link.tap.up_on_open=1

pf.conf
......
Here are some lines from my /etc/pf.conf:

   bhyve_net="192.168.8.0/24"
   ext_if="wlan0"

   nat on $ext_if from $bhyve_net to any -> ($ext_if)
   pass in all
   pass out all

vm-public
........
vm-public is the general virtual switch that is created
by vm-bhyve. On my X270 laptop, vm-public has a fixed address.
You set this in the system.conf file in the vm-bhyve .config directory:

   # system.conf
   switch_list="public"
   type_public="standard"
   ports_public="wlan0"
   addr_public="192.168.8.1/24"

ubuntu.conf
..........
Here are some lines from the file .templates/ubuntu.conf
from vm-bhyve:

   network0_type="virtio-net"
   network0_switch="public"

tap1 and guest
.............
The Ubuntu guest uses tap1 for the virtual network connection.

In order to be able to reach the guest from outside the host,
I had to manually add a static address to tap1:

   ifconfig tap1 192.168.8.5/24

In the Ubuntu guest I set the network manually to:

   ipv4 address: 192.168.8.6 (netmask 255.255.255.0)
   gateway: 192.168.8.1

The laptop uses the default local nameserver in the 192.168.2.0/24
network.

The Ubuntu guest can access the network and install packages.

To be sure the ssh server of the Ubuntu guest doesn't interfere
with the ssh server of the host, I did put it on port 2200.
I am not sure if this really is needed, but it doesn't hurt :)

Other hosts
..........
On another laptop I added a route for 192.168.8.0/24
with the ip-address of the bhyve host (laptop) as gateway.

It works!
---------
I could access with ssh the Ubuntu guest from my other laptop.
It works [tm]

And there was much rejoicing!


Last edited: $Date: 2023/09/17 15:01:47 $