Editing A Mac’s Hosts File 14

Tutorial

Share
Editing A Mac’s Hosts File

Hey

On your Mac there is a hosts file that controls certain IP and domain addresses. It works in a similar way to a normal DNS server. It translates web addresses to IP addresses. This file enables you to change this link. As a result you can block certain domains from loading or just have a bit of fun. You should only use this file if you really need to, as well as this changing this file is a little bit complicated and if you are new to the Mac, I would recommend skipping this tutorial.

The hosts file is in the /etc folder. To access this file in Finder to to Go > Go To Folder, and type in /etc. A normal finder window will appear. In this window find the file called “hosts” double click this file and open it in TextEdit. At this point you should be enabled as a root user, so you can quickly edit the file.

In this file you should notice a couple of things, there should be a comment area at the top signified by hashes (#), and a couple of entries in the file. Do not change these. They are very important to operation of you computer. Your file should look like something below.

127.0.0.1          localhost
255.255.255.255    broadcasthost
::1                localhost
fe80::1%lo0        localhost

The IP address in on the left and the domain is on the right. You can now add more domains and IP addresses, one per line. For instance if you want to block an ad server you would type the following:

127.0.0.1 ad.doubleclick.net

This will send any requests from the doubleclick.net address to a blank adress. Although I don’t recommend you do this for blocking adverts, something like Adblock Plus is a lot better it can be used for practically anything. Say for example you have a program accessing the web, you can put an entry in the hosts file. As well as this it is also very good for blocking sites that you don’t want your kids accessing. If you have a web server set up, you can forward it to that IP address on your local network telling them they are accessing something they shouldn’t.

To make the changes stick, all you have to do is save the file and flush your cache. Using the methods described in this post, clear your cache in Terminal. Once you have completed, the command the changes should take effect.

If you want to find out more about DNS and all its related workings I recommend the DNS for Dummies, I recommended it in a previous post and many people have said it sa really useful book.


If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.

Where To Next?

  • Subscribe To Mac Tricks And Tips