Home > VirtualBox > Internet access in Virtualbox Host-only networking

Internet access in Virtualbox Host-only networking

 

 

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 				: 192.168.1.3 	--> eth0
Gateway IP				: 192.168.1.3
Virtual Interface(Created by Virtualbox): 192.168.56.1 	--> vboxnet0	
DNS					: 192.168.1.1
OS					: Ubuntu 11.04

 

Guest VM Details:

IP					: 192.168.56.101
Gateway					: 192.168.56.1
Network					: 192.168.56.0/24
DNS					: 192.168.1.3
Networking Mode				: Host-only networking
OS					: Ubuntu 10.10

 

From inside the vm, I am able to ping the IP addresses of host(192.168.1.3) and virtual interface(192.168.56.1). But I am unable to ping to the default gateway(192.168.1.1) 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 192.168.56.0/24 -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 
nameserver 192.168.1.3
root@heuristics3:~# 

 

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:)

 

 

Ref:

 

http://www.cyberciti.biz/faq/caching-dns-server/

http://serverfault.com/questions/127636/force-local-ip-traffic-to-an-external-interface

http://ilconnettivo.wordpress.com/2011/02/20/virtualbox-4-nat-bridged-networking/

 

 

 

About these ads
Categories: VirtualBox
  1. tolaris
    May 16, 2012 at 9:30 pm | #1

    Why is proxy arp required?

    • Ken
      August 3, 2012 at 2:27 am | #2

      In this case, it may not be required. It is typically used to build a DMZ (I think). I’ll see if I can research a little more.

  2. July 4, 2012 at 3:03 pm | #3

    not working for me(

  3. Ken
    August 2, 2012 at 3:17 am | #4

    This worked great thanks much.
    How do I port forward to the VM through this setup?

    • August 2, 2012 at 11:40 am | #5

      Ken, try:

      iptables -t nat -A PREROUTING -p tcp -m multiport –dports 8000 -j DNAT –to-destination 192.168.56.101:80

      This will forward your PC’s port 8000 to the VM’s port 80. You can also forward multiple ports as long as they are sequential, in one rule:

      iptables -t nat -A PREROUTING -p tcp -m multiport –dports 8000:9000 -j DNAT –to-destination 192.168.56.101:80-1080

      • Ken
        August 3, 2012 at 2:25 am | #6

        Thanks. I will give it a shot and let you know what happens.

  4. July 19, 2013 at 12:45 pm | #7

    Hi, after reading this awesome piece of writing i
    am as well delighted to share my know-how here with mates.

  5. Martin
    July 21, 2013 at 3:00 pm | #8

    Thnx, this was one of the first hits when looking for access to the internet from within a virtual server. Easy to follow and suddenly apt-get update worked ;-)

  6. this neither
    September 6, 2013 at 6:27 pm | #9

    Works like charm. Thank you so much!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: