How to edit Hosts file [OSx 10.10]
What is a hosts file?
The hosts file on your Mac and PC are a local file that is used to map host named to IP’s. Every time you visit a website your computer looks at the hosts file for reference and if it doesn’t find any references to it then it looks for it using an online DNS server.
- Open the Terminal application.
- Type in, and hit return:
1sudo nano /etc/hosts
- It will ask you for a password. Type it in and hit return.
- Once the hosts file is open, you can modify it to your needs and click Control+X to exit. It will ask you to save. Y for yes and N for no.
- If you made changes to it make sure to open up Terminal again and flush the DNS cache for it to take effect. You might need to restart your Mac. You flush the DNS by typing in this command on the Terminal:
1sudo dscacheutil -flushcache
You can use the Hosts file to block websites on your computer. If you point them to the localhost IP (127.0.0.1) it will most likely load nothing. In this case, if I visited Google.com, the website would not load.