Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VirtualBox port forwarding not working with NAT adapter

I'm trying simple port forwarding with VirtualBox and it appears VirtualBox.exe is listening on the host to the port, but not actually forwarding the connection to the guest. I've tried on multiple ports, and I've restarted VirtualBox several times. Guest to host connectivity, on the other hand, is fine. Here's the info:

Host: Win7 x64 Guest: Win7 x64 VirtualBox version: VirtualBox 4.2.10 Firewalls: All firewalls on host and guest disabled.  Virtual Box > Machine Settings > Network  Adapter 1:    Attached to: NAT   Cable Connected : True   Port Forwarding:    Rule 1: TCP, HostIP=127.0.0.1, HostPort=8081, GuestIP=127.0.0.1, GuestPort=8081  On Host: [VirtualBox.exe]  TCP    127.0.0.1:8081         IBM-6KT5OPCF76P:0      LISTENING  On Guest: I never get the connection request on port 8081 or any others I've tried. 

Any ideas? I'd like to avoid using VirtualBox's bridged adapter for multiple reasons. I was under the impression that NAT port forwarding was relatively straightforward with VirtualBox.

Thanks!

like image 981
Roberto Olivares Avatar asked Mar 22 '13 21:03

Roberto Olivares


People also ask

How do I enable NAT Network in VirtualBox?

Open VirtualBox Preferences (File -> Preferences) and go to Network Tab. Click on the + icon on right side (Adds new NAT network). It will create a new NAT Network without asking any questions. You can also add Port Forwarding for accessing VM (over ssh or http kind of protocols).

What is NAT adapter in VirtualBox?

Network Address Translation (NAT) is the simplest way of accessing an external network from a virtual machine. Usually, it does not require any configuration on the host network and guest system. For this reason, it is the default networking mode in Oracle VM VirtualBox.

How do I enable port forwarding on my Virtual Machine?

To enable port forwarding, open the settings for your Virtual Machine. Verify that NAT is selected in the Attached to: selector. At the bottom of the window, click on the Port Forwarding button. You are then presented with a form where you can add new forwardings.

What network adapter should I use for VirtualBox?

Oracle's documentation suggests the best way to get optimal network performance is to use the Paravirtualized Network (virtio-net) adapter type. By default, if you use the out-of-the-box settings, VirtualBox uses an emulated Intel PRO/1000 MT adapter for Windows VMs.


2 Answers

Paravirtualized Network* (virtio-net) is the key

  1. select your vm that you want for port forwarding.

    • NOTE: Make sure the vm is in stop mode.
  2. Select “Settings"

  3. Select “Network"
  4. Select any free Adapter. Lets say "Adapter 2"
  5. Enable "Enable Network Adapter"
  6. In Attached to dropdown, select "NAT"
  7. Select "Advanced"
  8. In Adapter Type: Select “Paravirtualized Network (virtio-net)” [ This is important ]
  9. Select “Port Forwarding"
  10. In Right hand part of the “port forwarding” dialog box, select “+"
  11. Provide the

    • Name: Anything you want. example for ssh, say “ssh"
    • Protocol: Type of protocol [ for ssh: TCP ]
    • Host IP: provide hostname from which host you want to connect to [ over here: 127.0.0.1 ]
    • Host Port: On what port of that Host you want to connect to remote port [ example: 60022 ]
    • Guest IP: Leave it Blank
    • Guest Port: To what port you want to connect from the above host. [ for ssh, the default 22 ]
like image 176
Amit Avatar answered Oct 18 '22 08:10

Amit


You've pointed guest ip in wrong manner it should be ip of guest (if you're statically assign ip address to guest) or leave it empty. Note you're pointed host ip as 127.0.0.1 it means that port you're forwarding will be accessible only from port (if it isn't what you're desired it should be empty as well).

VBoxManage modifyvm "win" --natpf1 ",tcp,,8081,,8081" 

perhaps this is something you've wanted to do. (please look here for more details)

like image 35
vvlevchenko Avatar answered Oct 18 '22 07:10

vvlevchenko