Host-Only network

In a Host-Only network configuration, network packets are only exchanged between the virtual machine and the TwinCAT/BSD host. A vmnet(4) interface is created on the TwinCAT/BSD host for this purpose. The vmnet(4) instance serves as a backend for an emulated virtio-net or e1000 Ethernet controller of the virtual machine. Within the guest system, the Ethernet controller is recognized as a network interface. The IP addresses of the host and guest network interfaces are then configured to create a Host-Only network.

Host-Only network 1:
VM instance with a Host-Only network configuration.

To configure a Host-Only network, a vmnet(4) interface is created on the TwinCAT/BSD host with ifconfig and this network interface is assigned a private IP address.

doas ifconfig vmnet create inet 192.168.1.10 netmask 255.255.255.0

So that the vmnet instance is already created at system startup, it can be stored in the rc configuration:

doas sysrc cloned_interfaces+="vmnet0"
doas sysrc ifconfig_vmnet0="inet 192.168.1.10 netmask 255.255.255.0"

The vmnet(4) device is then transferred to the virtual machine as a backend for a virtual network controller of type virtio-net (see figure above).

Within the guest system, the virtual network interface must be configured to be on the same IP network as the vmnet0 interface of the TwinCAT/BSD host (sample above: 192.168.1.0/24). Afterwards the Host-Only communication can be checked with ping requests between TwinCAT/BSD host and guest system.

The following call starts the virtual machine samplevm with a virtio-net based network controller at PCI address 20. The previously configured vmnet0 instance is passed as the backend.

doas bhyve \
-c sockets=1,cores=1,threads=1 \
-m 2G \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_BHF_UEFI.fd,fwcfg=qemu \
-s 0,hostbridge \
-s 20,virtio-net,vmnet0 \
-s 31,lpc \
-A -H -P \
samplevm