3

Update: /etc/network/interfaces does not exist because I am using netctl profiles.

I set up a VirtualBox instance running ArchLinux with two network adapters. Adapter 1 (eth0) is attached to a NAT (10.0.2.0/24) and Adapter 2 (eth1) is on the host only network (192.168.56.0/24). I use udev rules to use old-fashioned names eth0 and eth1 for these adapters (but the issue existed with the enp*** names as well).

When I log on, I get this:

$ ip route
default via 192.168.56.1 dev eth1 
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 202 
10.0.2.0/24 dev eth0 proto dhcp scope link src 10.0.2.15 metric 202 
192.168.56.0/24 dev eth1 proto kernel scope link src 192.168.56.31

which results in

$ ping google.com
ping: google.com: Name or service not known

As I understand it, this is because 192.168.56.1 (the host only interface) is added with a lower metric than the NAT interface.

If I then manually do:

$ sudo ip route delete default
$ ip route
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 202 
10.0.2.0/24 dev eth0 proto dhcp scope link src 10.0.2.15 metric 202 
192.168.56.0/24 dev eth1 proto kernel scope link src 192.168.56.31

I get

$ ping google.com
PING google.com (172.217.12.174) 56(84) bytes of data.
64 bytes from ....1e100.net (172.217.12.174): icmp_seq=1 ttl=52 time=11.9 ms
64 bytes from ....1e100.net (172.217.12.174): icmp_seq=2 ttl=52 time=11.7 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 3ms
rtt min/avg/max/mdev = 11.698/11.782/11.867/0.137 ms

So, how can I ensure that outbound traffic is routed through eth0/10.0.2.0/24 (NAT interface to host) rather than eth1/192.168.56.0/24 (host only network).

The question is only tangentially related to VirtualBox (if there is a VirtualBox setting that allows me to change the metrics, I wouldn't mind it).

I believe there must be a way to do one of 1) Stop systemd from adding the default via 192.168.56.1 dev eth1 route; or 2) Add the default via 10.0.2.2 dev eth0 route with a lower metric, so I don't have to delete the default route manually every time I start the instance.

There might be another work-around I haven't considered yet. So far fiddling with names, static IP vs DHCP did not help.

The guest OS is ArchLinux.

2
  • Could you post content of the file /etc/network/interfaces
    – Bob
    Commented Aug 18, 2018 at 13:53
  • 1
    The file does not exist because I am using netctl. Commented Aug 18, 2018 at 14:37

3 Answers 3

2

Add in the /etc/network/interfaces file to corresponding interface the line:

post-up route del default via 192.168.56.1 dev eth1

which will delete the route default via 192.168.56.1 dev eth1 on interface startup.

4
  • +1 This did not immediately work in this case because I am using netctl profiles (my fault for not mentioning that). /etc/network/interfaces did not exist and creating it with the content had no effect. However, your answer nudged me in the right direction. I'll look some stuff up and come back to this later. Thank you. Commented Aug 18, 2018 at 14:40
  • @SinanÜnür If you're using netctl, possibly this approach will help you: bbs.archlinux.org/viewtopic.php?id=184434
    – Bob
    Commented Aug 18, 2018 at 14:43
  • I'll try and report back, but it will be a while. Commented Aug 18, 2018 at 15:26
  • 1
    /etc/network/interfaces is a Debian mechanism. The questioner stated that xe is using Arch.
    – JdeBP
    Commented Aug 18, 2018 at 15:55
2

Following @Bob's advice, I realized that the problem was that my static IP profile for the host-only network was specifying a gateway. I removed that and everything worked the way I wanted.

Here are the two netctl profiles:

Description='Host only connection'
Interface=eth1
Connection=ethernet
IP=static
Address=('192.168.56.31/24')
DNS=('192.168.1.1')

and

Description='Internet connection via NAT'
Interface=eth0
Connection=ethernet
IP=dhcp

This results in:

$ ip route
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 202 
10.0.2.0/24 dev eth0 proto dhcp scope link src 10.0.2.15 metric 202 
192.168.56.0/24 dev eth1 proto kernel scope link src 192.168.56.31

which may or may not be perfect, but it works for me.

1

Yes it's an old question but I came here looking for how the default routes worked for a systemd config I set up years ago that suddenly stopped working.

To answer this question you could use the sledge hammer approach and put in an /etc/networkd-dispatcher/routable.d/50-ifup-hooks file and manually craft your final desired route table there. Basically delete the routes the system creates and supply your own.

But make sure the permissions on the file are 755. That was my issue for it not running :(

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .