How to Edit Hosts File Using Terminal on Mac

102

“Hosts file” basically translates domain names or NetBIOS names into IP addresses. It's used for multiple purposes like blocking spyware and controlling the access to websites as well as network traffic. Based on your requirements, you can Edit Hosts File to remain in complete control.

Before proceeding, there are a few things you need to keep in mind. For instance, you must have the IP address of the device you want to send your Mac to, or the domain names you wish to keep your computer away from. Thanks to the Terminal app, working on Hosts file is a hassle-free experience.

How to Edit Hosts File Using Terminal on Mac

Step #1. Launch Finder app on your Mac and then click on Applications from the sidebar. Next, double-click on Utilities. Then, double-click on Terminal as well.

Or simply search Terminal in the Spotlight.

Open Terminal on Mac from Spotlight Search

Step #2. Now, enter the command: sudo nano /etc/hosts and then hit return.

Step #3. Next up, enter the administrator password and then press return.

Enter System Password on Mac

Step #4. Nano text editor will appear. Now, to add a new device or domain, simply move the cursor using the arrow keys and position it after the text in the window.

Hosts File on Mac

While mapping an IP address on your local network to a domain, type in IP address, and press return.

Step #5. Next up, you have to enter the domain name.

  • To keep your computer away from certain sites, make sure to use “127.0.0.1.”
  • 127.0.0.1 will default to the local machine even if it has been assigned a different IP address by its router.

Step #6. Next up, you need to hold down the control and O keys to save the file.

Then, use control and X to exit.

In the command line, enter sudo killall -HUP mDNSResponder Then, press return.

It will  Edit Hosts File and flush the DNS cache of your computer.

That's all there is to it!

Comments are closed.

Join 30,000 Bloggers
AND GET OUR LATEST CONTENT IN YOUR INBOX

SUBSCRIBE 
Your information will never be shared
close-link