2

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.

PS: Originally, I asked this question on ServerFault, but it was migrated to SuperUser (mistakenly in my opinion). Someone suggested it might be more appropriate here, so I am trying it.

  • Could you post content of the file /etc/network/interfaces – Bob Aug 18 '18 at 13:53
  • The file does not exist because I am using netctl. – Sinan Ünür Aug 18 '18 at 14:37
1

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.

  • +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. – Sinan Ünür Aug 18 '18 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 Aug 18 '18 at 14:43
  • I'll try and report back, but it will be a while. – Sinan Ünür Aug 18 '18 at 15:26
  • /etc/network/interfaces is a Debian mechanism. The questioner stated that xe is using Arch. – JdeBP Aug 18 '18 at 15:55
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.