iptables使用tee模块镜像流量

一般的流量镜像需要在交换机上做,实际上iptables也有个tee模块做流量镜像。在OpenWrt里使用也比较简单。
1. 把tee模块安装上加载进去(需要依赖ipv6模块)
[bash]
opkg install kmod-ipt-tee

2.把某个源IP的包镜像发到指定的IP
iptables -t mangle -A PREROUTING -s 192.168.3.224 -j TEE –gateway 192.168.3.100

3. 把某个目的IP的包镜像到指定的IP
iptables -t mangle -A POSTROUTING -d 192.168.3.224 -j TEE –gateway 192.168.3.100

4. 删除规则
iptables -t mangle -F

5. 也可以把整个网段的都镜像
root@wan:/etc/config# iptables -t mangle -A PREROUTING -s 192.168.3.0/24 -j TEE –gateway 192.168.3.100
root@wan:/etc/config# iptables -t mangle -A POSTROUTING -d 192.168.3.0/24 -j TEE –gateway 192.168.3.100
[/bash]
这样当192.168.3.224这个IP有通信的时候,流量都会被镜像到192.168.3.100这个机器上面,可以在上面直接抓包查看。

tee

上图是抓包手机 微博和易讯客户端打开的的DNS查询。

此条目发表在net, OpenWrt分类目录。将固定链接加入收藏夹。