How to

User Guide – Edit Mac Host File

Written by Hassan Abbas

Do you want to edit the Mac host file? While setting up the latest web server or another device that’s going to be plugged to the internet and you want to put it through its speed before it’s live. Or else if you’re facing issues with adware or spyware networks. Then there’s an invisible file on Mac that helps. It is known as the Hosts file, and this is how to use it.

The Domain Name System

Edit Mac Host File

Input the domain name of a web site. Every service or web site, almost every device plugged to the Internet has a unique numeric address. The address tells all the other devices where it is — its TCP/IP address. However, the Domain Name System (DNS) interprets numeric addresses into something a bit more memorable or recognizable to humans. Like “” etc.

Initially, once you input a web address, your Mac pings a DNS server. Typically one configured automatically for you by your ISP (Internet Service Provider) just to find out the TCP/IP address of the server you’re trying to connect to. However, your Mac builds up a hidden cache file to make sure that those details later on after you visit the same site again.

The Hosts file

The Domain Name System and its linked cache is your Mac’s way of knowing how to get to where it’s going on the Internet. But there’s an alternative file that can be very essential. It is known as the Hosts file, and it can also be used to override the default DNS information.

There are some practical causes why you’d like to use the Hosts file rather than of just allowing DNS to do its thing. Let’s say you’re checking a development server you’re about to install. Also, you want to use its domain name rather than the machine’s particular IP address. Before the PCs online and accessible to anyone via DNS. You can then use the Host file. Simply enter the machine’s IP address and while using that domain name, your Mac will move to that device.

Also, you can use the Hosts file to work around or block spyware and ad networks after “zeroing out” their IP addresses. Just put then the name of the domain you would like to block.

Edit Mac Host File Manually

Edit Mac Host File

Fix 1 – Using Terminal

If you want to edit the host’s file with the Terminal, administrator rights are required. You also want the password.

Step 1:

Look for the Terminal app on your Mac. For this utilize the Spotlight application. Or, you can select Applications located within the Finder window’s sidebar. Then, select Utilities and choose Terminal.

Step 2:

Once you launch the Terminal windows, you can access the Nano text editor that is used for editing the host’s file. Simply input sudo nano/etc/hosts and hit Enter. It’ll ask for an administrator password. Just input your admin password and hit Enter one more time. Now, you will enter the Nano text editor.

Step 3:

Add your pointer below the text already added to the Nano text editor. This is where you’ll actually enter the other IP address. Enter the particular IP address you want the website to be rerouted to. Hit Tab. After that, enter the domain name you want to link with it. For instance, if you want Facebook to reroute back to your homepage, simply input your web site’s IP address, hit Tab, and then enter If you want to input another website/ entry, just add a new line.

If you want to fully block the site, you can enter invalid IP addresses. Or else you can utilize 127.0.01 which always reroutes to your PC.

Step 4:

Save the changes you have made by pressing Control + O. Now, exit the Nano text editor by pressing Control + X. This will put you back on the Terminal display.

Step 5:

If you want to know that Mac doesn’t experience confusion because of the conflicting info from both the DNS and the host’s file. Then you simply enter sudo killall -HUP mDNSResponder before you exit the command line. Then, hit Return. With this action, you are removing the DNS cache. Thus, the old directory will execute in conflict with the newly modified hosts file.

Fix 2 – Using TextEdit

Step 1:

Head over to Finder. Tap Go and then tap Go To Folder. After which, input /private/etc/hosts and press Go.

Step 2:

Copy the required file onto your Mac’s desktop. Then open the file for editing. In the text file enter your alternative address identical to that of what you’ve done in the Terminal: Initially, put the rerouted IP address and then the domain name. Remember that there’s a space in between the domain name and the IP address to make it work perfectly.

If you want your Mac to erase access to specific websites, you can then utilize 127.0.01 as an IP address. As it will reroute the address to that of your Mac.

Step 3:

In this step simply save the file you have edited. After that, add it back to the folder name “etc.” Mac will confirm if you like to replace the required file. Confirm the replacement and then enter the administrator password to save it.

Reasons To Add The Host File:

If you want to input a web address in your browser, then you want to reach a specific IP address. So why do you want to edit the host’s file? Here are the advantages of doing so:

Networks Testing

If you want to develop a particular network, you can then reroute the real domain name to that of the website. The main cause behind this is to check out how real users can experience the site. The best thing about it is it can’t affect the users who can access the real site.

Blocking Harmful Websites

We all know the risks of malware and viruses. Also, clever add-ons can “sneak” their way within your PC and this results in slowing down of some things. You can simply use pop-up blockers to block harmful sites. However, after you edit the host’s file, it helps you to secure access to harmful sites. If a particular pop-up or link wants to enter the harmful site, your OS will re-route and launch another safer web page.

Fast Speed

After using the DNS to find a webpage, it is slower as compared to using a host’s file. When host files are localized to a Mac then it becomes faster in speed.

Enhanced Productivity

Social media networks and video streaming can be disturbing. You can also block access to these sites to improve the productivity of your company or team members.

Risk Factors:

After editing the host’s file, you are rerouting a particular domain to a specific IP address that’s not actually a site. Thus, if you want to edit the host’s file to set a specific domain to another website. Then it depends on the IP address staying the same as the ones you have entered.

When the website is rerouted to changes its own IP address, the new route becomes invalid. The domain name will either display up a new site or display an error message. If your servers are taking too much time while processing the requests. Then the DNS lookup probably NOT be the one slowing the process. You just try to fully wipe your OS to ensure your Mac is not causing the issue.

Alternative Way To Secure Your MacOS Privacy

Many fixes to secure your privacy in a macOS are simple or easy to do. One fix is to clean your Mac after wiping your user cache, browser cache, and system cache. You can also use the tool known as iMyMac’s Mac Cleaner to do the job.

Step 1:

Initially, download or install iMyMac – Cleaner

Step 2:

Once installed then launch the program which directs you to the main interface using your Mac’s system status.

Step 3:

Tap “Junk Files.”

Step 4:

Tap “Scan.” iMyMac will display you scanned junk files in different classifications

Step 5:

Choose a classification and pick the data you like to delete.

Step 6:

Tap “Clean” and confirm the process

Step 7:

However, the process is done and displays a Zero KB in some folders.

Step 8:

Repeat the whole process. But this time, choose “Clutter” OR “Large & Old Files” rather than “Junk Files.”


Here’s all about “Edit Mac Host File”. I hope this article helped you to edit the Mac host file.  If you think that it is helpful then do let us know your suggestions in the comment section below. Do you know any other method that you think we can’t mention in this article? Comment us below and stay tuned with us! If you still find any issue then let us know below!

Also Read:

About the author

Hassan Abbas

Tech enthusiast with too many items on his wish-list and not nearly enough money! Specializing in all things tech, with a slight Apple bent he has been writing for various blogs for the best part of (too many) years

Leave a Comment