host only network doesn't provide internet connection for vm

1

I have opened a vm with hostonly network as networking option on my desktop. I have assigned an appropriate static ip to the vm. I can establish an ssh connection to it from my desktop and I can also ping my desktop from the vm. However, I can not reach to outside network inside the vm.

command ifconfig vboxnet0 returns on the desktop:

vboxnet0  Link encap:Ethernet  HWaddr 0a:00:27:00:00:00  
inet addr:10.20.0.1  Bcast:10.20.0.255  Mask:255.255.255.0
inet6 addr: fe80::800:27ff:fe00:0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6132 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:0 (0.0 B)  TX bytes:328130 (328.1 KB)

on the vm, ifconfig eth0 command returns:

eth0      Link encap:Ethernet  HWaddr 08:00:27:a1:65:a1  
inet addr:10.20.0.10  Bcast:10.20.0.255  Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fea1:65a1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:161 errors:0 dropped:0 overruns:0 frame:0
TX packets:122 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:15459 (15.4 KB)  TX bytes:15973 (15.9 KB)

The ip of the vm is static. vboxnet0 is assigned as virtual NIC of this vm. Wht further configuration should I do to provide internet connection with vboxnet0? Any help is appreciated.

My desktop os: ubuntu 12.04

The vm os: ubuntu server 12.04

Virtualization tool : virtualbox 4.3.6 r91406

Shnkc

Posted 2014-01-16T14:24:40.293

Reputation: 111

Answers

1

That's the normal behavior of HostOnly. Only your host will be able to access your VM. If you want it to have internet access either use NAT or Bridge as Networking Option.

NAT will use your host computer as a relay to internet (but still in the 10.20.0.x range) and Bridge will make your VM part of your network like any other computer on the (probably) 192.168.x.x range.

Both solution will work, it's now up to you to choose what suit you best.

typositoire

Posted 2014-01-16T14:24:40.293

Reputation: 141

You don't have to choose. You can set up two adapters for the VM, and set one to be NAT while the other is host-only. – Kenster – 2014-01-16T18:47:57.907

1

AH but it can be done as I had the same question a few weeks ago. Here's how I did it

Give the guest OS a Host Only Adapter (default one is vboxnet0) and make sure vboxnet0 does dhcp.

Install squid proxy (sudo apt-get install squid3

Open the file /etc/squid3/squid.conf and make the following changes:

A. Find the line with "http_access deny all" and comment it out by placing a # at the beginning of the line.

B. Paste the following two lines into the file:

acl allcomputers src 192.168.56.0/255.255.255.0

http_access allow allcomputers

Restart the squid 3 service by running: sudo service squid3 restart

In the guest OS make sure dhcp is set for the network card

Open Internet Explorer's Internet Options, Go to the Connections Tab, Click on Lan Settings..., Check the box for Proxy Server and make the address 192.168.56.1 and the port 3128.

Internet works now on the guest and the guest can not see the local network.

user277244

Posted 2014-01-16T14:24:40.293

Reputation: 251

0

From the manual, p 98:

the virtual machines cannot talk to the world outside the host since they are not connected to a physical networking interface.

Jenny D

Posted 2014-01-16T14:24:40.293

Reputation: 520