‘last -d’ is REALLY slow

last

I can run the command last (and last -i) in a fraction of a second, but when I run last -d, according to my tests, it takes a whopping 5 minutes and 22 seconds.

Just for reference, this is what adding the -d flag does:

   -d     For non-local logins, Linux stores not only the host name of the
          remote host but its IP number as well.  This  option  translates
          the IP number back into a hostname.

There is no indication in the man pages that it should take that much extra amount of time. As it says, Linux stores the IP already, so it shouldn't have to do any sort of slow reverse-lookup of the IP based on the hostname on the spot. In addition, it is slow even when it is "looking up" that the hostname value of :0 (a local login) should return the "IP address" value of 0.0.0.0.

Is the -d flag slow on all computers, or just mine? Could this indicate a corrupted file somewhere which may be inaccessible or difficult to read?

For reference, I am running 32-bit Ubuntu 13.10 (haven't upgraded yet).

Best Answer

What's the DNS search order in /etc/nsswitch.conf? It should have files as the first option:-

hosts:      files mdns4_minimal [NOTFOUND=return] dns myhostname

It might be worth confirming the search order in your system.

I carried out the same test and had a result of 47 seconds for last -d.

I then added 0.0.0.0 localhost to /etc/hosts and it now take a mere 0.031s to run last -d.

Note - I've removed the 0.0.0.0 since, as according to Wikipedia, it's not valid to have it there.

Related Question