Page 1 of 1

Can't have simultaneous access to the host and to the web

Posted: 24. Aug 2011, 10:03
by markstickley
Hi all,

I am experiencing a little problem. I can't seem to get a regular NAT interface and a host-only interface running simultaneously. Here is the contents of my /etc/network/interfaces:

Code: Select all

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

# The host-only network for host access to this VM
auto eth1
iface eth1 inet static
        address 192.168.100.101
        netmask 255.255.255.0
This will allow me to connect to the VM via the host but the VM cannot ping out to any external servers. Commenting out eth1 will obviously stop host access to the VM but it will also allow the VM access outside.

Here is my ifconfig:

Code: Select all

eth0      Link encap:Ethernet  HWaddr 08:00:27:99:1d:25  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe99:1d25/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11 errors:0 dropped:0 overruns:0 frame:0
          TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2232 (2.2 KB)  TX bytes:1864 (1.8 KB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:fa:14:8a  
          inet addr:192.168.100.101  Bcast:192.168.100.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fefa:148a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:156 errors:0 dropped:0 overruns:0 frame:0
          TX packets:76 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:18245 (18.2 KB)  TX bytes:9927 (9.9 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
Any ideas what I'm doing wrong? Thanks!

Re: Can't have simultaneous access to the host and to the web

Posted: 24. Aug 2011, 22:41
by Sasquatch
Well, that depends on what the IP address of the Host is. What you have configured on the Guest is an IP that is not usually used by Host-Only. It's default is 192.168.56.1 for the Host side. If the IP you configured for Host-Only is the same as your Host network range, then that is the cause for it to fail. The OS will use the shortest path possible to reach the destination. If the DNS is 192.168.100.1, then it will try to reach it through your Host-Only adapter, and fail. Thus never be able to reach the web through names.
Change the range and you will be able to get both going.

Re: Can't have simultaneous access to the host and to the web

Posted: 25. Aug 2011, 09:47
by markstickley
Oh that's interesting, I didn't know how that worked.

However, my host IP is in the 192.168.201.* range and the DNS is something completely different, not even starting with 192, according to my Network Prefs pane.

Obviously these things change depending on which network I am currently connected to but it isn't working for this current network so here is the current ifconfig output for the host:

Code: Select all

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
	options=3<RXCSUM,TXCSUM>
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
	inet 127.0.0.1 netmask 0xff000000 
	inet6 ::1 prefixlen 128 
	inet6 fdfc:4af8:58c5:40fc:60c:ceff:fee0:e28a prefixlen 128 
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	ether 04:0c:ce:e0:e2:8a 
	inet6 fe80::60c:ceff:fee0:e28a%en0 prefixlen 64 scopeid 0x4 
	inet 192.168.201.146 netmask 0xffffff00 broadcast 192.168.201.255
	media: autoselect
	status: active
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
	ether 06:0c:ce:e0:e2:8a 
	media: autoselect
	status: inactive
vboxnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	ether 0a:00:27:00:00:00 
	inet 192.168.100.100 netmask 0xffffff00 broadcast 192.168.100.255
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1380
	inet6 fe80::60c:ceff:fee0:e28a%utun0 prefixlen 64 scopeid 0x6 
	inet6 fd00:6587:52d7:f8e4:60c:ceff:fee0:e28a prefixlen 64
Thanks!

Re: Can't have simultaneous access to the host and to the web

Posted: 26. Aug 2011, 07:20
by BillG
If your host is on a network with a DHCP server (which the config suggests), why not use bridged networking rather than fiddling with NAT and Host Only? Then the guest will get a 192.168.201.x address from DHCP and work just like the host.

Re: Can't have simultaneous access to the host and to the web

Posted: 26. Aug 2011, 08:39
by markstickley
That certainly would be easier but it would mean that the guest would have an ever-changing IP address as I connect to several networks over the course of a week. Not that convenient for SSH and connecting via a browser... I'd be editing my hosts file the whole time! Unless there's a trick to that which I don't know of?

Re: Can't have simultaneous access to the host and to the web

Posted: 26. Aug 2011, 09:34
by BillG
That is true if you are connecting the host to networks with different IP schemes.

The two NIC method should work OK (unless the address you got from DHCP was actually 192.168.100.x). The host should use the host only adapter to reach the vm and the DHCP enabled NIC for everything else.

What does or does not work with both interfaces active? What does the ifconfig on the host look like then?

Re: Can't have simultaneous access to the host and to the web

Posted: 26. Aug 2011, 21:10
by Sasquatch
And do switch back the Host-Only setting to 192.168.56.1. The range 192.168.100.* is sometimes used by routers. Even though your network may not use it, another network you connect with might.

And if that doesn't work, do some network tests as described in the VirtualBox FAQ.

Re: Can't have simultaneous access to the host and to the web

Posted: 9. Sep 2011, 09:29
by markstickley
OK guys I've had a bit of a revelation - it seems to work on any network but I have to reboot the VM to make it realise. There's probably also a command I don't know of to restart networking but the real question is: Is there a way of getting it to work it out automatically?

Thanks!