Reputation: 4742
I'm using Windows 10. I'm trying to map 127.0.0.1 to a hypothetical domain: en.mylocalhost.tld
When I opened C:\Windows\System32\drivers\etc\hosts as Administrator, it was empty.
I added following line to it:
127.0.0.1 en.mylocalhost.tld
Restarted the PC.
I have an Angular application which is served on localhost:4200. It works on localhost.
But when I enter en.mylocalhost.tld:4200, I get
DNS error (the host name of the page you are looking for does not exist)
Also, there is no entry for localhost in the hosts file. Then why is localhost working?
How can I solve this?
Upvotes: 1
Views: 8439
Reputation: 1418
The HOSTS file of my fully updated (as of August 2019) Windows 10 Pro system seemed to be being ignored. A search found many similar complaints but nothing useful. I have responded to your post because it is the most recent I have found.
I used procmon from sysinternals to look at HOSTS file activity in response to a ping
command (Filter: INCLUDE if path contains HOSTS).
The first (and initially only) action captured was not a reference to the HOSTS file but was a query for a registry key:
HKLM\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\UseHostsFile
This key did not exist, but the name was suggestive!
I created it with a DWORD value of 1 and executed a ipconfig /flushdns
, and
the problem seems to have been resolved.
I have not fully tested this solution (for example: does it persist across reboots?; does it cause more problems than it solves?...) but it might explain why so many people have problems with their HOSTS file.
Also, of course, Microsoft can change the behaviour of the Windows name resolution system with a future update.
Upvotes: 3