I have enabled two adapters in my VirtualBox (running Ubuntu 12.10 Server Edition), with types as: Host-only and NAT.
My main motive is to be able to connect two VMs running on two different hosts (physical machines) on a port (say 22). I know the answer is Port Forwarding, but it is too confusing. Well I have tried with Bridged mode, there too from outside my machine it is not able to connect to the virtual machine.

Edit: Well I wouldn't suggest Bridged Network, as it takes up IP addresses from the network, hence would prefer a NAT-ing technique.

migrated from serverfault.com Mar 6 '14 at 5:34

This question came from our site for system and network administrators.

  • 2
    Host-Only is not what you want. You want NAT or Bridged mode. How you enable traffic from the Host to the Guest is up to you. It won't be easy without Port forwarding in NAT mode. Bridged mode means that the Guest will need an IP in the same subnet as the host machine. HTH. – NickW Mar 4 '14 at 12:45
  • @NickW: you are very right.....I'm currently trying to do that only, port forwarding with NAT.....but I'm not able to understand what IP/ports to specify in the rule? And also should I mention the rule in the VirtualBox network or in the host? Please help. – Tanny Mar 4 '14 at 17:50
  • Well, you say <host.ip>:<port> <-> <guest.ip>.<port> so your rule would be` maps to or something similar, you just forward the ports, you can even forward from a different port to port 22 internally, if you google search, for your host OS, there will be explanations on how to do it. – NickW Mar 4 '14 at 17:55

I figured out the solution after much headbanging (although I figured it out some while ago, replying a bit late). The solution is to use NAT technique with port forwarding. All you have to do is, in the network setting of the vms in VirtualBox add Port Forwarding rules. There are no restriction on the value of the ports and they could be anything as long as there are no conflicting ports and it is advisable not to use certain port numbers.

For setting the rules: Host IP is the IP of your main machine and Guest IP is the NAT IP of the VM. Any request coming to your host on that port would directly be redirected to the guest ip on the port you have mentioned.

NAT port forwarding table

Here the first IP refers to my host machine, i.e. the one on which the VirtualBox is installed. And the second IP refers to the guest machine, i.e. the one which I need to start the server or connect to.


I would advise you to use Bridged mode. This will make your VM having their own IP in same network as the physical host, and behave like any physical machine on same network. Make sure both networks (from each host VM) can connect, and firewall are open on VM to communicate.

  • 2
    Actually this method I want to keep it for the last......as in this method, it will actually eat up the IPs.....otherwise Bridged mode is pretty straight forward to implement. Thanks for replying – Tanny Mar 4 '14 at 17:51
  • 1
    Be careful when using Bridged mode in environments with augmented security policies: Since the bridge interface uses a different MAC and not the original one of the physical interface the host may be blocked from the network since the unknown MAC might be interpreted as an intruder to the network. – mschenk74 Jan 18 '15 at 18:30
  • @Tanny, "it will actually eat up the IPs" That doesn't actually mean anything. How do you eat up Internet Protocols (IPs). I think you mean IP addresses. IP means Internet Protocol, and there are only two current IPs: IPv4 and IPv6. – Ron Maupin Dec 10 '17 at 4:28
  • @RonMaupin Thank you for pointing that out, my good sir.. It was lazy from my part... I wish I could edit the comment now.. :) – Tanny Dec 13 '17 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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