Page 1 of 1

Internet Connectivity Issue (NAT mode)

Posted: 11. Jun 2012, 01:22
by salman
Hi All,

I am running a ubuntu guest on top of windows 7 host. My guest has an interface connected in NAT mode and I was able to access internet on the guest in this configuration until after I changed the default NAT network address from 10.0.0.0/24 to 192.168.0.0/16.

Here is my ifconfig eth0 (in NAT mode) output:

Code: Select all

eth0      Link encap:Ethernet  HWaddr 08:00:27:16:d5:09  
          inet addr:192.168.0.15  Bcast:192.168.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9 errors:0 dropped:0 overruns:0 frame:0
          TX packets:234 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2736 (2.7 KB)  TX bytes:25339 (25.3 KB)
Here is the output of route -n:

Code: Select all

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.2     0.0.0.0         UG    0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
Here are the contents of /etc/resolv.conf:

Code: Select all

nameserver 192.168.0.1
(I changed it from 192.168.1.1 to 192.168.0.1 in hope that it may work bu I am unable to ping this DNS)

Kindly guide me on what to do ?

Thank!

Re: Internet Connectivity Issue (NAT mode)

Posted: 11. Jun 2012, 03:17
by martyscholes
It looks to me like your guest subnet may overlap with your host subnet.

The netmask tells the network stack which addresses to send to the LAN and which ones to forward to the gateway. On the host, the LAN is the LAN itself. On the guest, the LAN is the a fake LAN set up by VirtualBox. By way of example, my actual host has an address of 192.168.223.9/24 with a gateway of 192.168.223.1. The host's IP stack will do the following when sending an IP packet. If destination address is between 192.168.223.1 and 192.168.223.254, send to actual LAN, otherwise, send to 192.168.223.1 (the gateway) to forward the packet.

When I look at a virtual machine running Linux Mint on a NAT interface, it has the following information:

Code: Select all

marty@marty-VirtualBox ~ $ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 08:00:27:ee:a1:8e  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:feee:a18e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:53 errors:0 dropped:0 overruns:0 frame:0
          TX packets:134 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:27337 (27.3 KB)  TX bytes:17300 (17.3 KB)

marty@marty-VirtualBox ~ $ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.0.2.2        0.0.0.0         UG        0 0          0 eth0
10.0.2.0        0.0.0.0         255.255.255.0   U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
That means that the guest sits on a fake LAN created by VirtualBox with the address of 10.0.2.15/24 with a fake gateway of 10.0.2.2. If the guest sends to any address between 10.0.2.1 and 10.0.2.254, it will go out to the fake LAN. Any other address will go to the fake gateway and get forwarded by VirtualBox on the host.

In your example, your guest has an address of 192.168.0.0/16 with a gateway of 192.168.0.2. I am guessing that the fake gateway provided by VirtualBox is at a different address. Worse, your real LAN probably overlaps with the fake LAN. This means that none of your packets will get forwarded between the real and fake LAN.

The best thing to do is to go back to the addresses from VirtualBox, or used a bridged adapter.

I hope that makes sense,
Marty

Re: Internet Connectivity Issue (NAT mode)

Posted: 11. Jun 2012, 04:27
by salman
Hi Marty,

Thanks for the reply. I believe when I do a NAT my guest network is hidden from the host network. So how can the overlap take place? (Correct me if I am wrong?)
Also, is there something wrong with my gateway setting ? I set it to 192.168.0.2 because the documentation (http://www.virtualbox.org/manual/ch09.html#changenat) says so. I understand that any packet that is not destined to the 192.168/16 network would be thrown to this gateway but I don't understand what problem are you trying to point out with my gateway ?

Also, I changed my nameserver to 192.168.0.3 (which I am able to ping ! ) but still no access to internet. Furthermore, whenever I acquire an IP using 'dhclient eth0' my /etc/resolv.conf is restored with 192.168.1.1.

Please note that I don't want to revert to 10.0.0.0 subnet because I am running an application within the VM that simulates that subnet and I have little control over the application

Thanks again for your help.

Any other ideas please?

Re: Internet Connectivity Issue (NAT mode)

Posted: 11. Jun 2012, 04:37
by martyscholes
What is the subnet of your LAN?

Re: Internet Connectivity Issue (NAT mode)

Posted: 11. Jun 2012, 04:54
by salman
host lan is : 192.168.1.0/24

Re: Internet Connectivity Issue (NAT mode)

Posted: 11. Jun 2012, 14:51
by martyscholes
I can't make sense of that. If your host LAN is 192.168.1.0/24 and your VirtualBox NAT LAN is 192.168.0.0/16, then nothing from the NAT LAN should be routed to the host LAN. Nothing at all should get through.

It's early, and I could be wrong.