0

I am using Ubuntu 18 minimal image to create an Ubuntu server with VirtualBox. I created a host only network and added adapter to vm along with NAT adapter (already configured).

The original configuration of netplan was the following:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: yes

I changed this configuration to the following to enable host only adapter (enp0s8):

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: ye
    enp0s8:
      dhcp4: no
      addresses: [192.168.56.101/24]
      gateway4: 192.168.56.1

Now I am successfully able to access the VM from the host machine over the network. But internet inside the VM stops working :(. I have tried so many different solutions but either I get internet working (provided by NAT adapter) by disabling host only adapter, or can access vm from host by enabling host only adapter.

I suspect the VM is trying to connect to internet via host only adapter. How can I change this?

  • Delete the host-only adapter. Host-only is NOT a useful answer for your use case. Your problem is how to create a network connection from host to guest using NAT. – user535733 Sep 21 '19 at 19:26
  • If one wants to access samba or something which hard to assign destination port, host-only adapter is still very useful. – Alvin Liang Nov 8 '19 at 3:40
2

I am also hitting the same issue. I am able to get it work by removing this line:

      gateway4: 192.168.56.1

There are other alternatives discussed in netplan configuration on Ubuntu 17.04 virtual machine, however what I need is just to set up a lab environment for testing, so I didn't try those out.

| improve this answer | |
  • @Pablo thanks for the formatting improvement. – victor6510 Dec 30 '19 at 3:16
0

I have almost very similar situations, but not exactly the same. I want to share the problem and solution for my setup here, because the final step that make it works was the answer stated by @victor6510 above.

I have Ubuntu Server (18.0.4) guest running inside LinuxMint host. I have setup the server initially as follow:

  • Network: Bridged-Adapter (fixed IP on my home router's network)

I have a VPN client in the LinuxMint host. My objective is to allow the Ubuntu guest to access server through the VPN connection. It was not easy, but after some reading, I decided the NAT adapter option is the most likely solution. Hence I did the following:

  1. Add new network adapter in VirtualBox settings for my Ubuntu guest (NAT)
  2. Reboot Ubuntu guest
  3. Configure netplan setting for the Ubuntu guest
  4. Do netplan generate & netplan apply

Here is my netplan configuration inside the Ubuntu guest:

network:
  ethernets:
    enp0s3:
        dhcp4: no
        addresses: [192.168.1.200/24]
        #gateway4: 192.168.1.254
        nameservers:
                addresses: [8.8.8.8,8.8.4.4]
    enp0s8:
        dhcp4: yes
  version: 2

enp0s3 is the Bridged adapter

enp0s8 is the NAT adapter

Before I commented the line gateway4: 192.168.1.254, Internet and ping stopped from working. Once commented, I have Internet, and able to connect to my server on the other side of the VPN. Hope this will help anyone facing similar situation.

NOTE: I don't know details setting of the VPN server I connected to.

| improve this answer | |
0

In short when we have both NAT and host-only adapter for a VM.Then make sure for host-only adapter we do not have gateway4 defined.

For example in yaml file

network:
 ethernets:
   enps08:
     addresses: [192.168.56.100/24]
     dhcp: no
     #gateway4: 192.168.56.1
version 2 

The above configuration works.

| improve this answer | |

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.