How To Edit Hosts File On Mac


There may be times when you need to edit hosts file on mac. This post will give you a step by step instruction to do that.

You can edit hosts file on Mac from the terminal. You can find the Terminal app either on your dock or in the others menu under launcher.

If you are not able to find it, use the spotlight. Just type “Terminal” and you will get the application.

Edit Hosts File On Mac
Edit Hosts File On Mac

One you have the app, you can enter below command to open the hosts file.

[box]sudo nano /private/etc/hosts[/box]

It will ask for a password, it is a same password as your account password on Mac. Once you enter that password, you will get the hosts file open for editing.

Edit Hosts File On Mac

You can edit this file as a normal text file. If you want to add a new line, just make sure that you follow the syntax mentioned below:

[box]IP   Domain name[/box]

Note: Blank spaces does not matter and you can have multiple domain name at the same line. Below is an example of valid entry type:


Once you have done the editing, use CNTL+O to overwrite the file and CNTL+X to close the file. Do not close the file directly otherwise you will all your changes.

Refresh Browser to Pick up changes

Once you have done with the edit hosts file on Mac, you need to flush all the cache of the browser so it can pick your changes.

You can run below command in Terminal to flush the cache.

[box]dscacheutil -flushcache[/box]

Now close and restart your browser and your changes in Hosts file will be picked up.

Video Guide on How to edit Hosts file on Mac:

[youtube src=”S_I9lPILyaM”]

This is how you can easily edit hosts file on Mac. Let me know if you need any specific instruction for editing Hosts file.


Comments are closed.