Unable to access internet via NAT... NICs to blame?

Discussions related to using VirtualBox on Linux hosts.

Unable to access internet via NAT... NICs to blame?

Postby ralthor » 8. Mar 2020, 03:07

I have to connect to the internet from the VM, but cannot use bridged networking, because the physical NIC is limited to have only one IP address.

The software versions are: VirtualBox 5.2.34_Ubuntur133883 on an Ubuntu 18.04 dedicated server, without GUI.

The commands I used:

created two networks and related DHCP servers:

Code: Select all   Expand viewCollapse view
VBoxManage hostonlyif ipconfig vboxnet1 --ip 192.168.57.1
VBoxManage dhcpserver add --ifname vboxnet1 --ip 192.168.57.1 --netmask 255.255.255.0 --lowerip 192.168.57.10 --upperip 192.168.57.200

VBoxManage natnetwork add --netname natnet1 --network "10.10.10.0/24" --enable --dhcp on


then imported a worker, and assigned two networks to it:

Code: Select all   Expand viewCollapse view
VBoxManage import worker1.ova
VBoxManage modifyvm worker1 --nic1 hostonly --hostonlyadapter2 vboxnet1
VBoxManage modifyvm worker1 --nic2 natnetwork --nat-network1 natnet1


Unfortunately inside the VM, the second NIC has no IP:

Code: Select all   Expand viewCollapse view
VBoxManage startvm worker1 --type headless
ssh user@192.168.57.10
ifconfig -a


gives me this result (lo is removed):

Code: Select all   Expand viewCollapse view
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.57.10  netmask 255.255.255.0  broadcast 192.168.57.255
        inet6 fe80::a00:27ff:fe55:c1f6  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:55:c1:f6  txqueuelen 1000  (Ethernet)
        RX packets 53  bytes 7239 (7.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 55  bytes 8521 (8.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 08:00:27:3f:b6:21  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


I tried to set a manual IP address using ifconfig enp0s8 inet 10.10.10.4 netmask 255.255.255.0, though it does not connect.

The result for `VBoxManage list natnetworks`:

Code: Select all   Expand viewCollapse view
NetworkName:    natnet1
IP:             10.10.10.1
Network:        10.10.10.0/24
IPv6 Enabled:   No
IPv6 Prefix:    fd17:625c:f037:2::/64
DHCP Enabled:   Yes
Enabled:        Yes
loopback mappings (ipv4)
        127.0.0.1=2


The result for VBoxManage list dhcpservers:

Code: Select all   Expand viewCollapse view
NetworkName:    HostInterfaceNetworking-vboxnet1
IP:             192.168.57.1
NetworkMask:    255.255.255.0
lowerIPAddress: 192.168.57.10
upperIPAddress: 192.168.57.200
Enabled:        Yes

NetworkName:    natnet1
IP:             10.10.10.3
NetworkMask:    255.255.255.0
lowerIPAddress: 10.10.10.4
upperIPAddress: 10.10.10.254
Enabled:        Yes


I noticed that replacing the NIC configs make hostonly NIC unreachable. Therefore, did I make a mistake or there is an issue with NICs, and either way how to solve it?

Update:
In a windows host, I had the same experience with the same machine. However, when I set the first NIC to NAT, and the second to hostonly, NAT worked and hostonly is fixed by setting the address inside the machine. So, what to do on Linux host?
ralthor
 
Posts: 4
Joined: 8. Mar 2020, 02:55

Re: Unable to access internet via NAT... NICs to blame?

Postby scottgus1 » 8. Mar 2020, 16:14

The [code] tag into you posted seems correct. NAT-networks can have internet connection issues if the IP address range is changed after the NAT-network is used, due to the NAT-network's DHCP server not following the IP range change. But your NAT-network's DHCP server does seem to be set right.

ralthor wrote:In a windows host, I had the same experience with the same machine. However, when I set the first NIC to NAT, and the second to hostonly, NAT worked and hostonly is fixed by setting the address inside the machine.

Have you tried this same setup in the Linux guest?

ralthor wrote:VBoxManage import worker1.ova

You're importing a pre-built guest. What happens if you set up the networks as desired then do a fresh install of the OS instead of an import? (in my very limited experience trying to support Linux in the forum, I 'feel' that I have run across situations where a poster's Linux guest network cards held onto old IP address configuration data when the Virtualbox connection was changed and should have forced a new IP range configuration, for example NAT to Host-Only-to Bridged, etc. Pure bunkum and no supporting data, I know... Is there a 'force reset' or 'uninstall-reinstall-in-the-Device-Manager' thing similar to Windows that you could try in Linux?)

ralthor wrote:when I set the first NIC to NAT

ralthor wrote:VBoxManage natnetwork add

Can you please clarify, when you had success on the Windows host, were you using NAT or NAT network? These are two different forms of network, and under just about any circumstances, NAT always works to get internet into the guest. See Virtualbox Networks: In Pictures. NAT and Host-Only are the usual go-to for a not-Bridgeable host where full host LAN access is not needed. Additionally, though NAT network allows all guests in the NAT network to talk to each other, so does Host-Only, and a combination of NAT network and Host-Only would provide duplicate network paths between guests.
Human government is like that crazy uncle who hides a quarter in his fist behind his back, then asks you to guess which fist the quarter is in...
No matter which side you choose, Left or Right, both Sides are empty.
scottgus1
Volunteer
 
Posts: 6947
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Unable to access internet via NAT... NICs to blame?

Postby ralthor » 9. Mar 2020, 04:07

I exported the VM with working NICs to the Linux host: NIC1 was NAT and NIC2 was hostonly. In Windows host, it was "Host-Only Ethernet Adapter" which resisted to change in Linux, though changed after one-two minutes of running several modifyvm commands. I don't know if it was my fault to set it to hostonlyadapter1, because using hostonlyadapter2 worked:

Code: Select all   Expand viewCollapse view
VBoxManage modifyvm worker2 --nic2 hostonly --hostonlyadapter1 vboxnet1 # did not work
VBoxManage modifyvm worker2 --nic2 hostonly --hostonlyadapter2 vboxnet1 # worked


Therefore, I tested the same setup in the Linux host. It worked. NIC information is as follows:

Code: Select all   Expand viewCollapse view
NIC 1:           MAC: 080027115836, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 1 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 2:           MAC: 080027DE8DC6, Attachment: Host-only Interface 'vboxnet1', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none


What happens if you set up the networks as desired then do a fresh install of the OS instead of an import?

I am very new to the world of VirtualBox on Linux. My server has no GUI, and installing VBoxWeb was also unsuccessful. I think I also had the choice of using the console to create the VM. However, the easier way for me was to create VM on Windows.

(in my very limited experience trying to support Linux in the forum, I 'feel' that I have run across situations where a poster's Linux guest network cards held onto old IP address configuration data when the Virtualbox connection was changed and should have forced a new IP range configuration, for example NAT to Host-Only-to Bridged, etc. Pure bunkum and no supporting data, I know... Is there a 'force reset' or 'uninstall-reinstall-in-the-Device-Manager' thing similar to Windows that you could try in Linux?)

I read somewhere in the forum that it takes some minutes to take effect, fortunately, it did. It seems I was lucky it did not require such reset.

Can you please clarify, when you had success on the Windows host, were you using NAT or NAT network?

On the Window host I used NAT. I tested both, but NAT worked. I am confused about the difference between NAT and NAT network. First I thought the latter is used as internal network, but there is another network type with the same name! There is also no separate list command for NATs, they are listed with the same command as NAT networks.
ralthor
 
Posts: 4
Joined: 8. Mar 2020, 02:55


Return to VirtualBox on Linux Hosts

Who is online

Users browsing this forum: No registered users and 21 guests