[How to] Edit etc/ Hosts File On A Mac

Vincent —  October 17, 2011 — Leave a comment

If you happened to required to modify your hosts file on your Mac, you might experience some hard time searching it around your Mac OS. Well, the best way to get your hosts file edited is through Terminal.app, an application originally shipped with your OS.

What is Hosts file?

Hosts file is a text file that used by your computer to map hostnames to IP addresses. For example, if a hostname (or server name) match its IP address, you will be able to access to the website when you enter its URL into your internet browser.

You can also use hosts file to block any site or server (such as advertisement or malicious sites) by typing your own computer IP adresses along with server names by the side. The unmatched IP and hostnames will then be blocked and prevented your browser from accessing to it.

Step-by-step guide on editing etc/ hosts file

1. Open “Terminal” from your applications folder.


Search for “Terminal” from top right corner for spotlight search.

2. Type in “sudo nano /private/etc/hosts” and press enter. It will ask for authorisation password for your Mac.

Note: The original hosts file should contain some default homename (local host) and some sentence with hash (#). DO NOT simply modify or delete them. It is important for the system.

3. You can add your stuff under the default value.

4. After finish editing, press “control+ O” and enter to save the file. Press “control + X” to exit from the editor.

You might need to flush your DNS cache to let your new host file to take effect,

simply open Terminal and type “dscacheutil -flushcache”.

And you are done.


Posts Google+

Co-founder and Main Editor of Tezeal | Vincent is a blogger who is passionate in technology and dedicated most of his spare time for technology news, doing troubleshooting and searching for some of the best apps and tweaks for every devices.