The Mac OS X hosts file
The hosts file...
- doesn't have an extension, its just called hosts.
- is a text file that maps hostnames to IP addresses.
- is located at /etc/, which is a symbolic link to /private/etc/
- is checked before the active network connectionís DNS servers.
- plays an important role in managing an Avaya 7.5 system (and beyond).
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. 127.0.0.1 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:
We can also use the hosts file to block access to websites! Make an entry like: 127.0.0.1 facebook.com to locally block facebook (for example), or enter: 184.108.40.206 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.
- OS X (10.10) Yosemite:
- two commands, clear both MDNS (Multicast DNS) and UDNS (Unicast DNS) together...
$ sudo discoveryutil mdnsflushcache;sudo discoveryutil udnsflushcaches
- OS X (10.9) Mavericks:
- two commands, first flush the cache, then reload the DNS responder...
$ dscacheutil -flushcache;sudo killall -HUP mDNSResponderFor older OS X versions:
- (10.7) Lion & (10.8) Mountain Lion:
$ sudo killall -HUP mDNSResponder
- (10.5) Leopard & (10.6) Snow Leopard:
$ dscacheutil -flushcache
- (10.3) Panther & (10.4) Tiger:
$ lookupd -flushcache
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 hosts hosts.original $ sudo cp hosts.love 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.
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):
- Open: System Preferences Security & Privacy Firewall Advanced.
You may have to authenticate (click the padlock) with your Admin password to enter the Advanced features.
- Uncheck Enable stealth mode.
Don't forget to re-enable "stealth mode" when you connect to the internet.