Trouble with NAT

Discussions related to using VirtualBox on Windows hosts.
Post Reply
frankG1
Posts: 5
Joined: 3. Mar 2020, 18:40

Trouble with NAT

Post by frankG1 »

I'm using Virtual Box 6.0.16 on a Windows 10 Pro (1903) host. I have setup a few simple VMs with NAT, and can't get port forwarding to work at all (i.e. I use the GUI to set it up, but more-or-less equivalent to what is documented in Chapter 6, section 6.3 of the manual which shows how to do this by CLI).

On the windows side, the connection times out.

The error I get in vbox.log (for example with an Ubuntu 16.04.3-desktop-amd64 image clean install) is:

Code: Select all

00:00:03.480700 NAT: Failed to redirect TCP 127.0.0.1:2222 -> 0.0.0.0:22 (Unknown error)
A similar config on a macOS host shows

Code: Select all

00:00:00.589465 NAT: Set redirect TCP 127.0.0.1:2222 -> 0.0.0.0:22
I don't see port 2222 open via netstat on the Windows 10 host. I have tried setting explicit IP addresses for both src and dst of the port forward, and get the same unknown error.

What troubleshooting steps would you suggest?

Thanks.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Trouble with NAT

Post by mpack »

Why am I seeing 127.0.0.1 for the host? Why am I seeing 0.0.0.0 for the guest? What rule did you actually configure?
frankG1
Posts: 5
Joined: 3. Mar 2020, 18:40

Re: Trouble with NAT

Post by frankG1 »

I setup port forwarding for SSH in the gui. On the host side I used 127.0.0.1:2222. On the guest side I left the IP address blank (which is per the documentation -- if blank, vbox uses the IP address it assigns to the host), and port 22. This is so I can ssh into localhost port 2222, to ssh into the VM. These exact settings work fine on a macOS host, and do what I expect them to do.

I understand why you ask, and those values seem a little strange (at least the 0.0.0.0 does to me. I use local loopback as the source on a port forward from time to time in other contexts. It is for the host side of the forward, so the host will use it's local loopback. That is compliant with normal practice). The reason I care about exactly those settings is that vagrant uses that same set of values with VirtualBox guests. I have something that works fine on my mac, and not on Windows. In order to troubleshoot that, I took vagrant out of the equation. I went to a clean install of Ubuntu and followed docs for how to configure port forwarding in the VirtualBox GUI. I get the same error, and that is what I posted.

Note, I have also tried using both the guest and host local RFC1918 IP addresses instead of the 127.0.0.1 and blank, and I get the same error. Since 127.0.0.1 and 0.0.0.0 work fine on the mac, I don't think that is the issue.

EDIT: for documentation on the 0.0.0.0, or more precisely on leaving the IP address blank, see: www dot virtualbox dot org/manual/ch06.html#natforward (I'm not allowed to post URLs yet)
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

Re: Trouble with NAT

Post by scottgus1 »

Try removing the 127.0.0.1 from the port forwarding rule. Just use the 2222 and the 22. See what that does.

In my tests, I did not need to set the host IP address, just the incoming and outgoing port numbers.

FWIW in a working port-forwarding scheme on an ubuntu guest I have, the log does put 0.0.0.0 in for the IP address:
00:00:04.123414 NAT: Set redirect TCP 0.0.0.0:4000 -> 0.0.0.0:4000
I suspect the 0.0.0.0 in the log means "any IP address" in the 'IP address' parts of the port forwarding rule: enter no IP address, as in my rule, the log shows 0.0.0.0.

See Virtualbox Networks: In Pictures: NAT
frankG1
Posts: 5
Joined: 3. Mar 2020, 18:40

Re: Trouble with NAT

Post by frankG1 »

Yes, thanks. I tried that. Same error.

EDIT: more precisely, I see:

Code: Select all

00:00:05.896253 NAT: Failed to redirect TCP 0.0.0.0:2222 -> 0.0.0.0:22 (Unknown error)
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

Re: Trouble with NAT

Post by scottgus1 »

Please zip and post the guest's .vbox file, using the forum's Upload Attachment tab.
frankG1
Posts: 5
Joined: 3. Mar 2020, 18:40

Re: Trouble with NAT

Post by frankG1 »

.vbox file attached

EDIT: this is after making the change suggested by scottgus1. Otherwise you would see 127.0.0.1 on the host side of the NAT, which looks a little different in the .vbox file. Let me know if you need that.
Attachments
vbox.zip
(1.47 KiB) Downloaded 11 times
frankG1
Posts: 5
Joined: 3. Mar 2020, 18:40

Re: Trouble with NAT

Post by frankG1 »

@scottgus1, I'm tempted to build VirtualBox from source and walk through in a debugger. The build instructions make reference to VisualStudio 2010, which is almost a decade old. Do you have experience building VirtualBox in Windows 10? Is it really necessary to use such an old development environment? any pointers would be appreciated.

RE-EDIT: after looking into what it takes to build VirtualBox, rebuilding the code seems like a difficult task. The developer section of the community forum is moderated and I don't seem able to post over there. I'm willing to do the work to debug this, but I'm stuck on the tool chain needed. If anyone reads this and has any pointers to building the windows version of VirtualBox in a debug-capable environment, please reply or PM me.
fth0
Volunteer
Posts: 5690
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Trouble with NAT

Post by fth0 »

The VBox.log messages that you posted document the result of VirtualBox trying to create the TCP listener socket on the host (in slirp_add_redirect). Usually this happens when the TCP listener socket already exists (created by another application and/or another VirtualBox VM), but you seem to already have checked that using netstat.

There are some other similar cases like yours (to be found via https://www.google.com/search?q=site%3A ... edirect%22), and a similarity of the cases using Vagrant seem to be the DNS proxy settings.
Post Reply