Some context:
I'm trying to create a virtual private network on my laptop using VirtualBox. I want the virtual machines to be inside a private network, so a virtual machine can only be reached by other virtual machines and my laptop (the host machine). Some virtual machines need an internet connection though. To solve this problem, I've given these virtual machines two networkinterfaces:
eth0
connects to the network that my laptop is connected to (bridged). It uses DHCP to get an IP-address so I can easily switch between my home network and my work's network without having to change the static IP-address every time. (side note: I have used the built-in firewall to block any incoming connections from any network other than the private network described below)eth1
connects to the private network 192.168.1.0/24 and has a static IP-address. This network uses VirtualBox's host-only adapter so my laptop and the different virtual machines can reach each other.
My netplan configuration file
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yes
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
routes:
# Route all traffic to the default gateway that is connected to the internet.
# This setup means I still have to update the config whenever I connect to a different network.
# I was unable to find a solution for this yet.
- to: 0.0.0.0/0
via: 192.168.192.1
eth1:
dhcp4: no
dhcp6: no
addresses: [192.168.1.2/24]
gateway4: 192.168.1.1
routes:
# I know this is unnessecary because the network is directly connected
- to: 192.168.1.0/24
via: 192.168.1.1
This setup works, for a bit. When I ping for example the IP-address 8.8.8.8
, it seems to send about half of the requests to one interface and the other half to the other interface, until after some times it seems to realize that only one link works to reach the target address. Notice the sequence numbers 1, 3, 5, etc get no response.
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=29.0 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=117 time=18.1 ms
64 bytes from 8.8.8.8: icmp_seq=6 ttl=117 time=13.1 ms
64 bytes from 8.8.8.8: icmp_seq=8 ttl=117 time=13.7 ms
64 bytes from 8.8.8.8: icmp_seq=9 ttl=117 time=13.8 ms
64 bytes from 8.8.8.8: icmp_seq=10 ttl=117 time=12.2 ms
64 bytes from 8.8.8.8: icmp_seq=11 ttl=117 time=11.2 ms
64 bytes from 8.8.8.8: icmp_seq=12 ttl=117 time=13.8 ms
When I use WireShark to capture traffic over eth1, I find the missing ICMP packets with no response (obviously)
What I've tried
According do Netplan's documentation, it is possible to give a route the type of unreachable
. So giving eth1
a static route with type unreachable, all traffic must be directed trough eth0
. This did not work unfortunately.
routes:
- to: 0.0.0.0/0
type: unreachable
I've also tried using the commandline to manually add a static route
sudo ip route add 0.0.0.0/0 via 192.168.192.1 dev eth0
. This returns the message "RTNETLINK answers: File exists" after which the route is not added. The answer to this question does not resolve this issue.
Also the proposed answers to this question don't resolve this issue.
My question:
How do I route all traffic to the dynamically configured default gateway of eth0
?
I'm also interested to hear other suggestions to reach the same thing. Cheers!