I have a site with video content (mp4 files).

When people are watching videos, they are downloading video files from my site. I want to know the number of the active connections via the linux terminal. They are probably TCP packets on port 80.


$ netstat -an |grep :80 | wc -l

gives a huge number, ~6-7k. I don't think that this is correct?


netstat on Linux is obsolete and was replaced by ss which you should use instead.

Something like this ought to give you what you want:

$ ss -H state established '( sport = :https )' | wc -l

This selects connections on port 443 which are currently established, i.e. connected to a remote host, excluding those which are in the process of closing.

netstat -an

will give you active connections, along with EVERYTHING else. This includes things like listening ports etc..

If you are limited to only using netstat, you should be able to count out the number of established connections using something like:

netstat -an | grep -w "<listening ip>:80" | grep ESTABLISHED | wc -l

which is a bit of a hack, but works by just counting the number of established connections coming in to your listening ip, on port 80.

If you can install ss, or have it already installed:

ss -nt dst <ip webserver is listening on>:80 | wc -l

The above should give you a count of all connections with a destination of your listening ip address on port 80.

If you are looking for unique connections you could even narrow it down more by using "sort" and then "uniq -c" (foregoing "wc -l") to get a count to unique connections as well.

ss is super useful: https://linux.die.net/man/8/ss

  • Why do you limit it to IPv4 connections? Also your command will count both incoming and outgoing connections, which may not be what he wants. – Michael Hampton Jul 6 '18 at 19:51
  • Good point. edited answer. TY! – frontsidebus Jul 6 '18 at 19:57
  • -jailshell: ss: command not found. i dont have it and i cant install it. im on shared hosting – KoSMoS Jul 6 '18 at 20:09
  • edited my original answer with a solution that will just use netstat. It's a bit hacky, but it should work as well. – frontsidebus Jul 6 '18 at 21:01
  • @KoSMoS If you are on shared hosting, you can't really differentiate your connections from other people's via any of these methods. – Michael Hampton Jul 6 '18 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.