相关文章推荐
文武双全的拐杖  ·  解决Gson解析报 ...·  1 年前    · 
奔放的蜡烛  ·  WPF ...·  1 年前    · 
被表白的野马  ·  Global Malaria Programme·  1 年前    · 

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?

    lol, yeah, I ended up removing that right quick. When i was looking at the VMIP, i wanted to have it say localhost, so i thought 127.0.0.1 made sense to me. – Fallenreaper Mar 18 '16 at 16:09 No , you cannot 127.0.0.1 neither localhost. @Giuseppe Gorgoglione does give you the hint. oh wait.. I better give some visualisation. – mootmoot Mar 18 '16 at 16:18 Ok, I just read both Vmware and virtualbox. The answer is pretty simple : Vmware and Virtualbox do things differently. The port forwarding method are NOT INTERCHANGEABLE. Vmware "prefer" the bridge way, Virtualbox only let you do it at the NAT setting. – mootmoot Mar 18 '16 at 16:38

    I believe you actually answered your question correctly as I was following it and achieved desired outcome.

    IMHO, the error: ERR_CONNECTION_REFUSED indicates that a firewall on your host OS or guest OS (your VM) or on both doesn't allow the communication through the given ports.

    The easiest thing would be to try to disable firewalls on boths, your HOST and GUEST OS.

    Not sure what are your OSes, but here is just a good guide for setting up firewall rules on Ubuntu

    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.

    You should change your question to "What is the correct ways to configure port forwarding in Vmware" . – mootmoot Mar 18 '16 at 16:41

    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".

    "NAT: Used to share the host's IP address." Bridged sets the guest on the same network with a new IP and can access it according by accessing it by ipconfig and getting the IPV4 address and accessing it with the port. – Fallenreaper Mar 18 '16 at 15:41 Where did you get the quoted sentence from? I think you got it wrong. The explanation is too long for a comment, see my edited answer. – Giuseppe Gorgoglione Mar 18 '16 at 18:43 The quote was from the VMware Workstation. I right clicked my instance > Settings > Network Adapter. For the Network Connection subsection: "Nat: Used to share the host's IP Address." – Fallenreaper Mar 18 '16 at 18:46

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

    site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution required. rev 1.0.0.0