8

VirtualBox Port Forwarding on Windows 7 not Working

Im trying to ssh onto my VirtualBox from my Windows 7 host via port forwarding, but VirtualBox wont open the port for listening. I can connect to it by turning on the VirtualBox GUI and navigating via that terminal, but I cannot connect via a standard ssh client from my host. I want to be able to ssh on port 2222 on my host to the guest.

Here's my setup:

Host: Window 7 SP1
Guest: Ubunto Ubuntu 12.04
VirutalBox: 4.3.26
Host Processor: Intel Core i7 920

The guest machine is configured as a NAT and port forwarding is enabled for 127.0.0.1 for host port 2222 to guest port 22.

The output from ifconfig on the guest:

eth0    inet addr:10.0.2.15 Bcast:10.0.2.255 Mask: 255.255.255.0

The output from ps -ef | grep sshd on the guest:

root    625 1   0   12:27   ?   00:00:00    /usr/sbin/sshd -D

The output from netstat -ant | grep 22 on the guest:

tcp     0   0   0.0.0.0:22  0.0.0.0:*
tcp6    0   0   :::22       :::*

But on the host, netstat -ant | grep 2222 doesnt show anything.

In the VBox.log however I have this:

00:00:03.413790 NAT: set redirect TCP host 127.0.0.1:2222 => guest 10.0.2.15:22
00:00:03.424301 supR3HardenedErrorV: supR3HardenedScreenImage/LdrLoadDll: rc=VERR_LDRVI_UNSUPPORTED_ARCH fImage=1 fProtect=0x0 fAccess=0x0 \Device\HarddiskVolume2\Windows\mfnspstd64.dll: WinVerifyTrust failed with hrc=Unknown Status 0x800B0101 on '\Device\HarddiskVolume2\Windows\mfnspstd64.dll'
00:00:03.424422 supR3HardenedErrorV: supR3HardenedMonitor_LdrLoadDll: rejecting 'C:\Windows\mfnspstd64.dll' (C:\Windows\mfnspstd64.dll): rcNt=0xc0000190
00:00:03.424476 NAT: failed to redirect TCP 127.0.0.1:2222 => 10.0.2.15:22

The last line looks like the suspect but there's no clue as to why it fails to redirect. I've tried all of the following from various other posts and forums but cant get it to listen on any port on the host:

  • Turned off the firewall
  • Changed the port
  • Enabled VT-X on BIOS
  • Disabled Hyper-V
  • Tried numerous different builds of VirtualBox

Any help would be much appreciated. Works fine on my Mac Book with OS-X.

Sparm
  • 403
  • 1
  • 6
  • 10

3 Answers3

2

Did you set forwarding in machine settings ?

  1. To forward ports in VirtualBox, first open a virtual machine’s settings window by selecting the Settings option in the menu.

  2. Select the Network pane in the virtual machine’s configuration window, expand the Advanced section, and click the Port Forwarding button. Note that this button is only active if you’re using a NAT network type – you only need to forward ports if you’re using a NAT.

  3. Use VirtualBox’s Port Forwarding Rules window to forward ports. You don’t have to specify any IP addresses – those two fields are optional.

Also here: http://www.howtogeek.com/122641/how-to-forward-ports-to-a-virtual-machine-and-use-it-as-a-server/

Crowlex
  • 101
  • 7
  • 3
    Yup port forwarding is enabled on my instance. Ill update my question – Sparm Apr 22 '15 at 09:05
  • Try to disable firewall. If I remember correct `sudo ufw disable` or `sudo service iptables stop` – Crowlex Apr 23 '15 at 10:30
  • 4
    As mentioned in my question, I have already tried turning off firewall – Sparm Apr 23 '15 at 11:04
  • what about windows firewall or workgroup ? Try to check all steps again may be you will find what you did wrong. 1)Set 1 Host Only Adapter & 1 NAT adapter 2)Enable Virtual Box Network Adapter in your Host Machine. 3)Ping both Host and the Guest and ensure both are connected. 4)Now Create Port Forwarding on the Host Only Adapter. – Crowlex Apr 23 '15 at 20:36
  • Port forwarding configured for the guest VM will be enabled automatically when you power on the guest VM. For verification, check that port 2222 is opened by VirtualBox after you launch the guest VM [How to access a NAT guest from host with VirtualBox](http://ask.xmodulo.com/access-nat-guest-from-host-virtualbox.html) – Crowlex Apr 23 '15 at 20:37
  • 2
    Again, as stated in the original question, I am checking the host to see if 2222 is open by running **netstat -ant | grep 2222** (as also stated in the link you provided) and the port isnt opened. The startup log for in **VBox.log** states "failed to redirect TCP 127.0.0.1:2222 => 10.0.2.15:22" – Sparm Apr 27 '15 at 10:56
0

I used this article to ssh into my Raspberry pi3 VM.

Using this command ssh -p 2222 pi@localhost.

Originally, I had kept trying to use ssh pi@10.0.2.x -p 2222, but it didn't work and kept returning a "Connection timed out." My port number is 2222, but yours could be different depending what you set in your VirtualBox.

I am using a Windows 10 into a Debian Raspberry Pi VM (VirtualBox).

robsiemb
  • 4,959
  • 7
  • 24
  • 33
0

I found the solution in a hypernode-vagrant issue: VirtualBox fails to establish the port forwarding for SSH on Vagrant's standard port 2222, but higher ports work. In that issue, ports >= 4000 worked, whereas ports <= 3500 would fail. On my machine running Windows 10, I found 2380 to be the first port for which the TCP redirect can be established.

The port on the host used for forwarding can be changed by adding the following lines to your Vagrantfile (where you may have to replace 4000 by a higher number):

config.vm.network :forwarded_port, guest: 22, host: 2222, disabled: true
config.vm.network :forwarded_port, guest: 22, host: 4000, id: "ssh"

I have no idea what the root cause for this behavior could look like, but the workaround has been working reliably so far.

Fabian Meumertzheim
  • 1,432
  • 1
  • 11
  • 21