4

I'm on a Mac running a Windows VM in Parallels, I'd like to - from my mac - be able to hit http://localhost:44300 and have that request served by an application running inside the VM.

I know that this is possible since when I run docker, that is in fact what it does, I can create an application, run it in the docker container on port 44300, then hit localhost:44300 from the host machine. I simply do not know how to configure my Windows + VM to do it.

So I created a simple webserver in nodejs that just replies with a timestamp. This works when hit from inside the virtual machine:

Works from inside the VM

My netstat at this point reads

 TCP    127.0.0.1:44300        :0                     LISTENING

At this point, trying to curl from the host of course doesn't work

 $ curl http://localhost:44300
 curl: (7) Failed to connect to localhost port 44300: Connection refused

So to open this up to the host machine I forward the port in Parallels on my NAT configuration

Forwarded port in Parallels

I also create a urlacl rule:

PS C:\Users\gmauer> netsh http show urlacl | select-string 44300 -Context 1,5


>     Reserved URL            : http://*:44300/
          User: \Everyone
              Listen: Yes
              Delegate: No
              SDDL: D:(A;;GX;;;WD)

Now, when I curl I get something different

 $ curl http://localhost:44300 --max-time 3
 curl: (28) Operation timed out after 3004 milliseconds with 0 bytes received

This seems to be due to my Windows firewall. I (temporarily) disable it:

Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False

and now I get something different yet again

 $ curl http://localhost:44300 --max-time 3
 curl: (56) Recv failure: Connection reset by peer

Which seems to me that the request is passing into the VM but being shut down by something inside the VM (my understanding is that's the peer).

To confirm that I open up wireshark where I see the following:

Wireshark shows a request being killed

So the VM sees the request, then something Resets it with an RST...And there I run out of ideas what else needs to be done.

I've had it suggested to me that the issue is that localhost is special (it of course is), but I think I've demonstrated above that the request is getting into the VM, its getting past the firewall, its just not going any further. What else can I check/do?

Edit 1: As a this-sounds-crazy-but-I'll-try-it, I tried to map localhosts to my guest IP in my windows hosts file - no dice, same result.

Edit 2: I've tried running netcat to set up a socket server and can telnet in from the host and send messages to the socket server. This beyond a doubt proves that requests are getting into the vm. An interesting clue is that while wireshark shows the request, fiddler does not.

1 Answer 1

-2

127.0.0.1 or localhost is a special IP/hostname. It only works when you are referring to a port that is open on the current machine. You may have circumvented this by forwarding a port from the VM host to the VM guest, but probably the more robust solution is to use the IP address of the virtual machine. Connect directly to the guest; skip over all the firewall rules, forwarding rules, and address translations. You are making this too difficult.

Just run ipconfig from within your guest, get the IP, and use that instead.

3
  • 1
    Hi Andy, that really doesn't answer the question. I'm aware of how to hit guest VMs via the IP address, however that requires both a reworking of my application and - worse - setting up a bridged network and bouncing all requests off a shared router. In my situation I work a lot from a variety of coffee shops and the constant reconfiguration is a nonstarter. As I noted, this is certainly something that is possible as when you run an application in docker it does precisely this, allowing you to use localhost that is forwarded into the container (which outside of linux is in a VM. Commented Jan 30, 2019 at 3:36
  • You should tag your question with 'docker' then so that people who are more familiar with your environment will be able to help.
    – Andy
    Commented Jan 31, 2019 at 19:04
  • But I'm not using docker, I'm simply pointing to the fact that docker does this as proof that it is possible. If I tagged it with docker, I'd get blasted for drawing docker people to a question that has nothing to do with docker Commented Feb 1, 2019 at 16:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .