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:
- Type
sudo vim /etc/hosts
in terminal. - Inputted
127.0.0.1 www.google.com
into the hosts file. - 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