No Internet with NAT and Host-only connections
No Internet with NAT and Host-only connections
Hi all,
I am running VirtualBox 6.1.30 on an Ubuntu 21.10 host. I want to create a set of four linux (ubuntu 18.04) VMs that have a private network among them and with the host, and at the same time to be able to connect to internet from any of the VMs.
I am testing with one Vm, and once I make it work, I will clone that (adapting IPs and hostnames, of course). I have configured this VM with two network adapters:
- a NAT based adapter, that gets its IP from dhcp
- a host-only adapter, with a specific network configured from Virtualbox in a different subnet to the host internet connection
Each of them works fine alone. With the NAT connection activated I have internet access, and with the host-only connection activated I can access from the host to the guest and viceversa. But, here comes the tricky part, when I am working with the NAT connection and I click the check to "plug the cable" in the host-only adapter, I inmediately lose internet access. The host-only connection works, but the NAT doesn't work any more. As soon as I de-select the "plug cable" checkbox, I get my internet connection back.
I will be happy to provide any additional data you may need. Any help will be much appreciated.
Thanks!
I am running VirtualBox 6.1.30 on an Ubuntu 21.10 host. I want to create a set of four linux (ubuntu 18.04) VMs that have a private network among them and with the host, and at the same time to be able to connect to internet from any of the VMs.
I am testing with one Vm, and once I make it work, I will clone that (adapting IPs and hostnames, of course). I have configured this VM with two network adapters:
- a NAT based adapter, that gets its IP from dhcp
- a host-only adapter, with a specific network configured from Virtualbox in a different subnet to the host internet connection
Each of them works fine alone. With the NAT connection activated I have internet access, and with the host-only connection activated I can access from the host to the guest and viceversa. But, here comes the tricky part, when I am working with the NAT connection and I click the check to "plug the cable" in the host-only adapter, I inmediately lose internet access. The host-only connection works, but the NAT doesn't work any more. As soon as I de-select the "plug cable" checkbox, I get my internet connection back.
I will be happy to provide any additional data you may need. Any help will be much appreciated.
Thanks!
-
- Site Moderator
- Posts: 20945
- Joined: 30. Dec 2009, 20:14
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Windows, Linux
Re: No Internet with NAT and Host-only connections
We'd need to know what you're adapting; Also if you changed the MAC addresses on the clones.Luirl wrote:adapting IPs
Please give us an 'ip address' from the host and each VM. Also, please zip and post all the .vbox files from the VMs.
And please run 'vboxmanage list hostonlyifs' on the host terminal; post the command output.
-
- Volunteer
- Posts: 5677
- Joined: 14. Feb 2019, 03:06
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Linux, Windows 10, ...
- Location: Germany
Re: No Internet with NAT and Host-only connections
I'd suggest to check the routing table (ip r) inside the guest OS for the default route(s).
Re: No Internet with NAT and Host-only connections
Thank you very much scottgus1 and fth0.
Here is all the information I compiled.
First of all, so far I am only working with one guest. The ip address output in that guest is:
and the routing table is:
Networking in the VM is controlled by netplan, and the config file for netplan is:
where I leave the NAT connection to get an IP from dhcp, while I set an static IP for the Host-only connection. This is what I mentioned in my first post that I will need to adapt if I ever clone this VM to have several replicas forming a cluster (besides the MAC address and the hostname).
In the host, this is the output of the "ip address" command:
I have also attached the zip file with all the logs of my VM.
Thanks in advance for your time and help.
Here is all the information I compiled.
First of all, so far I am only working with one guest. The ip address output in that guest is:
Code: Select all
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:69:92:53 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3
valid_lft 86324sec preferred_lft 86324sec
inet6 fe80::a00:27ff:fe69:9253/64 scope link
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:95:47:5d brd ff:ff:ff:ff:ff:ff
inet 192.168.57.11/24 brd 192.168.57.255 scope global enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe95:475d/64 scope link
valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:68:28:e3:35 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
Code: Select all
default via 192.168.57.1 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
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
192.168.57.0/24 dev enp0s8 proto kernel scope link src 192.168.57.11
Code: Select all
# 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
enp0s8:
dhcp4: no
addresses: [192.168.57.11/24]
gateway4: 192.168.57.1
In the host, this is the output of the "ip address" command:
Code: Select all
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
link/ether c8:d3:ff:ec:f1:51 brd ff:ff:ff:ff:ff:ff
altname enp5s0
3: wlo1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether c8:21:58:59:b0:5f brd ff:ff:ff:ff:ff:ff
altname wlp4s0
inet 192.168.1.124/24 brd 192.168.1.255 scope global dynamic noprefixroute wlo1
valid_lft 86036sec preferred_lft 86036sec
inet6 fe80::cb2f:3160:47b0:a947/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:e0:16:4b:83 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
5: br-c37315971e30: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:0a:0c:93:28 brd ff:ff:ff:ff:ff:ff
inet 172.18.0.1/16 brd 172.18.255.255 scope global br-c37315971e30
valid_lft forever preferred_lft forever
6: br-ff242f13be4f: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:6c:3f:ae:4b brd ff:ff:ff:ff:ff:ff
inet 192.168.49.1/24 brd 192.168.49.255 scope global br-ff242f13be4f
valid_lft forever preferred_lft forever
7: vboxnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 0a:00:27:00:00:00 brd ff:ff:ff:ff:ff:ff
inet 192.168.57.1/24 brd 192.168.57.255 scope global vboxnet0
valid_lft forever preferred_lft forever
inet6 fe80::800:27ff:fe00:0/64 scope link
valid_lft forever preferred_lft forever
Thanks in advance for your time and help.
- Attachments
-
- VBox.zip
- (117.93 KiB) Downloaded 14 times
Re: No Internet with NAT and Host-only connections
Looks like I solved it!!
fth0 was right, and it was related to a faulty routing table. There were too many routes, ones overlapping with others. I finally simplified it to:
For some reason I dont know (I am learning about routing tables as I try to solve this), the gateway 192.168.57.1 I had configured for the device enp0s8 appears as 0.0.0.0 in the routing table, but that is another issue...and it works.
fth0 was right, and it was related to a faulty routing table. There were too many routes, ones overlapping with others. I finally simplified it to:
Code: Select all
Destino Pasarela Genmask Indic Métric Ref Uso Interfaz
0.0.0.0 10.0.2.2 0.0.0.0 UG 100 0 0 enp0s3
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.57.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s8
-
- Volunteer
- Posts: 5677
- Joined: 14. Feb 2019, 03:06
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Linux, Windows 10, ...
- Location: Germany
Re: No Internet with NAT and Host-only connections
When there are multiple routes to a Destination network (e.g. 0.0.0.0/0), the Metric comes into play. The meaning of "no metric" (in the output of ip route) depends on the Linux distribution and its networking stack, but often it's interpreted as (the highest) metric 0, that's why your host-only adapter got the Internet traffic.
In the output of route -n, the Gateway column only makes sense for routes where the Destination is outside of the Interface's network, that's why it's displayed as 0.0.0.0.
In the output of route -n, the Gateway column only makes sense for routes where the Destination is outside of the Interface's network, that's why it's displayed as 0.0.0.0.
Re: No Internet with NAT and Host-only connections
Thank you very much fth0!!
I thought my problem was solved, but after a restart of the VM, the routes table looked like this:
New entries for the 0.0.0.0 destinations have appeared, and so again the "Host-only" network was "over" the NAT network, hence losing internet connection If I manually delete the first entry, everything works fine. To be honest, I am not sure if this is something done by Virtualbox or by ubuntu. After reading a post in the askubuntu forum (that I cannot paste by now) and following your explanation about the metrics I modified the content of my netplan configuration file as:
trying to assign the NAT interface a lower metric than the Host-only interface, but this only resulted in the following strange routing table after a VM restart:
With the routes that I forced through the netplan config, but ALSO the one establishing the Host-only interface the default interface for any network appearing again. Is there a way I could prevent the first line from being generated, or make it have a lower priority than the enp0s3 line?
I thought my problem was solved, but after a restart of the VM, the routes table looked like this:
Code: Select all
Destino Pasarela Genmask Indic Métric Ref Uso Interfaz
0.0.0.0 192.168.57.1 0.0.0.0 UG 0 0 0 enp0s8
0.0.0.0 10.0.2.2 0.0.0.0 UG 100 0 0 enp0s3
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s3
10.0.2.2 0.0.0.0 255.255.255.255 UH 100 0 0 enp0s3
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.57.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s8
Code: Select all
# 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
dhcp4-overrides: {route-metric: 0}
enp0s8:
dhcp4: no
addresses: [192.168.57.12/24]
routes:
- to: 0.0.0.0/0
via: 192.168.57.1
metric: 100
gateway4: 192.168.57.1
Code: Select all
Destino Pasarela Genmask Indic Métric Ref Uso Interfaz
0.0.0.0 192.168.57.1 0.0.0.0 UG 0 0 0 enp0s8
0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 enp0s3
0.0.0.0 192.168.57.1 0.0.0.0 UG 100 0 0 enp0s8
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s3
10.0.2.2 0.0.0.0 255.255.255.255 UH 0 0 0 enp0s3
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.57.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s8
-
- Volunteer
- Posts: 5677
- Joined: 14. Feb 2019, 03:06
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Linux, Windows 10, ...
- Location: Germany
Re: No Internet with NAT and Host-only connections
In my own Linux Mint (Ubuntu-derived) setups, the VirtualBox host-only adapter uses the VirtualBox DHCP server, and no default route is created by the Linux guest OS.
I think that you get the default route because you've specified a gateway, which would only make sense if you wanted to provide routing functionality on your host for that network. Why did you specify a gateway?
I think that you get the default route because you've specified a gateway, which would only make sense if you wanted to provide routing functionality on your host for that network. Why did you specify a gateway?
Re: No Internet with NAT and Host-only connections
You're absolutely right fth0!!!! No gateway, no default route in the route table!
Thanks, you saved my end of year
Happy 2022!!
Thanks, you saved my end of year
Happy 2022!!
-
- Volunteer
- Posts: 5677
- Joined: 14. Feb 2019, 03:06
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Linux, Windows 10, ...
- Location: Germany
Re: No Internet with NAT and Host-only connections
You're welcome, and a happy new year for you, too!