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.
Related videos on Youtube
Author by
Daniele B
Updated on September 18, 2022Comments
-
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 about 10 yearsThere 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 about 10 yearsAlso, while this happens, also my network calls seem affected (about 5 seconds delay is added on each)
-
Nathan C about 10 yearsIf 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 about 10 years@DanieleB you can use
nscd
to cache lookups -
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 about 10 yearsAll (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 almost 3 yearsThank you so much, we went from netstat taking well over 20 minutes to just a few seconds!