0

I'm running an ubuntu server 18.04 under VirtualBox with 2 network adapters: NAT Network (enp0s3) and a Host-only Adapter (enp0s8). I use the NAT to access the internet and the Host-only Adapter to SSH in from the host. I want the address at both interfaces to be static. At first, I thought that this was the problem but it seems that it is not.

network:
    ethernets:
        enp0s3:
            addresses: [10.0.0.200/24,]
            dhcp4: no
            dhcp6: no
            gateway4: 10.0.0.1
            nameservers:
                addresses: [8.8.8.8, 8.8.4.4]
        enp0s8:
            addresses: [192.168.1.2/24,]
            dhcp4: no
            dhcp6: no
            gateway4: 192.168.1.1
    version: 2

It seems that the two gateway definitions conflict with each other but I don't know how to make it work without it. I tried using routes and the result was the same. Maybe I used them wrong since they seemed equivalent to just having the gateway definition there. At first, it might seem like it worked and I'm able to ssh into the machine and ping google.com, but if I turn off the vm, exit vbox and then start everything again I find that I'm be able to just ssh into the vm or just ping google but never both, depending on what tweak I made to the netplan plan. How can I make that configuration work?

$ VBoxManage natnetwork list
NAT Networks:

Name:        natnet1
Network:     10.0.0.0/24
Gateway:     10.0.0.1
IPv6:        No
Enabled:     Yes
0

gateway4 refers to the router used for the default route. You should generally only have one of these. You should not list a gateway on enp0s8 if it's only used for host connections. You probably don't need to add any routes at all, as the local route to 192.168.1.0/24 is probably the only one you need.

  • That's what I thought but when I remove the gateway4 from enp0s8 I can't ssh into it from my guest machine. The behavior is not consistent, for example, the configuration I posted would allow me to ssh into the guest through enp0s8 but I wouldn't have internet on enp0s3. However, if I then commented out gateway4 from enp0s8 and applied the plan, I would have internet and be able to ssh into the guest but, if I then restarted the guest, I wouldn't be able to ssh into it once it finished booting up. – Wildland Dolphin Feb 18 at 15:15

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.