Friday 15 November 2019

How come hosts file redirection fails?


I am trying to redirect google.com to my local machine for fun and learning with this /etc/hosts file on my Mac.


127.0.0.1 www.google.com

However, www.google.com still maps to the Google home page when I visit it in Chrome on my Mac. Why?


Basically, this is all I did:



  1. Type sudo vim /etc/hosts in terminal.

  2. Inputted 127.0.0.1 www.google.com into the hosts file.

  3. Saved and quit vim.



Answer



The hosts file doesn't work this way. You can only use it to map an hostnames to IP addresses, not to localhost.


For your case you'd use 127.0.0.1 www.google.com, i.e. map www.google.com to 127.0.0.1.


If you want to map more hostnames to a singe IP, you just add those hostnames in the same line, e.g. 127.0.0.1 www.a.com www.b.com.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...