Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to configure some virtual hosts and I'm quite confused as to when this file is loaded.

At what point is /private/etc/hosts loaded? When logging in? At every DNS call? When Mac OS restarts?

share|improve this question
up vote 5 down vote accepted

The hosts(5) manual page provides some insight into how /etc/hosts is used.

The file is used by mDNSResponder and, given your question, I suspect you want to see edits to /etc/hosts reflected in your DNS look-ups.

After each edit of /etc/hosts reset the mDNSResponder cache using this Apple technical note, OS X: How to reset the DNS cache:

sudo dscacheutil -flushcache

The note explains when you might need to do this:

When you might want to do this

OS X keeps a local cache of resolved DNS queries for a time defined by the DNS server, but sometimes it may be necessary to reset the cache immediately and re-query a DNS server. For example, you might do this after an entry on the server is changed or a new entry is added.

share|improve this answer

Usually changes to /etc/hosts are updated automatically within a few seconds, and I haven't needed to reset the DNS cache manually.

If you try to run sudo opensnoop|grep /etc/hosts and edit /etc/hosts, /etc/hosts is read by mDNSResponder almost immediately after you save it.

share|improve this answer
I suspect in later versions of OS X, Apple started actively watching the hosts file for changes using the kqueue mechanism. – Graham Miln Feb 17 '14 at 7:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.