Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to monitor the number of incoming and outgoing network connections. I can get the total number with netstat and wc -l, but I want to know how many are inbound and how many are outbound.

share|improve this question
what do you mean by inbound/outbound? please be specific. – Farhan Nov 24 '11 at 17:31
You mean netstat instead of netcat? – quanta Nov 25 '11 at 7:07
up vote 3 down vote accepted

You can accomplish that by using ip_conntrack.

modprobe ip_conntrack
cat /proc/net/ip_conntrack

The established connections that have the source address equal to your interface's address are the outgoing connections.

The established connections that have the destination address equal to your interface's address, are the incoming connections.

# Number of outgoing connections
cat /proc/net/ip_conntrack | grep "ESTABLISHED" | grep "" | wc -l

# Number of incoming connections
cat /proc/net/ip_conntrack | grep "ESTABLISHED" | grep "" | wc -l

( is obviously your interface's ip address)

Keep in mind that there are connections that occur for inter-process communication, between applications running on your system.

You can find information about ip_conntrack entries here.

share|improve this answer

You can monitor all the incoming and outgoing connections with iftop.

If you want to get some statistics

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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