networking - Forward port from guest to host

06
2013-10
  • evfwcqcg

    How can I forward port from Guest (OS on virtual box) to Host (my actual machine)?

    Guest - Windows 7
    Host  - Ubuntu 12.10
    

    On my host, I run a web-server on port 3000.

    I want to be able to open a browser from Guest on url

    http://127.0.0.1:3000
    

    and see my web app which I run on Host. (the reason is I need IE browser to test some stuff).

    In Virtual Box settings, I selected NAT and in Port Forwarding I wrote

    Host IP: 127.0.0.1     Port: 3000 
    Guest IP: 192.168.0.3  Port: 3000
    

    where 192.168.0.3 is IP of my Guest machine which I obtained from ipconfig.

    I thought this should work but now, once I try to run a web-server and Guest is running, I get an error that the port is already in use.

    Actual error

    /home/username/.rbenv/versions/2.0.0-rc2/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)

    Web-server is Webrick (default Rails and Ruby web-server in development mode).

    I tried different combination of host/guest IP's and ports but none of them seems to be working.

  • Answers
  • user2313067

    The easiest way for me seems to be to use the host's IP address instead of 127.0.0.1. You can obtain this from ipconfig by looking at the default gateway.

    If you really want to to do port forwarding, I suggest you take a look at http://stackoverflow.com/a/11535395/2313067. I am not even sure that this works on the loopback interface.


  • Related Question

    networking - Port forwarding
  • Claudiu

    I want to set up a svn server on my computer, so it's available from anywhere.

    I think I set up the repository correctly, using CollabSVN. If I go to Repo-Browser with TortoiseSVN and point it to svn://localhost:3690, it shows the proper repository.

    The problem now is that I'm behind a router. My local IP is 192.168.1.45. Doing svn://192.168.1.45:3690 also works. My global IP is, say, x.x.x.x. Just doing svn://x.x.x.x:3690 doesn't work, which makes sense, since I have to set up port forwarding.

    I'm using a Verizon router. Using their web interface (on 192.168.1.1) I added the following port forwarding rule:

    IP Address forward to: 192.168.1.45
    Source Ports: Any
    Dest Ports: 3690
    Forward to: 3690
    Protocol: TCP
    

    However, even after applying this rule, going to svn://x.x.x.x:3690 doesn't work. It takes a few seconds to fail, then says that the connection couldn't be established because the server connected to didn't respond properly after a period of time. What's interesting is that a random port, like svn://x.x.x.x:36904 fails immediately, saying that the target machine actively refused the connection. So I figure that the forwarding rule did something, but not fully what was necessary.

    Any ideas on how to get this working? The router model is MI424-WR and the firmware version is 4.0.16.1.56.0.10.12.3.

    UPDATE: I also tried setting destination port to 45000, and still forwarding to 3690, in case something was wrong w/ the lower-numbered ports, but to no avail. I also tried port 80 to port 3690, still all in vain.


  • Related Answers
  • Jay R. Wren

    Many routers don't support this, but if you try it from outside your internal network it will work.

    Ask a friend to try that svn://x.x.x.x:3690 from somewhere else on the internet and see if it works, or if you have a shell account somewhere, ssh to there and try to svn ls svn://x.x.x.x:3690

    I don't know the name for this firewall feature. I do know that making linux do it (which is what your wrt54gl uses) is a matter of adding an SNAT rule along with the DNAT rule.

    There is a VERY good explanation here : http://security.maruhn.com/iptables-tutorial/x9305.html

  • JNK

    Try forwarding on both TCP and UDP. Some quick research showed that SVN uses both.