Question

On my work Mac (Sierra) I'm running a NodeJS webserver on localhost, port 3000. I need to access to it from Internet Explorer running in Parallels for testing purposes.

I have searched and read and experimented extensively, and have thus far been stymied. My current situation is as follows:

I've got a Parallels "Host-Only" network with my Mac at 10.37.129.2 and my virtual Windows box at 10.37.129.3

Pointing my IE to 10.37.129.2:3000 fails.

I've jumped through every hoop imaginable to ensure port 3000 is open between the two, but nmap -p 3000 10.37.129.2 from the Windows side tells me port 3000 remains closed, as does Mac's Network Utility Port Scan software.

Sadly all guides and advice on the subject are either insufficiently similar, grossly outdated, or simply unsuccessful when attempted.

Any progress you help me achieve is greatly appreciated.


The relevant portions of my server.js are:

const port = process.env.PORT || 3000;
const host = process.env.HOST || 'localhost';
const proxyTarget = process.env.PROXY || 'none';
Was it helpful?

Solution

The "technical background" of the special behavior (at least on Macs) of using localhost as "host constant" is the specific nature of dns.js, which obviously binds the node http/https server to the interface it reverse-resolves to the const host (= localhost) with the help of mDNSResponder.

This is localhost > 127.0.0.1 > lo0.

Any other interface like en0/en1 as physical interfaces or vnic0/vnic1 as Parallels' virtual interfaces won't be addressed/attached.

To solve this you may either

  • set up a DNS-server like dnsmasq in Parallels' Host-only network and use the fqdn of the node http server host as host const
  • use the IP-address of the node http server in Parallels' Host-only network as host const
  • modify the hosts files of every host in Parallels' Host-only network and add a line like 10.37.129.2 testserver.example.com and use testserver.example.com as host const

OTHER TIPS

One of the way I could use it, I found my local IP4 address provided by the router.

From Mac system preferences > Network > IP Address: 192.168.x.xx

And let say if you access it in Mac with http://localhost:3000 you can do it also with http://192.168.x.xx:3000 from Mac itself and from Parallel Windows OS with shared network configuration.

This IP address could be changed each time you restart the router or choose another router etc.

Currently, I'm using Parallels Desktop 12

The temporary solution is to edit server.js and set host = '10.37.129.2' or set the HOST system variable to 10.37.129.2 and read it in with host = process.env.HOST || 'localhost'. It may also be possible to edit /private/etc/hosts to map 10.37.129.2 to localhost, though my quick test of that failed.

Everything was behaving precisely as expected. The localhost name is mapped to 127.0.0.1, and not to any network facing IP address. Thus 10.37.129.2, which was my Mac's IP on the virtual network shared with Windows running in Parallels, was never reaching localhost. This is correct and reasonable.

All credit goes to klanomath. Thanks!

Just run in the terminal:

ifconfig

And go to vnic0: inet address from the Parallels (like http://1x.2xx.5x.2:3000/ for ex.)

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top