How to fix DNS resolving issues on Mountain Lion after waking from sleep?

I've had this exact same experience, though not every time. Sometimes it means sites that I have visited recently are unavailable but other sites I haven't visited in ages load just fine.

Usually flushing the DNS cache resolves it.

sudo killall -HUP mDNSResponder

Occasionally I get this as well. When it happens, I tell the system to flush the DNS:

# As root or sudo it
dscacheutil -flushcache

In the power settings, to avoid sleep/wake related issues, I've disabled the system's "put disk to sleep" option, as apparently, it can cause issues with SSD equiped boxes.