将端口80上的stream量redirect到未知mac的apache,以及某些mac的squid

我有一个Linux的行为像一个路由器,处理两个networking接口:eth0的互联网和eth1的LAN。

我设置了iptables,以便将所有来自局域网的networkingstream量redirect到本地apache,并使用以下规则侦听端口80:

sudo iptables -t mangle -N internet sudo iptables -t mangle -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j internet sudo iptables -t mangle -A internet -j MARK --set-mark 99 sudo iptables -t nat -A PREROUTING -i eth1 -p tcp -m mark --mark 99 -m tcp --dport 80 -j DNAT --to-destination $BOX_IP 

现在,我需要为一些已知的MAC地址添加一个例外情况,以便将他们的networkingstream量redirect到apache,而不是redirect到端口3128上监听的squid代理。

我设法只是删除redirect,并让Web请求去附加这个其他规则的请求主机:

 sudo iptables -t mangle -I internet 1 -m mac --mac-source $MAC_ADDRESS -j RETURN 

但我想要的是,networkingstream量被放入$BOX_IP:3128 。 什么是最好的方式来做到这一点?

为什么你要重复所有的 – --mark 99系列的过滤标准? 你标记一个包,就是这样。 如果出现更多标准,则应更改标记,但不要检查标记以上。 顺便说一句, internet名称internet似乎相当不理想。

 #!/bin/bash if iptables -L apache -n &>/dev/null; then iptables -t mangle -F apache else iptables -t mangle -N apache fi iptables -t mangle -A apache -j MARK --set-mark 99 # finish the handling of this packet in this table iptables -t mangle -A apache -j ACCEPT if iptables -L squid -n &>/dev/null; then iptables -t mangle -F squid else iptables -t mangle -N squid fi iptables -t mangle -A squid -j MARK --set-mark 98 # finish the handling of this packet in this table iptables -t mangle -A squid -j ACCEPT if iptables -L proxy_mac_check -n &>/dev/null; then iptables -t mangle -F proxy_mac_check else iptables -t mangle -N proxy_mac_check fi for MAC_ADDRES in 11:22:33:44:55:66 11:22:33:44:55:67; do iptables -t mangle -A proxy_mac_check -m mac --mac-source $MAC_ADDRES -j squid done iptables -t mangle -A proxy_mac_check -j apache iptables -t mangle -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j proxy_mac_check iptables -t nat -A PREROUTING -m mark --mark 99 -j DNAT --to-destination $BOX_IP iptables -t nat -A PREROUTING -m mark --mark 98 -j DNAT --to-destination $BOX_IP:3128