How to Edit Hosts File on Mac Monterey 2022

Last Updated on Mar 31, 2022

A lot of software and website developers use their Macs to host, run and configure their websites. Although the MacBook might seem very intuitive and has a user-friendly and simple user interface, it is also an amazing programming beast that developers of different sorts can use.

Host file has an essential role in website configuration & Blocking port. So you can make your own rules about your website hosted on the Local mac running on macOS. Point the IP address to the desired website URL So you can override DNS temporarily by making changes in the host file located on Mac System. For Edit hosts file on Mac, we need little technical knowledge, and then you can do it with ease. However, to edit hosts files follow the below steps carefully.

With this article, we aim to deliver you all the information regarding the Hosts File on your device, where you can find them, and all the risks involved if you decide to edit the Hosts File on your MacBook.

Note: Before making changes, please backup your host’s files or copy lines of text onto another text file. Here you have two common solutions that might be very useful on the Edit host file on Mac OS X or OS X Server.

1. What and where is the Hosts File on Mac

The Hosts file plays a crucial part in this process since Mac users can override the Domain Management System (DNS) settings. Since every website has a basic numeric TCP or IP address like 1.6.8.0.21 that allows the search engine to search for the exact size you are looking for, keeping track of every TCP/IP can be tiresome. This is where changing the Hosts File to override DNS comes into play.

When we enter a URL on a web browser (e.g., google.com), the Domain Management System or DNS instructs the domain, translating the requested domain into TCP/IP format and then connecting the users to their desired website.

Hence for the website developers, the Hosts File plays a vital role as it allows them to change the TCP or IP of a domain from default to the one you want, which helps the developers while testing their website. If used properly, the Hosts file can also block spyware and adware websites from your browser.

The Hosts File can be located on the Mac by following the steps below.

Step. 1→ Open the terminal application on your MacBook.

Step. 2→ Now enter the following code in the terminal app: Sudo nano /private/etc/hosts and hit the enter key.

By completing the steps described above, the users can access and edit the Host Files on their MacBook. The Hosts File can also be accessed from Go > Go To Folder and typing /private/etc/hosts in the search bar.

2. Reasons to change your Hosts file.

The reasons to change the Hosts File on your MacBook can vary from person to person. For website and software developers changing the Hosts File helps them test their website link without even the link going online with SSL. 

By changing the Hosts File, the developers can override DNS for a specific domain temporarily, thus allowing your computer to have a direct look at the domain’s Internet Protocol or IP address. The users can also block some of the spyware and adware sites by changing the Host Files on their MacBooks.

3. How to edit the Hosts file on Mac

As we have discussed the importance and uses of changing or editing the Hosts File on Mac earlier in this post, it is essential to talk about the ways by which one can edit Hosts File on Mac. Therefore, pay attention to the instructions stated below to edit Hosts File on MacBook.

Note that before editing or making any changes to the Hosts File on Mac, ensure to make a backup or copy the text into a new document when you wish to revert to the default configuration. 

Step. 1→ First, open the Terminal tool on your Mac.

Step. 2→ In the terminal window, enter “Sudo nano /etc/hosts” and hit the enter key.

Step. 3→ Then type in your admin password if asked.

After completing these steps, a Nano text editor window will open where you can edit or change the Hosts File of your MacBook. Some TCP or IP addresses will already be visible to the users under the localhost and broadcast host tab. Now, all that is remaining is entering your TCP/IP address in the list.

Step. 4→ Now, hit the enter or return key on the keyboard to go to a new address line.

Step. 5→ Then, enter the TCP or IP address you want.

Step. 6→ After that, press the tab key and enter the domain name.

Step. 7→ Finally, save the file by hitting Ctrl + O keys and exit from the nano text editor by pressing the Ctrl + X keys on the keyboard.

Once you have finished this process, type “Sudo killall -HUP mDNSResponder” in a new line and hit the enter button to clear the DNS cache files on your Mac. This will prevent any interference between the DNS and Hosts File, and the changes take place immediately after saving the file.

4. How to Fix a Malfunctioning Mac Hosts file

If you make a lot of changes to the Hosts File in a short period of time, it is possible that your Mac might not be able to process these changes due to multiple entries. So to fix this problem, go through the steps explained in the earlier section to open the Nano text editor and delete all the text in it. Once you have deleted everything, enter the following default configuration to resolve the issue.

##

# Host Database

#

#

# local host configures the loopback interface.

# when the system is booting. Do not change this entry.

##

127.0.0.1 localhost

255.255.255.255 broadcast host

::1 localhost

Then hit the Enter key to change the Hosts File of your Mac to its default configuration.

5. Is it dangerous to edit the Hosts file on Mac?

Changing or editing the Hosts File of your Mac is a very safe and secure process as long as the Mac user is aware of what they are doing. For website developers, changing the Hosts File helps in the local development and testing process of the website of web developers. Although there is some amount of risk involved in this process, some people might use some other MacBook for testing without proper information regarding the modified files, etc. Hence, we advise you to be very cautious while changing the Hosts File on your Mac.

So if you want to change or edit Hosts File on your Mac to get rid of the spyware and adware websites, then we suggest you try out the method in the following section instead of editing the Hosts File.

6. Protect your daily internet presence

This section of the article is dedicated to the people who are tired of the ads and spyware of some malicious websites and are willing to edit the Hosts File to get rid of these sites. The CleanMyMac X application is one of the best optimizations that scans for malware and removes it from your device. Launch the app and click on the Malware Removal Scan option on the sidebar to scan for malware on your Mac.

In simple words, CleanMyMac X is a very handy app that helps you to delete all the DNS cache files from your system without using the Terminal app. It has many other useful features that will help you keep your Mac in good health.

As properly discussed in this article, there are some ways by which one can change or edit the Hosts File of their Mac for website hosting or testing and even for blocking some malicious sites with ads, etc. Keep all the risks and benefits of editing the Hosts File on your Mac before jumping into the process.

Steps on How to Edit the Hosts File on Macbook, Mac with Latest MacOS

Apple didn’t make any changes on the path of the hosts file location and Command syntax for the older OS X version. Same steps you can try on any OS X version.

I recommend using the Command Line method to open the host file on your Mac. Due to Security Reasons, the Simple folder method on Your Mac or MacBook Doesn’t allow editing hosts file directly like a simple file. It would help if you changed on a duplicate Hosts file first. So,

First Easy Way: Command for Open Hosts File on Mac and Edit File Normally

Terminal on Mac
Terminal on Mac
  1. Open terminal on Mac, To Open on Mac, Type Terminal on Spotlight Search [Command + Space]. or Directly open from Launchpad.
    • If it asks then Enter the Mac Admin password and press return.
sudo nano /private/etc/hosts

Type in terminal: and hit the Enter to open Hosts file on Mac screen.

Open Host file on Mac using Terminal and Direct Edit
Open Host file on Mac using Terminal and Direct Edit

Use the Arrow key on your keyboard to move a cursor and start Editing. Here I added one line. Once you edited.

Move Cursor in Host file to Edit on Host file on Mac
Move Cursor in Host file to Edit on Host file on Mac

Press Control + X from the keyboard to Save. Now in the Next Window, Your will be asked to enter Y for yes and N for No.

Save and Exit from host file on Mac
Save and Exit from host file on Mac

Press Y to move the earlier screen of a host file.

Press Yes to Agree host file
Press Yes to Agree to host file

Press the Return [Enter] from the mac Keyboard to close the Hosts file and Move to the Terminal window.

Hit Return button to Exit host file window
Hit Return button to Exit host file window

Now, You are on Terminal Screen. Now, You can verify or check the Hosts file by Re-Open with a terminal command. I hope you help this way very easily.

Move back to terminal on Mac
Move back to the terminal on Mac

That’s it.

Second Way: Open & Edit Hosts File on Mac Without Terminal Command

You can make changes by shortcut keys give on-screen.

Step 1: Open a Finder Window on your Mac.

Edit hosts file on Mac from finder

Step 2: From Top menu, go to the GO > GO TO FOLDER.

Step 3: Move to Hosts files location type in the text box:

/private/etc/hosts

and click on Go.

Go to hosts file on Go to menu

Step 4: double click on the file named hosts. The file will be open in the text editor.

Hosts file Location on Mac OS X

Step 5: Inside the hosts file, you can edit after broadcasthost.

How to Save Hosts File on Mac Using Keyboard Shortcuts?

Type or edit on hosts file

Here I redirected my Twitter account to another website IP for my Mac only. Not work on other Mac. Before Edit the file, you have to make a new copy of the host file, and changes will be saved to a new copy. Then you have to replace that new file with the original file manually. Due to privacy reasons, you can’t make changes directly on the original hosts file.

(/private/etc/hosts) 

To Exit or Save,

Control + X to Exit and Press Y key to Save in hosts file. and Tap on Return or Enter Button. [Play Below video to Learn on my Mac’s screen]

New copy of host file on Mac

That’s it. Nothing else. Want more help on Edit hosts to file on macOS Monterey, Catalina, Mojave, EI Capitan, Yosemite, or OS X Server. Could you share with me the comment?

Useful: Best Dictation software for Mac

HowtoiSolve Staff

Jaysukh Patel is the founder of howtoisolve. Also self Professional Developer, Techno lover mainly for iPhone, iPad, iPod Touch and iOS, Jaysukh is one of responsible person in his family. Contact On: jaysukh.pharma@gmail.com [OR] admin@howtoisolve.com

We will be happy to hear your thoughts

Leave a reply

HOWTOISOLVE
Logo