11. Network

11.1. Virtual network

The hypervisor provides a virtual network. The Hypervisor Host and all the guests can be connected to this virtual network.
The IP addresses are set to fixed values.
The default IP addresses are:
Hypervisor Host: 192.168.157.1
First RTOS: 192.168.157.2
Windows example guest: 192.168.157.3

Hint

The Hypervisor Host virtual network IP address is initially set when calling the /hv/bin/inithv.sh script. If the IP addresses shall be changed, the hv_netconf command can be used to adjust the Hypervisor Host IP address, for more details, see Hypervisor Host network configuration. The IP addresses of the RTOS and KVM guests have to be adjusted accordingly.

11.2. Network Forwarding from external computer to the RTOS

11.2.1. Hypervisor Host preparation

If the RTOS (or any other OS connected to the virtual network) shall be accessed via TCP/IP from a single external system, traffic can be forwarded to the virtual network. Execute the following steps to forward traffic from a specific external computer to the RTOS:

  • enable network forwarding in the Hypervisor Host:

    sudo sysctl -w net.ipv4.ip_forward=1
    
  • determine the IP address of the Hypervisor Host. You can use the ifconfig command to accomplish this.

Caution

Assure the Default Gateway in the RTOS is set to the Hypervisor Host virtual network IP address (192.168.157.1)!
For RT-Linux it is set by default. For other RTOS you need to check the RTOS documentation how to accomplish this.

11.2.2. Forwarding from external Windows computer

  • open a Command Window with Administrator rights on your Windows PC

  • run the following command (replace AAA.BBB.CCC.DDD with the appropriate IP address of the Hypervisor Host):

    route add 192.168.157.0 mask 255.255.255.0 AAA.BBB.CCC.DDD
    

11.2.3. Forwarding from external Linux computer

  • open a Terminal Window on your Linux PC

  • run the following command (replace AAA.BBB.CCC.DDD with the appropriate IP address of the Hypervisor Host):

    ip route add 192.168.157.0/24 via AAA.BBB.CCC.DDD
    

11.3. Bridge virtual and physical network

If the RTOS (or any other OS connected to the virtual network) shall be accessed via TCP/IP from any external system, the virtual network and the respective physical network have to be bridged.

In the folder /hv/config you can find the template configuration file brvnetconfig.sh for the bridge configuration. Note, the IP address of the virtual network inside the RTOS guest need to be adjusted appropriately, see below for more details.

11.3.1. Bridge configuration

First step: determine, which network adapter should be bridged. Search for <link> entry and get the adapter name.

ifconfig -a

In this case it’s enp2s0. The current $IP$ address of enp2s0 is inet 172.17.10.53 and the network mask is 255.255.0.0.

 rtv@rtv-TEST:~$ ifconfig -a
 enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
     inet 172.17.10.53  netmask 255.255.0.0  broadcast 172.17.255.255
     inet6 2a02:590:801:2c00:7170:3747:f835:a1cb  prefixlen 64  scopeid 0x0<global>
     inet6 fe80::fe6f:c5f8:c5cd:e3cd  prefixlen 64  scopeid 0x20<link>
     inet6 2a02:590:801:2c00:96b0:b8a:2c58:6c91  prefixlen 64  scopeid 0x0<global>
     ether 90:1b:0e:18:c9:83  txqueuelen 1000  (Ethernet)
     RX packets 116751  bytes 22127837 (22.1 MB)
     RX errors 0  dropped 0  overruns 0  frame 0
     TX packets 74453  bytes 551331072 (551.3 MB)
     TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 enp3s5: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
     ether 74:ea:3a:81:4b:1d  txqueuelen 1000  (Ethernet)
     RX packets 0  bytes 0 (0.0 B)
     RX errors 0  dropped 0  overruns 0  frame 0
     TX packets 0  bytes 0 (0.0 B)
     TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
     inet 127.0.0.1  netmask 255.0.0.0
     inet6 ::1  prefixlen 128  scopeid 0x10<host>
     loop  txqueuelen 1000  (Local Loopback)
     RX packets 201  bytes 14798 (14.7 KB)
     RX errors 0  dropped 0  overruns 0  frame 0
     TX packets 201  bytes 14798 (14.7 KB)
     TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 vnet0: flags=99<UP,BROADCAST,NOTRAILERS,RUNNING>  mtu 1500
     inet 192.168.157.1  netmask 255.255.255.0  broadcast 192.168.157.255
     ether 00:60:c8:00:00:00  txqueuelen 1000  (Ethernet)
     RX packets 0  bytes 0 (0.0 B)
     RX errors 0  dropped 0  overruns 0  frame 0
     TX packets 59  bytes 10381 (10.3 KB)
     TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Next step: determine the default gateway.

ip route ls

You will get an output like default via 172.17.5.2 dev enp2s0 proto dhcp metric 100.

Next step: determine the DNS server.

resolvectl status | grep "Current DNS Server"

You will get an output like Current DNS Server: 172.17.5.9.

Next step: Adjust brvnetconfig.sh with the detected values of ifconfig:

gedit /hv/config/brvnetconfig.sh

Values:

  • netif="enp2s0"

  • defaultgw="172.17.5.2"

  • dns="172.17.5.9"

  • vnetbrip="172.17.10.53"

  • vnetbrnm="255.255.0.0"

  • #vnetbrmac= comment in and adjust value only if there are collisions with ‘same’ MAC-IDs on the network.

 #!/bin/bash

 # Ethernet network interface to bridge with VM.
 # ethernet interface to bridge with vnet
 netif="enp2s0"

 # Default gateway
 # How to determine the default gateway:
 #       Use the command ip route ls
 #           default via 172.17.5.2 dev enp2s0 proto dhcp metric 100
 #           172.17.0.0/16 dev enp2s0 proto kernel scope link src 172.17.10.4 metric 100
 #       The default gateway here is "172.17.5.2"
 defaultgw="172.17.5.2"       # default gateway

 # DNS server
 # How to determine the default gateway:
 #       Use the following command: resolvectl status | grep "Current DNS Server"
 #            Current DNS Server: 172.17.5.9
 #       The DNS server here is "172.17.5.9"
 dns="172.17.5.9"

 # Bridge settings
 # The bridge replaces the former network device used by the hypervisor to connect to the network.
 # See above results provided by the ifconfig -a command
 #       enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
 #               inet 172.17.10.53  netmask 255.255.0.0  broadcast 172.17.255.255
 #       In this example, the bridge IP address is 172.17.10.53 and the network mask is 255.255.0.0
 vnetbrip="172.17.10.53"
 vnetbrnm="255.255.0.0"

 # the values below are default values, typically not to be changed
 vnetip="192.168.157.1"
 vnetnm="255.255.255.0"
 #vnetbrmac="54:52:00:ac:30:10       # by default, the MAC address of the physical network is used
 vnet="vnet0"
 vnetbr="vnetbr"

11.3.1.1. RT-Linux Guest IP address settings

If the network is bridged, the IP address of RT-Linux must be adjusted properly. The settings are stored in /hv/guests/examples/rt-linux/linux.config. The IpAddress has to be set to a unique address in your company network, assure the entries are uncommented! The MacAddress has to be adjusted to a unique value only if more than one RT-Linux guest is bridged, in that case, please adjust the last value from 12 to 13, 14 etc.

 ; This must be set correctly if the vnet device is bridged in the Hypervisor Host
 [Rtos\Vnet\0]
     "IpAddress"="172.17.10.239"
     "MacAddress"="AA:BB:CC:DD:E0:12"

11.3.1.2. Bridge activation

  • After configuring the brige parameters, you can create the bridge:

    • First, start the RTOS to assure the virtual network is available.

    • Run the hv_brvnetset command.

  • Remove the bridge - Run the hv_brvnetclr command.

11.4. Hypervisor Host network configuration

The Hypervisor Host network can be configured using automatic IP address configuration (DHCP), manual IP address configuration or disabled network. To simplify the process, the hv_netconf command is provided.

Caution

The Hypervisor Host network configuration has to match with the KVM guest network settings (e.g. Windows or Ubuntu guest)
One of the guest network settings is determined by parameter netif_mode in the guest configuration file (e.g. usr_guest_config.sh located in the GUEST_FOLDER).
If the Hypervisor Host and guest settings do not match, the behaviour is undefined.

11.4.1. Automatic network configuration

This is the default mode. Nothing has to be changed if this mode shall be used. In case the networking had been adjusted manually, you can switch back to the automatic configuration as follows.

hv_netconf -auto

A single network interface can be set into automatic mode as follows.

hv_netconf %DEVICE% -auto

For example:

hv_netconf enp1s0 -auto

11.4.2. Manual network configuration

If you want the Hypervisor Host to be configured manually, you need to adjust the settings accordingly.

hv_netconf %DEVICE% -manual IP-address netmask-bits gateway-IP dns-IP

For example:

hv_netconf enp1s0 -manual 192.168.178.188 24 192.168.178.1 8.8.8.8

Then, configure the guest.

cd GUEST_FOLDER
gedit usr_guest_config.sh

Change the respective configuration values.

netif_mode=0
netif_m=...
defaultgw_m=...
dnsgw_m=...
brip_m=...
brnm_m=...

11.4.3. Disabled network

If you want the Hypervisor Host not to use the network, you need to adjust the settings accordingly. In case the PC currently is connected with the LAN and you want to use this connection for a guest, you need to determine the device name before disabling the Hypervisor Host network. You may use the ifconfig command for that purpose.

sudo ifconfig

Next, disable the network of the Hypervisor Host.

hv_netconf -off

You need to turn off IPv6 as follows.

sudo gedit /etc/sysctl.conf

Insert the following lines at the bottom of this file:

net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6 = 1

Make this effective:

sudo sysctl -p

Then, configure the guest.

cd GUEST_FOLDER
gedit usr_guest_config.sh

Change the respective configuration values.

netif_mode=2
netif_m=...

Caution

You must define the network device that shall be used in the guest by setting the parameter netif_m to the name you have determined above.

Hint

To re-enable the Hypervisor Host network in automatic mode, run the hv_netconf command again:

hv_netconf -auto

And change the netif_mode configuration value.

cd GUEST_FOLDER
gedit usr_guest_config.sh
netif_mode=1

11.5. SMB (Windows) file share

If you want to exchange data between the hypervisor and external (Windows) computers, you may want to create a network share.

In a first step, the SAMBA package needs to be installed:

sudo apt-get install samba

Then you need to configure the SMB server properly. It is recommended to use the same username for the network share as you are using for the Hypervisor Host. To determine the user, you may run:

whoami

In this document we assume, the username is hvuser.

If you want use a different user for the SMB share, this user must also be configured for the Hypervisor Host. For example, to add a new user smbuser, run the following command:

sudo adduser smbuser

To create a file share which is accessible from a remote Windows computer, go to the SAMBA configuration file:

sudo gedit /etc/samba/smb.conf

In the below example, we will create a share with the name guests ([guests]) which will share the folder /hv/guests.

Add the following section to the end of the smb.conf file and save:

[guests]
  comment = guests share
  path = /hv/guests
  browseable = yes
  valid users = hvuser
  guest ok = yes
  read only = no

If you encounter issues with the file share, you may also adjust the following section in the smb.conf file:

[global]
map to guest = never

Then you need to provide network share access for the user hvuser:

sudo smbpasswd -a hvuser

Restart the SAMBA service:

sudo systemctl restart smbd.service nmbd.service

To check, if the share is active, try to access the SAMBA share from the Windows explorer. You may have to use the IP address of the hypervisor.

Access to share from Windows file explorer.

Fig. 11.1 Access to share from Windows file explorer.