Archive for the ‘VirtualBox’ Category

Internet access in Virtualbox Host-only networking

February 13, 2012 11 comments



SITUATION: After enabling host-only networking mode for a VM in virtualbox, from inside the vps I am unable to ping the default router of host or connect to internet for installing packages.
In bridge mode it was working fine. The details of host and guest vm is provided below,


Host Details:

Main IP 				: 	--> eth0
Gateway IP				:
Virtual Interface(Created by Virtualbox): 	--> vboxnet0	
DNS					:
OS					: Ubuntu 11.04


Guest VM Details:

IP					:
Gateway					:
Network					:
DNS					:
Networking Mode				: Host-only networking
OS					: Ubuntu 10.10


From inside the vm, I am able to ping the IP addresses of host( and virtual interface( But I am unable to ping to the default gateway( from inside vm. So, I wasn’t able to install additional packages in that vm.




SOLUTION: Configure packet forwarding from interface “vboxnet0” to “eth0”. Follow the steps mentioned below,


1) Add the following iptable rules from host machine’s command line

iptables -A FORWARD -o eth0 -i vboxnet0 -s -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE


2) Install dnsmasq in host and start it. dnsmasq is a small caching DNS proxy and DHCP/TFTP server.

 apt-get install dnsmasq
 /etc/init.d/dnsmasq start


3) Set the nameserver in guest vm to host server ip

root@heuristics3:~# cat /etc/resolv.conf 


4) Add the following entries in /etc/sysctl.conf of host and run “sysctl -p” in host command line.

net.ipv4.ip_forward = 1
net.ipv4.conf.all.proxy_arp = 1


That’s all:)







Categories: VirtualBox