
查看nat路由表的流量
iptables -nvL -t nat
如果不指定路由表名,则默认为filter表
# 默认查看filter表
iptables -nvL
抓取mangle表中含有192.168的全部表链信息包
iptables -nvxL -t mangle | grep 192.168| awk '{print $2" | "$8" | "$9}'
iptables -nvxL -t mangle | grep 192.168| awk '{if($2>0){print $2" | "$8" | "$9}}'
iptables -nvxL -t mangle | grep 192.168| awk '{flow+=$2}END{print flow}'
filter表查看指定ip,当存在流量值大于0时显示
iptables -nvxL -t filter | grep 192.168.201.10 | awk '{if($2>0){print $2" | "$8" | "$9}}'
iptables -nvxL -t filter | grep 192.168.201.11| awk '{if($2>0){print $2" | "$8" | "$9}}'
iptables -nvxL -t filter | grep 192.168.201.12| awk '{if($2>0){print $2" | "$8" | "$9}}'
iptables -nvxL -t filter | grep 192.168.201.13| awk '{if($2>0){print $2" | "$8" | "$9}}'
iptables -nvxL -t filter | grep 192.168.201.14| awk '{if($2>0){print $2" | "$8" | "$9}}'
只抓取mangle表中POSTROUTING链信息包(含有192.168)
iptables -nvxL POSTROUTING -t mangle | grep 192.168| awk '{print $2" | "$8" | "$9}'
iptables -nvxL POSTROUTING -t mangle | grep 192.168| awk '{if($2>0){print $2" | "$8" | "$9}}'
iptables -nvxL POSTROUTING -t mangle | grep 192.168| awk '{flow+=$2}END{print flow}'
只抓取mangle表中POSTROUTING链信息包(含有192.168),打印出来后,并清除mangle表数据
iptables -t mangle -nvxL POSTROUTING | grep 192.168 | awk '{print $2" | "$8" | "$9}' && iptables -t mangle -Z
统计mangle表流量数据(shell脚本)
#!/bin/sh
# 统计mangle表流量数据,定时统计,并写入文件,统计完清除mangle表数据
result=`/sbin/iptables -nvxL -t mangle | grep 192.168| awk '{flow+=$2}END{print flow}'`
if [ "$result" -gt "0" ];then
echo -n `date +%Y%m%d%H%M%S:` >> /root/mangle.txt
echo $result >> /root/mangle.txt
/sbin/iptables -t mangle -Z
fi
网友评论