iptables将单个网站stream量redirect到端口8080

我的目标是能够通过代理与一个,并且只有一个网站build立连接。 其他一切都应该放弃。

我已经能够成功地做到这一点,没有这个代码的代理:

./iptables -I INPUT 1 -i lo -j ACCEPT ./iptabels -A OUTPUT -p udp --dport 53 -j ACCEPT ./iptables -A OUTPUT -p tcp -d www.website.com --dport 80 -j ACCEPT ./iptables -A INPUT -m conntrack --cstate ESTABLISHED,RELATED -j ACCEPT ./iptables -P INPUT DROP ./iptables -P OUTPUT DROP 

除了将stream量redirect到8080端口,我怎么能做同样的事情呢? 我一直试图在PRATOUTING链在nat表中redirect。 我不确定这是否适合这样做的地方。

谢谢你的帮助!

我认为Web服务器configuration是更好的地方做到这一点。 请检查Apache服务器的虚拟主机configuration:

Apache vhostsconfiguration: http : //httpd.apache.org/docs/2.2/vhosts/examples.html

其他服务器有类似的configuration。 您可以指定您希望他们处理的网站(通过URL)。

除了使用iptables指定到特定域的stream量之外,您不需要删除httpstream量。 您可以使用像这样的规则将httpstream量redirect到您的代理:

 iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination proxy_ip:8080 

你需要一个运行代理服务器,支持透明代理和监听8080端口。然后你可以configuration你的代理允许/拒绝任何你想要的域名/ URL等。

请注意,在iptables规则中使用域名不是一个好主意,因为在input规则之后,iptables将不会看到name-IP映射中的更改。