How To Edit Hosts File On Mac

Share and Like

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.

sudo nano /private/etc/hosts

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:

IP   Domain name

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:

11.11.11.11   makewebworld.com    www.makewebworld.com

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.

dscacheutil -flushcache

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:


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

About Sanjeev Mohindra

Welcome to MakeWebWorld! I am Sanjeev, a blogger and Technical Consultant in Software Industry. This blog will provide help and tutorials for creating your web space, Wordpress tutorials, social media management, video marketing or SEO tips. You can connect with me or subscribe to MakeWebWorld free tips.

Comments