14

Sometimes (not too often at all) when I type "netstat", it takes over 5 seconds to return. While other times is instantaneous.

I have been observing this for weeks on my server (CentOS 6.4), but I don't understand why!?

Can anyone give an explanation?

1 Answer 1

23

It's all DNS resolution. If the DNS server is slow, it delays netstat. Pass -n to netstat when you invoke it to skip resolution and it'll often return immediately.

The other cause of the delay is if you use the -p (-b in Windows) to return the process owner since some processes don't like to be queried if you're not root/Administrator.

7
  • There are times (99%) when this does not happen at all. But when it happens, it happens for a few minutes, even on subsequent calls. Doesn't the DNS have some sort of caching system? Could it happen that the DNS is slow only at specific times?
    – Daniele B
    Apr 3, 2014 at 14:55
  • Also, while this happens, also my network calls seem affected (about 5 seconds delay is added on each)
    – Daniele B
    Apr 3, 2014 at 14:56
  • 1
    If you don't control the DNS servers anything could happen (high load, routing, etc). DNS does cache things, but netstat on a busy web server for example may have thousands of different IPs at the same time. Try the -n switch during periods of slowness to see what happens.
    – Nathan C
    Apr 3, 2014 at 14:57
  • @DanieleB you can use nscd to cache lookups Apr 3, 2014 at 15:17
  • 1
    All (or nearly all) lookups. It also caches user and group lookups too, thats usually only important if you use ldap as a name service backend. Apr 3, 2014 at 15:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .