I'm trying to get my El Capitan's (10.11.6) DNS cache to flush, to try and solve slow localhost domain name resolution, but nothing I do has any effect. My computer name, hostname and hard disk names used to be as follows:
Santa's MacBook Pro
santas-macbook-pro-2.local
Santa's MacBook
(I didn't choose to put the "-2" at the end of the hostname; that's what the Mac had in the Sharing preference pane.)
I tried editing the etc/hosts
file as follows:
127.0.0.1 localhost santas-macbook-pro-2.local
255.255.255.255 broadcasthost
::1 localhost santas-macbook-pro-2.local
fe80::1%lo0 localhost
but even after a restart the resolution was still as slow as ever.
Tried renaming the computer and hostname to trial
and trial.local
(updating etc/hosts
accordingly) and the hard disk to tt
. Got OnyX to flush various caches including system and kernel extensions, restarted, still slow.
In running the little inetTester I get Santa's MacBook Pro.local
returned.
I've tried flushing the DNS cache following the instructions here, restarted, and I still get Santa's MacBook Pro.local
returned.
It seems discoveryutil
doesn't exist any more (in any case it's not on my machine), so I can't even look at the contents of the cache.
What on earth do I have to do to get this machine to forget about being Santa's MacBook Pro?
Best Answer
You are mixing a lot of completely or partly different/unrelated things here.
To properly and quickly name resolve your hard disk/SSD, you also have to add its name to the hosts file:Now you can check the response time by pinging it:
The average round-trip time is ~0.071 ms. So the time needed to resolve it is less than ~0.071/2 ms. With a real HDD/SSD you can expect even faster responses.
Please use the shorttt
(the name of your volume) instead of my longtt-this_....
name to get an even quicker response.To check your DNS cache open Console.app (enter mDNSResponder in the Search field) and Terminal.app.
Check the time and enter in Terminal:
sudo killall -INFO mDNSResponder
Roughly the first half of the output in Console with the time stamp noted previously is the DNS cache. The cache part starts with
------------ Cache -------------
and ends with a summary likeCache currently contains 391 entities; 33 referenced by active questions
.To kill the cache use
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Re-check the cache by entering
sudo killall -INFO mDNSResponder
again.discoveryutil was introduced in OS X 10.10.0 and replaced by its predecessor mDNSResponder in OS X 10.10.4.
To modify your local hostname and computer name use
scutil
:If you still get a Bonjour name (e.g. Santa's MacBook Pro.local) your hostname is probably set incorrectly. Either change the hostname by entering:
or remove it completely (recommended) by modifying the file preferences.list:
and remove your current malformed HostName near the bottom of the file:
☛
You may also have to remove the preferences backup file preferences.plist.old. Reboot afterwards.
Name resolution is roughly done in this order:
inetTester is a tool to quickly check the elapsed time spent from the Java layer to access the localhost domain name. This is not the time to get (resolve) the local hostname. The hostname is stored somewhere in memory and a system call takes nanoseconds to get it.
Regarding item 1 in the list. I wear Dark Vader's
helmetparty hat and got nasty temporarily.