Updating /etc/hosts on OS X

Updating /etc/hosts on OS X

Sometimes you need to have a static IP address configured to a specific domain name on OS X. For instance, locally testing a web server is a great reason to do this. Doing so is fairly easy to setup, but does take a bit of command line work.

First, edit /etc/hosts with your favorite text editor.

the default looks something like this:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost

Edit the file, add in the IP address under the 255.255.255.255 address, then put in the hostname with spaces over under “localhost.”

Then you have to reload the hosts file.

OS X 10.4 type:

sudo niload -v -m hosts . < /etc/hosts

on OS X 10.5 and 10.6
lookupd -flushcache
dscacheutil -flushcache

Then simply ping the new domain name and check that is resolves to the correct IP address. (assuming the other computer is setup to respond correctly)

Leave a Reply