VirtualBox Port Forward not working when Guest IP *IS* specified (while doc says opposite)

Posted by Patrick on Super User See other posts from Super User or by Patrick
Published on 2014-06-10T20:42:45Z Indexed on 2014/06/10 21:30 UTC
Read the original article Hit count: 184

Trying to port forward from host (Mac OS X) 127.0.0.1:8282 -> guest (CentOS)'s 10.10.10.10:8080. Existing port forwards include 127.0.0.1:8181 and 9191 to guest without any IP specified (so whatever it gets through DHCP, as explained in the documentation).

Here is how the non-working binding was added:

VBoxManage modifyvm "VM name" --natpf1 "rule3,tcp,127.0.0.1,8282,10.10.10.10,8080"

Here is how the working ones were added:

VBoxManage modifyvm "VM name" --natpf1 "rule1,tcp,127.0.0.1,8181,,80"
VBoxManage modifyvm "VM name" --natpf1 "rule2,tcp,127.0.0.1,9191,,9090"

And by "non-working", I of course mean not listening (as a prerequisite to forwarding):

$ lsof -Pi -n|grep Virtual|grep LISTEN
VirtualBo 27050 user   21u  IPv4 0x2bbdc68fd363175d      0t0  TCP 127.0.0.1:9191 (LISTEN)
VirtualBo 27050 user   22u  IPv4 0x2bbdc68fd0e0af75      0t0  TCP 127.0.0.1:8181 (LISTEN)

There should be a similar line above but with 127.0.0.1:8282.

Just to be clear, this port is listening perfectly fine on the guest itself. And when I remove the guest IP (i.e., clear the 10.10.10.10) the forward works fine, albeit to eth0 (not eth1 where I need it). I can tcpdump and watch the traffic flow back and forth. And yes, I've disabled iptables entirely while testing -- it's not getting blocked anywhere on the guest.

As VirtualBox writes in their documentation, you are required to specify the guest IP if it's static (makes sense, no DHCP record it keeps): "If for some reason the guest uses a static assigned IP address not leased from the built-in DHCP server, it is required to specify the guest IP when registering the forwarding rule:". However, doing so (as I need to), seems to break the port forward with nary a report in any log file I can find. (I've reviewed everything in ~/Library/VirtualBox/).

Other notes:

  1. While I used the above command to add the third rule, I've also verified it showed up correctly in GUI and then removed/re-added from there just to make sure).
  2. This forum link -- while very dated -- looks somewhat related in that a port forward to a static IP was not appearing (perhaps they think due to lack of gratuitous arp being sent for host to know IP is there/avail?).

Anyway, what gives? Is this still buggy? Any suggestions? If not, easy enough workarounds? What's interesting is that this works perfectly fine on another user's Mac, however he's running a slightly older version (4.3.6 v. 4.3.12).

© Super User or respective owner

Related posts about linux

Related posts about networking