11. Network
11.1. Virtual network
192.168.157.1192.168.157.2192.168.157.3Hint
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=1determine the IP address of the Hypervisor Host. You can use the
ifconfigcommand to accomplish this.
Caution
(192.168.157.1)!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-IDson 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_brvnetsetcommand.
Remove the bridge - Run the
hv_brvnetclrcommand.
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
usr_guest_config.sh located in the GUEST_FOLDER).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