监视传输到/从端口上的IP地址的字节数

任何人都可以推荐一个Linux命令行工具来监视本地服务器和指定的IP地址/端口之间传输的字节数。

等效的tcpdump命令是:

tcpdump -s 0 -i any -w mycapture.trc port 80 host google.com

其输出:

 46 packets captured 131 packets received by filter 0 packets dropped by kernel 

我想要类似的输出:

 54 bytes out, 176 bytes in 

我希望它在RHEL上工作,并且是免费/开源的。 如果有一个我现在只是缺less的工具,那将是一件好事!

你可以使用iptables。 如果你还没有使用它,你可以使用一个打开的接受configuration,但有一个规则来做计数。

例如,在RHEL上,您的/etc/sysconfig/iptables文件可能如下所示:

 *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A FORWARD -j INPUT -A INPUT -s 10.10.1.1 -p tcp -m tcp --sport 80 -j ACCEPT -A OUTPUT -d 10.10.1.1 -p tcp -m tcp --dport 80 -j ACCEPT 

10.10.1.1:80是主机端口:你想要统计stream量(你不能使用主机名)。 然后,您可以检查使用命令iptables -nvxL作为根计数的stream量。

示例输出:

 Chain INPUT (policy ACCEPT 7133268 packets, 1057227727 bytes) pkts bytes target prot opt in out source destination 7133268 1057227727 ACCEPT tcp -- * * 10.10.1.1 0.0.0.0/0 tcp spt:80 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 INPUT all -- * * 0.0.0.0/0 0.0.0.0/0 Chain OUTPUT (policy ACCEPT 7133268 packets, 1057227727 bytes) pkts bytes target prot opt in out source destination 7133268 1057227727 ACCEPT tcp -- * * 0.0.0.0/0 10.10.1.1 tcp dpt:80 

还有一个名为“iftop”的工具,它显示主机在一个接口上的带宽使用情况。 我认为iftop可以做你所描述的,但通常它的界面就像“顶”。

所以对于你的例子,我认为你可以创buildconfiguration文件来提供你的过滤代码。

所以这里是我的configuration文件中的过滤代码。

 $ cat /tmp/conf filter-code: port http and host google.com 

然后,我跑了以下看到networking交易。

 $ sudo iftop -c /tmp/conf 

不知道这是否是最好的select,但肯定是一种方法来实现你所需要的。 HTH。

我正要build议wireshark(因为这是很多' 对话 'function),但它不是一个命令行工具。 你可以尝试tshark ,这是一个接近wireshark的命令行分析工具。 输出应该(有点)你正在寻找(例如下面):

 tshark -R "ip.addr == 10.2.3.67" -z conv,ip -p -f "tcp port 22" 

结果:

  | <- | | -> | | Total | | Frames Bytes | | Frames Bytes | | Frames Bytes | 10.2.3.23 <-> 10.2.3.67 42 15341 35 4890 77 20231 

你也可以尝试“iptraf”,它是轻量级和简单的。 它可以通过端口进行过滤,并为您提供高级信息,无有效载荷数据等。