10

I'm running VirtualBox with 2 network adapters: standard NAT (enp0s3) and a Host-only Adapter (enp0s8). I use the NAT to access the internet and the Host-only Adapter to SSH in from my local machine.

The box boots up with both adapters enabled, both have IP addresses, everything looking good.

ifconfig-output

I can SSH into this box over the host-only adapter, no issues there. But I can't get on the internet with it. However, if I disable the host-only adapter, then I can access the internet (but obviously I can no longer SSH into it over the local tunnel).

console-output

And finally, here is my netplan yaml config:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
ethernets:
  enp0s3:
    dhcp4: yes
    dhcp6: yes
  enp0s8:
      dhcp4: no
    dhcp6: no
    addresses: [192.168.52.101/24]
    gateway4: 192.168.52.101

Any ideas? It seems like maybe all my outbound traffic is routing through the host-only adapter somehow.

Edit: attaching the output of ip route list in case it helps.

default via 192.168.52.101 dev enp0s8 proto static
default via 10.0.2.2 dev enp0s3 proto dhcp src 10.0.2.15 metric 100
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15
10.0.2.2 dev enp0s3 proto dhcp scope link src 10.0.2.15 metric 100
192.168.52.0/24 dev enp0s8 proto kernel scope link src 192.168.52.101
  • Forget it, I couldn't figure out netplan so I formatted and installed Ubuntu 16 instead. – hellojason Dec 11 '17 at 2:17
11

I found this problem doing exactly the same thing this afternoon. Somehow managed to figure it out and netplan finally created only 1 default route through the NAT interface of my VM. In my case, both IP's were 192.168.56.101 (host-only) and 10.0.3.x/24 (NAT dhcp4). I'm using this netplan file:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s8:
          dhcp4: yes
          dhcp6: yes
          routes:
          - to: 0.0.0.0/0
            via: 10.0.3.2
            metric: 0
        enp0s3:
          dhcp4: no
          dhcp6: no
          addresses: [192.168.56.101/24]
          routes:
          - to: 192.168.56.1/24
            via: 192.168.56.1
            metric: 100

With this I have only one default route, and it's using the NAT so it can reach the internet through my host.

Output of ip r

default via 10.0.3.2 dev enp0s8 proto dhcp src 10.0.3.15 metric 100
10.0.3.0/24 dev enp0s8 proto kernel scope link src 10.0.3.15
10.0.3.2 dev enp0s8 proto dhcp scope link src 10.0.3.15 metric 100
192.168.56.0/24 dev enp0s3 proto kernel scope link src 192.168.56.10
  • 2
    Great answer! You indeed need to set up your own routing in this case. If both devices include a "default gateway" (ie. they specify "dhcp4" or "dhcp6", or set "gateway4"), then the system will set up both devices with a default gateway with the same metric. You won't need the route on enp0s3 however, since the "addresses" already contain the same /24 subnet as the one that would be used to access 192.168.56.1. Alternatively, set your own routing everywhere as you are doing. – Mathieu Trudel-Lapierre Mar 9 '18 at 11:23
7

For me removing gateway4 from configuration did the trick. With it configured I was also not able to ping internet.

Here is my netPlan config if it can help others.

Note: enp0s3 is for ssh via port forwarding and enp0s8 for static ip

network:
    ethernets:
        enp0s3:
            addresses: []
            dhcp4: true
            optional: true
        enp0s8:
            addresses: [192.168.10.20/24]
            dhcp4: no
            dhcp6: no
            nameservers:
              addresses: [8.8.8.8, 8.8.4.4]
    version: 2
  • Yes, removing the gateway4 line the only thing that worked for me. – furman87 Jun 4 at 13:58
0

As a note, while I was struggling with this and VMware Fusion... If you have any 'gateway4' value specified, it will assume that as default for the interface, and it doesn't seem to respect the 'metric' option or having multiple .yaml files with a numbering sequence (01-netplan.yaml, 02-netplan.yaml, etc...) in my case 02 ended up being the 'first default', but that is my internal network so public internet was unreachable.

  • Hi Mike -- welcome to askubuntu. This would be better as a Comment under the question. You should move the text there and just delete this as it isn't intended to "answer" the question. – dpb Apr 11 '18 at 3:35

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.