Jan
20
2007

Howto: Port forward to Your Virtual Machine

So sometimes I do things just for the fun factor. As mentioned in a previous post, I like having Windows server, but I prefer Linux for web-hosting. I finally found the solution to do both at the same time on one machine. In the real world people have been doing this for years, but it’s a first for me.

After doing all my installing, I then installed VMWare’s now free VMWare Server. I downloaded the Ubuntu Server distro and decided on the 6.10 release dubbed Edgy Eft. It doesn’t have the LTS, but is perfect for my needs because the repositories include everything I need for my Ruby on Rails setup (including Lighttpd).

Then I just had to figure out how to get traffic from my host to my virtual host. I wanted to use Bridged Ethernet and did that originally, but even though my VM grabbed an IP address on my Lan, when trying to access it from another computer, I was told that there was:

No route to host

If you’re smarter than I am, you can probably figure out a way around this, but I was just trying to get it to work. I turned to NAT. Go to VM > Settings > Ethernet in your VMWare Server Console, select NAT, and click OK.

Now boot your VM log in, and run an

ifconfig

to see what your IP Address is. Again in your server console go to Host > Virtual Network Settings. Select the NAT tab. Make sure to move this window so you can clearly read your VM’s IP address. VMNet8 is the default virtual adapter for NAT, so if this is your only VM go ahead and click the Edit button (if you have others, make sure to select the proper adapter for your VM from the dropdown menu, then click edit). Now click the Port Forwarding button and then the Add button. Fill in the host port, the VM ip address, and the VM port. For me this meant forwarding port 80 from the host to port 80 on the VM. Don’t forget a nice description. Click OK 4 times. Now just forward traffic through your router (as needed) and you’re good to go.

My Ubuntu VM is now serving Apache2+MySql+PHP5 to the world. Soon it will be serving Ruby on Rails.

For a graphical tutorial see:

14 Comments + Add Comment

  • [...] if you need to forward traffic to your VM, then at your router point port 22 at the host OS and follow my other instructions on port forwarding to a virtual [...]

  • Okay, so I’ve got a host on a lan, and a VM to be used as an e-mail server. Should the router point ports 110 and 25 to the host machine’s static IP address, vmnet8’s IP address, or what?

  • That depends on how your VM is setup. If it’s using bridged Ethernet, then it should be grabbing it’s IP address from your router anyway. If this is the case, then you should be able to forward traffic directly from the router to the VM. Check your IP address on your virtual machine. If it’s in the same range as your host machine (probably 192.168.x.x) then you’re probably using bridged ethernet. If this is the case, then you should be able to forward from the router directly to the VM.

    As I mentioned above, this didn’t work for me, so I used NAT instead of the bridged ethernet. If you’re going with this route, then you need to point those ports form your router to your host machine, then go into the VM settings as described and forward those ports again so that they can get to your virtual machine.

    With all the Parallels/Fusion/Mac’s running Windows VMs, this is even more applicable now than it was a year ago when I wrote this.

  • I cannot access my Linux which is inside my VM ware from outside my Host system. I possible do send in your comments to rojan555@gmail.com

  • Thank you, this helped dearly!

  • If I have understood you are talking about VMs with an host OS. I have the same problem (if I make a port forward in my router to the ip address of
    my linux vm I can’t reach it) but I’m using an ESXi server. It doesn’t give the possibility to forward packets to another address…..

  • @Federico, yes, these instructions are for VMs with a host OS, and specifically for VMs running with VMWare. Unfortunately, I don’t have any experience with the setup you’re describing.

  • I am hosting a webserver within a VMWare image running Ubuntu/Tomcat. I am using verizon fios with a static ip. I have set up the virtual server to listen for traffic on port 9000 (changed from port 80) to test. For some reason I cannot see the server from outside the firewall. I was on the phone for 4 hours with verizon today trying to troubleshoot the problem, and no love. Any ideas?

  • This works for me. (port Forwarding) I have 2 IPs assigned to my server. My server port 80 is running a few applications so I do not want port 80 to port 80 forwarding. How can I assign the second IP to forward to virtual port 80?

  • I’m having the same issue, however, i’m using the free VMware server 2.0 running on a Windows host. The guest OS is an image.

    Internally, everything works fine. But with port 80 pointing to the VM image, it does not work. When i forward port 80 to a different system it works great.

    I dont see a lot of the settings you discussed above, in Vmware Server 2.0. Has this functionality been removed from the free version?

  • It’s been a long time since I played with VMWare server. I’m not sure what version it was on at the time I was using it, but it was the free version.

  • [...] ClicK mE This only prove that VM can be portforward __________________ RageZone Free SubscriptionClick Here to Join [...]

  • Hey, man! You saved my life! I’ve been trying to forward my ip to VM guest for a week and could not succeed. Just did what you advised, set forward port THROUGH VM Virtual Network Editor and good to go! Thanks for sharing your experience!

  • I installed Windows Server 2008 R2 in Oracle Virtual Box,also WAMP server inside Windows server 2008 R2.

    I am able to open/access the WAMP server in my Virtual Box guest OS that is the local host.

    But I am unable to access the WAMP server from the host OS.

    The host OS is Windows 7

    How can this be fixed?

Leave a comment