How to Edit Hosts File on Mac

Whether you want to control network traffic or access to websites or thwart spyware, you will need to edit Hosts file on your Mac. Thanks to Terminal application, configuring the host file is a bit easier on macOS. Read on to know how it works!

The 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 on your Mac 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.

Sponsored Links

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.

Sponsored Links

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

Sponsored Links

While mapping an IP address on your local network to a domain, type in IP address, press ‘Tab’ on Keyboard and enter the domain name. (Make sure to enter all the possible combinations i.e. www.facebook.com and facebook.com)

  • 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.

Block Website on Mac By Editing Hosts File

Step #5. Next up, you need to hold down the control and O keys to save the file. Press enter/return key.

Then, use control and X to exit.

Sponsored Links

Most importantly, you need to flush the DNS. To do so, In the command line, enter sudo killall -HUP mDNSResponder Then, press return. Enter your system password.

Refresh Terminal on Mac

It will flush the DNS cache of your computer. Read more on how to flush DNS on Mac.

Video Walkthrough to Edit Hosts File on your Mac

Sponsored Links

That’s all there is to it!

Over to you

So, now you know how to make the best use of the Hosts file to keep malicious spyware at bay. Have any feedback? Do share it with us.

You would like to read these posts as well:

Found this guide helpful? Download our app and stay connected with us via Facebook, Twitter, and Google Plus to read more such articles.

Jignesh Padhiyarhttps://www.igeeksblog.com
Jignesh Padhiyar is the founder of iGeeksBlog.com who has a keen eye for news, rumors and all the unusual stuff that happens around iPhone and iPad.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

16 iPad and iPhone Apps Price Drop – 17 August 2018

What happens when you come to know that one of your favorite iPhone/iPad apps price has just dropped-and available at a huge discount? A...

18 Paid iPad and iPhone Apps Gone Free Today – 17 August 2018

iOS Games Gone Free TodayiOS Apps Gone Free TodayWhile there are tons of awesome apps available for free, a number of extraordinary ones come...

Apple’s tall claims of security falsified by an Australian teen; hacked into the secure computer network

Apple is a company that has always produced high-quality products known for their privacy and security. But the company has failed to maintain its...

How to Install iOS 12 Developer Beta 8 on your iPhone or iPad

Apple has just unveiled iOS 12 and made it available for developers for testing purpose. Packed in with several top-of-the-line features, the latest iOS...