Mike's PBX Cookbook

The Mac OS X hosts file


The hosts file...

Editing the hosts file

Editing the hosts file in Mac OS X is a pretty easy task, especially if you are familiar with the terminal.

1 Open the Terminal.app

Either by typing "Terminal" in Spotlight, or by navigating to: Applications Utilities Terminal

2 Open the hosts file

Open the hosts file by entering the following command in the Terminal window you've just opened:
$ sudo nano /etc/hosts

Enter your (admin) user password when prompted.

3 Edit the hosts file

The hosts file contains some comments (lines starting with the # symbol), as well as some default hostname mappings (one per line), entered as IP address followed by one or more hostnames (e.g. localhost).

Append your new mappings underneath the existing ones. Navigate using the arrow keys, leave space between fields, and make sure there is an empty blank line after the last entry. Here we'll add ucm0.pbxbook.com:

Editing the Mac OS X hosts file with nano

We can also use the hosts file to block access to websites! Make an entry like: facebook.com to locally block facebook (for example), or enter: facebook.com to direct facebook requests to cnn.com.

4 Save the hosts file

When done editing the hosts file, press Ctrl-o to save the file.
Press enter on the filename prompt to leave it unchanged, and Ctrl-x to exit the editor.

You can now test your new mapping with ping mypbx.com, or by entering the URL in a browser window!

5 Flush the DNS cache

If your changes don't seem to have taken effect, use one of the following commands to flush the DNS cache.

Details: https://support.apple.com/en-ca/HT202516

The GUI options

If you prefer to do things with a nice GUI, take a look at Gas Mask. It can manage multiple host files, and let you switch between them. Its then an easy matter to switch between work and play host tables.

A simpler alternative is the Hosts preference pane. This lets you easily add, edit, and remove host entries. If an item is checked, it's stored in the hosts file, if it's unchecked, it's removed rather than commented out, but continues to be stored in the preference panel for future use. When you visit a customer site, you can activate the relavent host settings with a simple check box.

How to make the internet not suck (as much)

If you like the idea of locally blocking access to certain websites, have a look at http://somebodywhocares.org and their custom hosts file. In their own words, "This is an easy and effective way to protect you from many types of spyware, reduces bandwidth use, blocks certain pop-up traps, prevents user tracking by way of 'web bugs' embedded in spam, provides partial protection to IE from certain web-based exploits and blocks most advertising you would otherwise be subjected to on the Internet."

Download their custom hosts file, rename and copy it to /etc/hosts.love
Install by swapping the active and inactive files (remember, the active file is always hosts):

$ sudo cp /etc/hosts /etc/hosts.original
$ sudo cp /etc/hosts.love /etc/hosts

Once installed, you'll find that your surfing experience improves, your breath becomes more lovely, and the world transforms into a gentle place full of unicorns and love. If this is your thing, check back with the site regularly for the latest updated download.

Stealth Mode

OS X has a built-in Firewall, and one of the options is "stealth mode". If this option is checked, the Mac will not respond to PING's.
To allow a network response (including localhost):

Don't forget to re-enable "stealth mode" when you connect to the internet.

OS X Stealth Mode will not respond to Ping
Home » Other » Mac-host