iptables 实现流量监控,重定向: 一

iptables 重定向可以使用如下命令:
iptables配置规则:

iptables -t nat -A PREROUTING -p tcp --dport 80 -s 192.168.1.223 -j DNAT --to 61.55.167.115

其中: 192.168.1.223是需要实现IP重定向的设备IP地址
61.55.167.115 指明了重定向到何处

iptables 显示每个客户端的使用流量情况:
参考:
http://blog.csdn.net/chang198932/article/details/39481115
脚本内容如下:

#!/bin/sh
# @Create on 2013-12-01

echo "Collecting data..."
echo ""
cat /proc/net/arp | grep : | grep 192 | grep -v 00:00:00:00:00:00| awk '{print $1}'> mac-ip
iptables -N UPLOAD
iptables -N DOWNLOAD
while read line;do iptables -I FORWARD 1 -s $line -j UPLOAD;done < mac-ip
while read line;do iptables -I FORWARD 1 -d $line -j DOWNLOAD;done < mac-ip

sleep 1

echo "Download speed:"
echo ""
iptables -nvx -L FORWARD | grep DOWNLOAD | awk '{print $2/1024/1" KB/s ",$1/10" packets/s", $9}' |
echo ""
echo "Upload speed:"
echo ""
iptables -nvx -L FORWARD | grep UPLOAD | awk '{print $2/1024/1" KB/s ",$1/10" packets/s", $8}' | s

while read line;do iptables -D FORWARD -s $line -j UPLOAD;done < mac-ip
while read line;do iptables -D FORWARD -d $line -j DOWNLOAD;done < mac-ip
iptables -X UPLOAD
iptables -X DOWNLOAD

你可能感兴趣的:(iptables,Openwrt,教程,linux,iptables,重定向,流量监控,防火墙)