Netstat hangs: why?

9,586

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.

Share:
9,586

Related videos on Youtube

Daniele B
Author by

Daniele B

Updated on September 18, 2022

Comments

  • Daniele B
    Daniele B almost 2 years

    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?

  • Daniele B
    Daniele B about 10 years
    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
    Daniele B about 10 years
    Also, while this happens, also my network calls seem affected (about 5 seconds delay is added on each)
  • Nathan C
    Nathan C about 10 years
    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.
  • Matthew Ife
    Matthew Ife about 10 years
    @DanieleB you can use nscd to cache lookups
  • Daniele B
    Daniele B about 10 years
    @MatthewIfe, does this apply only to netstat lookups or to any domain lookup? I am asking this because I am not too worry about netstat (as Nathan said, you can always use -n). I am most worried for the slowdown to the network calls of my server-side application.
  • Matthew Ife
    Matthew Ife about 10 years
    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.
  • Jake Steffen
    Jake Steffen almost 3 years
    Thank you so much, we went from netstat taking well over 20 minutes to just a few seconds!