iptables预路由redirect以太网上的源IP地址

互联网上有两个ip地址在同一台机器上redirect。 在这台机器上,一个Debian在OpenVZ上运行。 我可以设置iptables规则来redirect所有http请求到Debian。

iptables prerouting -d ip_address_2 DNAT --to ip_address_local_1 +--------------+ | | | V | 10.10.101.5 I| +------+ +----------+ N|ip_address_1 | |-----|Debian1 VE|-- Apache's log T|-----------------|OpenVZ| +----------+ [client ip_address_1] E| | | | R|ip_address_2 | | | N|--------------+ | | E| +------+ T| 

iptables的规则:

 iptables -t nat -A PREROUTING -p tcp -i eth0 -d ip_address_2 --dport 80 -j DNAT --to 10.10.101.5:80 iptables -A FORWARD -p tcp -i eth0 -o venet0 -d 10.10.101.5 --dport 80 -j ACCEPT iptables -A FORWARD -p tcp -i venet0 -o eth0 -s 10.10.101.5 --sport 80 -j ACCEPT 

当我去“ http:// ip_address_2 ”的网页,我可以看到好的内容,但访问日志文件上的IP地址是ip_address_1,我想看看我的ISP的IP地址。

如果我input:

 # iptables -t nat -L -n Chain PREROUTING (policy ACCEPT) target prot opt source destination DNAT tcp -- 0.0.0.0/0 ip_address_2 tcp dpt:80 to:10.10.101.5:80 Chain POSTROUTING (policy ACCEPT) target prot opt source destination MASQUERADE all -- 0.0.0.0/0 0.0.0.0/0 SNAT all -- 10.10.101.5 0.0.0.0/0 to:ip_address_2 Chain OUTPUT (policy ACCEPT) target prot opt source destination 

有任何想法吗?

也许这就像在httpdconfiguration中添加Listen ip.add.re.ss2:80一样简单?

并删除任何Listen 80指令,以确保服务器只提供您想要的IP地址。

我只是重新读你的iptables规则; 你从端口80上的ip2发送stream量到端口80上的ip1 …当然你的日志将显示ip1。 您在stream量到达服务器之前将stream量redirect。