Tuesday, June 9, 2009

using bridge networking on VirtualBox

I wanted to run Ubuntu as a guest on my Windows and I need to access ubuntu's web server (LAMP) from my Windows...

NAT does not work, and surprisingly Host-only mode does not either... i don't know why.. it should be simple a bug or something wrong on my side..

anyway it is a long and tedious process.... with lots of reboots of my ubuntu


now the steps to do it:

1) select Bridge adapter and choose an ACTIVE network card, and for my case it is my wireless nic

Note: This simple step is the cause of my frustrations... I choose my Ethernet nic but it is not active because Windows does not detect a cable - one of the many limitations of windows - and I go on to install TAP-Win32, after reading articles like http://samiux.wordpress.com/2007/07/11/bridge-network-interface-on-virtualbox/




2) take note of the ip setting of the active nic that u have chosen, and let's say it is 192.168.100.1/24

3) Boot Ubuntu and edit /etc/network/interface to be:

fs@ubuntu:~$ more /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.100.4
netmask 255.255.255.0
gateway 192.168.100.1


Here I choose 192.168.100.4, it can be anything, as long as it does not conflict with the active nic in step 1 or other ip in the network... u must be careful if your network is big with many machines.



That's it, reboot Ubuntu and u should be able to ping to it from Windows.


fook sheng

9 comments:

Sylvain said...

Thanks for your help !

It was very usefull... keep that way !

Whatdoesitwant said...

Hey, thank you so much for figuring this out. I am new to linux, trying to create exactly this. I'm working from 9.04 on virtualbox. I couldn't start or get apt vim but nano worked. However, at the last bit, i do not understand your bash command (fs@ubuntu) At this point my terminal is still at user@VirtualBox:-$. Could I not simply use nano here as well to edit the interfaces file according to your suggestion?

Fook Sheng said...

hi Willem

you said .... "However, at the last bit, i do not understand your bash command (fs@ubuntu)"

just ignore fs@ubuntu the actual command is :

more /etc/network/interfaces

and yes, u can use any text editor to edit the files, good luck :)

Whatdoesitwant said...

Hi Fook,

Again thank you very much for this solution. I at least got the server to be recognized from the host with the new static ip settings (after an edit in my router (-:). However, this lost me the internet connection from the guest. I am guessing that I either need to set the router as a dns somewhere or there is some more bridging involved. But I'm not smart enough to do these things in Ubuntu.

Anyway, it appears to me that the address that is supplied to the virtualbox in bridged mode by default through dhcp is always the same, thus behaving like a static address and allowing me to call the virtualbox server from the host anyway whilst keeping internet within the virtualbox available. Ofcourse I'll have to think of that whenever I port the virtualbox environment to another system but for now this is acceptable.

Fook Sheng said...

Hi Willem

If your host is using dhcp, and it can connect to the internet, then your guest should use dhcp after you have configured it to use bridge networking. Your guest would be just like another machine on your normal network, just like your host machine.

Just imagine your guest to be another real machine attached yo your network. This is the crucial point.

cheers :)

Anonymous said...

Didn't work. :)

Cheers.

Anonymous said...

Worked for me :-)
Using Windows 7 as host and Ubuntu as guest on VirtualBox 3.1.2
Followed following steps

1. Set Bridge Adapter in "Attached To"

2. Set active network adapter of host computer in "Name" drop down box.

3. Edit /etc/network/interfaces as said.

4. Run following two commands
sudo iptables -t mangle -A PREROUTING -i ppp0 -j TTL --ttl-inc 1


sudo iptables -t mangle -A POSTROUTING -j TTL --ttl-set 64

I got these two comands from https://help.ubuntu.com/community/VirtualBox/Networking

5. Restart Guest

6. Be happy !!!!

Thanks

Unknown said...

It worked beautifully, man!

Thanks a lot.

Gaurav said...

I did the same,and was able to ping my guest (ubuntu) from windows but not the other way round.

So my host is not accessible from the guest OS