Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to do Port Forwarding using VMWare

I have created a VM which has a server running at localhost:8675/ which I had wanted to connect to my host machine at the same port for ease of understanding. I was following these to documents for information:

  • https://www.virtualbox.org/manual/ch06.html
  • http://www.howtogeek.com/122641/how-to-forward-ports-to-a-virtual-machine-and-use-it-as-a-server/

When I was in my VMWare Workstation, I clicked on my VM, then did: Edit > Virtual Network Editor. After that, enabled Change Settings which relaunched the window in admin mode. I clicked on the Row with Type NAT and external Connection NAT and in the VMNet Information with the NAT radio button pressed, I clicked the NAT Settings Button.

I said: Add... and then did:

Host: 8675
Type: TCP
VMIP: 127.0.0.1:8675
Description:  Port Foward of 8675 from Host to VM.

It looks like everything is good. I say Ok and Apply in succession. It looked like it shut down nat and restarted some services.

I confirmed in the VM, the 127.0.0.1:8675 is correct. In the HOST, I tried to go to: http://localhost:8675/ and it says: ERR_CONNECTION_REFUSED

I figured this was all I needed to do.

I was looking up some additional information and noticed that some people have had to configure firewalls. I wasnt sure if i needed to though, as I was thinking that the HOST and VM are all in 1 actual machine, it might be entirely self contained.

Is there a critical task I am missing?

like image 921
Fallenreaper Avatar asked Mar 15 '16 15:03

Fallenreaper


2 Answers

When you use NAT, the host system and the guest boxes have completely different IP addresses on their virtual subnet, so my guess is that when from the host system you try to connect to localhost:8675 you are actually trying to connect to port 8675 of the host and not of the guest. So don't use the localhost or 127.0.0.1 syntax, but discover the real IP address of the guest and use it. If your guest is Windows use the ipconfig command, if Linux use ifconfig.

Probably you will also have to configure the firewall on the guest side.

EDIT: Commenting the sentence "NAT: Used to share the host's IP address.": it probably refers to the IP address of the real ethernet adapter you have on your host and that is shared by host and guests to access the internet. That's not related to the way your host and guests communicate together. For example I use VMware Workstation to run a virtual Linux box in Windows. Selecting NAT, VMware creates a virtual subnet called VMnet8. In this subnet the virtual router has address 192.168.120.0, my Windows host is assigned a virtual ethernet adapter with address 192.168.120.1 and my Linux guest has got address 192.168.120.128. So when I want to access a Samba shared folder from Windows I type "net use * \192.168.120.128" in a Windows command prompt. When I want to access a Windows shared folder from Linux I type "sudo mount.cifs //192.168.120.1/path_to_shared_folder target_folder".

like image 76
Giuseppe Gorgoglione Avatar answered Sep 27 '22 19:09

Giuseppe Gorgoglione


I saw this post: https://superuser.com/questions/571196/port-forwarding-to-a-vmware-workstation-virtual-machine which told me to just adjust it to bridged and use it that way. Does this solve the issue of connecting HOST / VM Issue.

I don't want to say this is the correct answer though as the question itself is particular to NAT, but this is a valid alternative answer that does work.

This is solves the base issue at hand, but not the question.

like image 31
Fallenreaper Avatar answered Sep 27 '22 18:09

Fallenreaper