VirtualBox and two separates NATs

Aim is to create two networks (10.0.2.x and 10.0.3.x) in VirtualBox and be enable ip routing between them. At first there is no default routing (AFAIK) implemented in VirtualBox for such a scenario, thus the creation of a separate router is required.

There are two separates networks 10.0.2.x and 10.0.3.x defined in VirtualBox


Further more we need for such an example 3 virtual machines:
• router with two networks (10.0.2.x and 10.0.3.x)
• ipa2 network 10.0.2.39/24
• ipa3 network 10.0.3.5/24
Both ipa2 and ipa3 have virbr0 for internet connection (i.e. package updates)

Network on “router”

[tomas@router ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:a7:20:28 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.4/24 brd 10.0.2.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:ea:77:c4 brd ff:ff:ff:ff:ff:ff
inet 10.0.3.4/24 brd 10.0.3.255 scope global noprefixroute enp0s8
valid_lft forever preferred_lft forever
[tomas@router ~]$ ip r
default via 10.0.3.1 dev enp0s8 proto static metric 101
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.4 metric 100
10.0.3.0/24 dev enp0s8 proto kernel scope link src 10.0.3.4 metric 101

Enable ipv4 forwarding in kernel

[tomas@router ~]$ sudo sysctl net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1[tomas@router ~]$ sudo sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

Network Connection on ipa2 (ipa3 is similar)

[tomas@ipa2 ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:e5:0e:7b brd ff:ff:ff:ff:ff:ff
inet 10.0.2.39/24 brd 10.0.2.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:e1:ad:57 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever

Additional routing for 10.0.3.x network:

[tomas@ipa2 ~]$ sudo nmcli connection modify enp0s3 +ipv4.routes "10.0.3.0/24 10.0.2.4"[tomas@ipa2 ~]$ sudo nmcli connection down enp0s3 [tomas@ipa2 ~]$ sudo nmcli connection up enp0s3 
[tomas@ipa2 ~]$ ip r
default via 10.0.3.1 dev enp0s3 proto static metric 100
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.39 metric 100
10.0.3.0/24 via 10.0.2.4 dev enp0s3 proto static metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown

Checks

[tomas@ipa2 ~]$ ping 10.0.3.5
PING 10.0.3.5 (10.0.3.5) 56(84) bytes of data.
64 bytes from 10.0.3.5: icmp_seq=1 ttl=63 time=1.94 ms
[tomas@ipa3 ~]$ ping 10.0.2.39
PING 10.0.2.39 (10.0.2.39) 56(84) bytes of data.
64 bytes from 10.0.2.39: icmp_seq=1 ttl=63 time=0.899 ms

Schreibe einen Kommentar