Can anyone recommend a linux command line tool to monitor the number of bytes transferred between the local server and a specified IP address/port.
The equivalent tcpdump command would be:
tcpdump -s 0 -i any -w mycapture.trc port 80 host google.com
which outputs :
46 packets captured
131 packets received by filter
0 packets dropped by kernel
I'd like something similar that outputs:
54 bytes out, 176 bytes in
I'd like it to work on RHEL and be free/open-source. It would be good if there was an existing tool which I was just missing too!
You could use iptables. If you're not already using it, you can use an open Accept configuration, but have a rule in place to do the counting.
For example, on RHEL your
/etc/sysconfig/iptables
file could look something like:Where 10.10.1.1:80 is the host:port you want to count traffic to (you can't use a hostname). You can then check traffic counted with the command
iptables -nvxL
as root.Example output:
I was about to suggest wireshark (for it's many 'conversation' features), but it is not a command-line tool. You could try tshark though, which is a command-line analyzer tool that is closes to wireshark. The output should have (somewhat) what you're looking for (example below):
Result:
There is also a tool called 'iftop' which displays bandwidth usage on an interface by host. I think iftop can do what you described but normally its interface is something like 'top'.
So for your example, I think that you can just create config file to provide your filter-code.
So here is my filter-code in my config file.
Then, I ran the following to see the network traffice.
Not sure if this is the best option but certainly one way to achieve what you need. HTH.
You can also try "iptraf" it's lightweight and simple. It can filter by port and gives you high level info, no payload data, etc.