Virtual machine network configuration
Virtual machines can be configured with virtual network controllers to connect the virtual machine to a network. Virtual machines use tap(4)or
vmnet(4) network interfaces of the TwinCAT/BSD host, which in turn are managed under TwinCAT/BSD with the help of ifconfig(8).
The following command creates a new vmnet(4)
instance:
doas ifconfig vmnet create
vmnet0
Similarly, tap(4) instances can be created
doas ifconfig tap create
tap0
tap(4) and vmnet(4) network interfaces can be created via cloned_interfaces at system startup. To do this, the instances of the cloned_interfaces listing can be added to the rc configuration:
doas sysrc cloned_interfaces+="vmnet0 tap0"
The created vmnet(4)
or tap(4)
instances (in this case vmnet0
and tap0
) can then be used as an Ethernet endpoint for a virtual machine to exchange Ethernet packets between the TwinCAT/BSD host and the virtual machine environment.
To do this, the bhyve
call is started for one or more emulated virtio-net
devices that use the previously created network interfaces as endpoints. A MAC address is generated for each network interface of the virtual machine. Optionally, each network interface can also be given a defined MAC address with ,mac=xx:xx:xx:xx:xx:xx
.
The following command starts a virtual machine with two virtual network controllers that use the above-mentioned instances vmnet0
and tap0
at PCI slot -s 20
and -s 21
as endpoints on the host side and receive defined MAC addresses:
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 2,fbuf,rfb=0.0.0.0:5900,w=1024,h=768 \
-s 3,xhci,tablet \
-s 20,virtio-net,vmnet0,mac=58:9c:fc:02:34:25 \
-s 21,virtio-net,tap0,mac=58:9c:fc:03:5e:ec \
-s 31,lpc \
-A -H -P \
samplevm
Thus, virtual machines are always connected to external networks via tap(4)
or vmnet(4)
devices.
The configuration with virtual network controllers is as follows:
Depending on the application, a virtual machine can also be configured with additional network controllers in order to be integrated into different networks. The connection of a virtual machine to a network is then determined by the configuration of the respective tap(4)
or vmnet(4)
devices on the TwinCAT/BSD host. This results in different possibilities to realize the communication of virtual machines into a network: