How To: Flush DNS Cache on OS X

Most users don’t need to use this command, but it’s very helpful for web developers and network admins to troubleshoot issues with web sites.

This command is run via terminal.

On Leopard (10.6) and Snow Leopard (10.7):

(as root or admin user) dscacheutil -flushcache

On all other version (10.0 – 10.4):

(as root or admin user) lookupd -flushcache

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.
## localhost broadcasthost
::1 localhost

Edit the file, add in the IP address under the 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)