Fist we need to create a directory where vm-bhyve will store it’s
configuration as well as the various VMs created:
Creating vm-bhyve directory
1
2
zfs create -omountpoint=/var/bhyvemain/bhyve# Create vm-bhyve directory
zfs set compress=zstd main/bhyve# Enable compression if desired
Enabling vm-bhyve and specifying it’s directory is done in the
system configuration file rc.conf:
rc.conf
1
2
vm_enable="YES"
vm_dir="zfs:main/bhyve"
Allows vm-bhyve to initialize it’s infrastructure:
Initialize vm-bhyve infrastructure
1
vm init
Various templates are available in /usr/local/share/examples/vm-bhyve/,
they should be copied (and adapted) in the .templates
directory inside the defined in vm_dir (in case of a zfs filesystem,
the mountpoint is used).
The bridge interface on which bhyve will attach is manually configured,
instead of letting vm-bhyve manage it, so it’s easier to integrate
on other part of the system.
Element
Description
wan0
Interface to the outside world
bridge1
Cloned bridge interface
vmnet0
Renamed bridge1 interface
bhyve-bridge
Name given to the ‘switch’ is vm-bhyve
192.168.100.0/24
Subnet dedicated to VMs
192.168.100.1
IP address of the host on the VM subnet
192.168.1.1
IP address of the host
Create the vmnet0 interface and assign it an IP address,
the interface is also given a group name jail to ease management
in complex firewall rules:
rc.conf
1
2
3
cloned_interfaces="bridge1"
ifconfig_bridge1_name="vmnet0"
ifconfig_vmnet0="inet 192.168.100.1/24 group jail"
If we want to give the VM access to the outside world
we need to have the host act as a gateway, and also as here
the VMs have been defined on a private network NAT must be enabled:
pf.conf
1
natpassonwan0inetfromvmnet0:networktoany -> wan0
rc.conf
1
2
gateway_enable="yes"pf_enable="yes"
It is possible to use, for a more complex configuration, a full
featured DHCP, TFTP and DNS server to provide the necessary network
services for booting and network access, but we have chosen here to
use dnsmasq which conveniently provide all these services with a
simple configuration:
dnsmasq.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Select listening interface
interface=vmnet0# Select the interface on which to listen
except-interface=lo0# Ensure we don't listen on loopback
bind-interfaces# Bind to interfaces instead of listening on wildcard
# DNS (with DNSSEC enabled)
domain-neededconf-file=/usr/local/share/dnsmasq/trust-anchors.confdnssecdnssec-check-unsigned# DHCP
dhcp-authoritativedhcp-range=192.168.100.10,192.168.100.150,24h# Using statically allocated addresses for some guests
# infinite = maximum lease time
dhcp-host=debian,192.168.100.55# from provided hostname
dhcp-host=58:9c:fc:0d:84:bd,192.168.100.52,infinite# from MAC address
We now let vm-bhyve know that we have created an interface
where it will be able to connect the VMs:
system.conf
1
2
3
4
5
6
# List of available switch
switch_list="bhyve-bridge"# Switch definition
type_bhyve-bridge="manual"bridge_bhyve-bridge="vmnet0"
named doesn’t support tapX interface created
by vm-bhyve and get stuck on it so we are forced to
specified listen address (directive: listen-on and
listen-on-v6) of all the desired intefaces so to skip
tapX (no more keyword: any).