How to Change Mac Hosts File

Affiliate disclosure: In full transparency – some of the links on our website are affiliate links, if you use them to make a purchase we will earn a commission at no additional cost for you (none whatsoever!).

The denizens of the modern tech world eat, live and sleep on the Internet. Always connected is the name of the game and it’s no doubt a scary thought to even imagine us being stranded without internet connectivity.

However, this nightmare often makes its way into reality as we find ourselves in situations where connecting to the internet seems nigh impossible.

While it could sometimes be due to hardware faults from your end or your ISP’s, more often than not. it’s something to do with your software configuration.

What does one do in such situations though? Well, one of the first things you should do is find your Mac hosts file and see if it has been tampered with.

So today I’m going to share with you one of the few easy ways you can change your the hosts file on your Mac. This simple method will not only save you from malicious attackers but also help you block websites without involving any third party software!

Why the Mac Hosts File Is So Important?

Well, the Hosts file for any Operating system is a vital tool. We discuss it at length in this article. While the host’s files mac can differ a bit primarily in where they are found and how they manage the access of the computer to the Internet, they are similar in the way they operate.

Let’s go through a tiny recap then shall we?

So, the Host File is an internal address book for your computer. The host’s files Mac can be used to both edit and

The best way to work with the Hosts file is by using the Terminal application found in your Mac’s utility folder. You’ll need to know the IP address of the device you’d like to send your Mac to or the domain names you’re trying to keep your Mac away from.

How to Change Mac Hosts File?

Without any further ado, let us begin!

Step 1

We are going to use the Terminal. So our first step is to open the app by double-clicking on Terminal.

Step 2

Next up, we have a bit of code so you can copy-paste it from here directly!

sudo nano /etc/hosts

and once you’re done with that, hit return.

Step 3

In this step, you’ll be asked to enter your password. This is the admin password that you use to login to your Mac.

Step 4

You will now find yourself in the Nano text editor. You should see something that looks like a wall of text.

Step 5

Now comes the most important part! To add a new device or domain, we must position the cursor just after the text you see by using the arrow keys and then begin typing in our new entry.

If you want your new entry to map to any particular IP address which is on your local network to a particular domain of your choice, you can do that easily.

Just type in the IP address followed by tab button on your keyboard and finally type in the domain name.

And that’s it you’re done. In the next step, we will detail how you can block a specific website by editing the host’s file on a Mac.

Step 6

If you’d like to block a particular website and make sure that the  URL doesn’t go through to its destination, or if you’re trying to keep your Mac protected by restricting access to certain sites, use the IP address “127.0.0.1.

This will make that specific website always revert to your Mac. This is a fail-safe mechanism for keeping certain websites out f reach of whoever is using that Mac.

Step 7

Now that you’re done with your editing you’d want to save your work. For that, hold down the control and O keys to save the file.

Step 8

Hurrah! You’re almost at the end! Just hit ctrl+X to exit the editor and you’re out of the nano text editor!

Step 9

The hard part should be over by now. Now that you’re back in front of the command line, type

sudo killall -HUP mDNSResponder

followed by return. This flushes your Mac’s DNS cache so that it doesn’t get confused by any changes you’ve made to the Hosts file.

Precautions

While this a relatively simple procedure, it never hurts to be safe! For your safety, we advise you to make a copy of your host’s file before you start making any edits.

That’s all from us for today. If you have any questions regarding this topic or anything else regarding hosts files and Macs, leave a comment down below.

I’ll be glad to help you out! If you’re looking for something else to read about Macs, do check out this article where we discuss how you can show hidden files!

If there’s anything about Macs that you’d like to have us address, leave that in the comment section as well! We will try to feature it in an article as well!

Amartya

Leave a Comment