Linux 桥接器可以拦截流量吗?

Linux 桥接器可以拦截流量吗?

我有一台 Linux 机器设置为客户端和服务器之间的桥梁;

brctl addbr0
brctl addif br0 eth1
brctl addif br0 eth2
ifconfig eth1 0.0.0.0
ifconfig eth2 0.0.0.0
ip link set br0 up

我还有一个应用程序正在监听这台机器的 8080 端口。是否可以将发往 80 端口的流量传递给我的应用程序?我做了一些研究,看起来可以使用ebtables和来完成iptables

以下是我的其余设置:

//set the ebtables to pass this traffic up to ip for processing; DROP on the broute table should do this
ebtables -t broute -A BROUTING -p ipv4 --ip-proto tcp --ip-dport 80 -j redirect --redirect-target DROP

//set iptables to forward this traffic to my app listening on port 8080
iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TPROXY --on-port 8080 --tproxy-mark 1/1
iptables -t mangle -A PREROUTING -p tcp -j MARK --set-mark 1/1

//once the flows are marked, have them delivered locally via loopback interface
ip rule add fwmark 1/1 table 1
ip route add local 0.0.0.0/0 dev lo table 1

//enable ip packet forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

但是什么都没有进入我的应用程序。我遗漏了什么吗?我的理解是,bro​​ute BROUTING 链上的目标 DROP 会将其推送到 iptables 进行处理。

其次,我还应该研究其他什么替代方案吗?

编辑:IPtables 在 nat PREROUTING 处获取它,但是看起来它在那之后丢失了;INPUT 链(在 mangle 或 filter 中)看不到该数据包。

答案1

我决定保留桥接行为。我将使用 ebtables 来阻止我想要拦截的流量,并让我的应用程序使用原始套接字来拦截这些数据包。这似乎有点不切实际,但似乎有效。

相关内容