I have guest Ubuntu operating systems installed in Oracle VirtualBox. I'm using Ubuntu 10.04 as the host(base) operating system with static public IP addresses.

I can access the Internet on guest(VirtualBox) OS only if I select the NAT as network mode in VirtualBox settings and this is fine, but host(base) to guest(VirtualBox) networking is not working.

I want to connect my guest OS from host via ssh.

I need a step by step guide.

link|improve this question

62% accept rate
feedback

3 Answers

I wrote a HOWTO for Linux Journal regarding port forwarding within NAT in VirtualBox here: http://www.linuxjournal.com/content/tech-tip-port-forwarding-virtualbox-vboxmanage

Use the VBoxManage utility to forward an unused local port (like 2222) to port 22 of the virtual machine (assuming that you are using the default port on the VM), which will easily allow you to SSH into your virtual machine.

link|improve this answer
feedback

When you use NAT for your Guest instances, VirtualBox creates a separate "subnet" (10.x.x.x) within which the Guest instances operate. In order to access these instances, you need to set up Static Routes on the Host system. There are plenty of links / guides out there where people have done this.

Alternatively, you could use Bridged Networking instead of NAT. Bridged Networking will put the Guest instances in the same network as your Host operating system, thereby giving you direct access.

link|improve this answer
Maybe a link to one of the guides you've seen that is most clear on the topic? I've looked (not recently), but never found anything really great. – Nate Bross Sep 17 '10 at 15:36
No, I could only access the internet if I select NAT mode. If I select bridge, host to guest networking is possible but I couldn't access internet. – user53864 Sep 17 '10 at 16:26
feedback

The reason is that in NAT mode VirtualBox effectively provides routing of Internet traffic to and from the virtual machine, whereas in bridged mode you have to do this yourself. In other words, you need to set up your host computer as an Internet gateway (with forwarding and SNAT or masquerading). In bridged mode your guest behaves as if it were a completely separate computer on a LAN behind the firewall (or a completely separate computer on the internet, but that will require a separate static IP address), which is sort of the whole point of running a virtual machine.

Since you probably only have one static public IP address, you need to bind another (internal) IP address to the host OS, either on the same interface or on a different one, and then either allow the guest to acquire an IP address on the same internal subnet from a DHCP server or configure it statically that way. Then you set up iptables on the host to do forwarding from the external IP to the internal LAN, plus the relevant rules for SNAT/MASQUERADE, and all should be fine.

link|improve this answer
Could you instruct me how to do forwarding(SNAT or masquerading). – user53864 Sep 19 '10 at 13:38
How much do you know about iptables? – wolfgangsz Sep 19 '10 at 16:48
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.