UltraDonut
UltraDonut

Reputation: 61

/etc/hosts doesn't work for localhost only

What I need: Localhost points to the IP of my other PC on the local network.

What I tried: I added "IP localhost" to the /etc/hosts file. Command ran: "ipconfig /flushdns"

Browser: Edge/Chrome/Internet Explorer

This doesn't work, but if I name it anything else than "localhost" it does actually work. I know it is something about the DNS, but I read online that the hosts file should overwrite it.


Partly solution

Google OAuth only accepts localhost or example.com as redirect URL. Not being able to use localhost on a different PC for testing, I solved this by using example.com on both the local PC and the second PC. I added the following to the hosts file:

Local PC: 127.0.0.1 example.com

Second PC: IP_OF_LOCALPC example.com

You can then use URL example.com:PORT. This isn't supported by Microsoft OAuth though (I guess I will only use Google Login for developing). Any ideas on how to solve this for Microsoft OAuth are welcome :)

Upvotes: 2

Views: 2194

Answers (1)

Rhu
Rhu

Reputation: 2179

Are you using Chrome?

Chrome has it's own DNS, if you use another browser then it's likely it will work as you expect.


Edit: Confirmed that this is still possible in Safari today on a Mac (26/12/2021). However, browsers appear to be clamping down on this - and are making an effort to make sure that localhost and *.localhost will only ever point to your local machine.

Upvotes: 0

Related Questions