Applying changes to hosts file on OS X (without restarting)

Some machines seem to have no problem with changes to the hosts file, others seem to have quite a bit of trouble with caches and things hanging onto information. This has worked once or twice now, and I thought I’d bother to re-document it (for myself at very least).

To add an entry:
Edit /etc/hosts
sudo niload -v -m hosts .  Clear Private data and clear things.
lookupd -flushcache

To remove the entry:
Edit /etc/hosts
sudo niload -v -d hosts .  Clear Private data and clear things.
lookupd -flushcache
Notice the -d for deletion.

Source: Coding In Paradise

Leave a comment