简单的端口转发

我已经search和search,尝试了几个不同的东西,并没有能够find解决办法。

这是我的情况:

node1有两个接口: eth0 (公网IP:56.XXX)和eth1 (私网IP:10.XXX)

node2有两个接口: eth0 (公网IP:56.XXX)和eth1 (私网IP:10.XXX)

每个节点都运行Ubuntu 10.04 LTS

从这个设置节点1节点2每个都可以访问互联网,但也可以通过局域网相互连接。

我想要完成的是将node1作为node2防火墙代理服务器 ,以及稍后部署的许多其他节点。 节点1将有唯一的互联网接入,因为我将禁用节点2上的eth0 ,使节点2​​只能访问其私有networking上的任何东西。

简而言之,如何将转发到node1eth0www请求转发到使用eth1的 node2,node2将作为该请求的Web服务器?

按照下面的例子,这里是我的iptables -L:

Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- anywhere 10.182.43.193 state NEW tcp dpt:www ACCEPT tcp -- anywhere 10.182.43.193 state NEW tcp dpt:https ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination 

这是我的iptables -t nat -L

 Chain PREROUTING (policy ACCEPT) target prot opt source destination DNAT all -- anywhere firewall to:10.182.43.193 Chain OUTPUT (policy ACCEPT) target prot opt source destination Chain POSTROUTING (policy ACCEPT) target prot opt source destination 

我将分配一些任意的IP地址来清除。 replace你的真实地址。

node1 eth0:56.0.0.1 node1 eth1:10.0.0.1 node2 eth0:56.0.0.2 node2 eth1:10.0.0.2

如果node1是您的网关/防火墙机器,您将需要运行iptables来处理NAT /转发。

 # iptables config on node1 # set up a destination nat from 56.0.0.2 to 10.0.0.2 iptables -t nat -A PREROUTING -d 56.0.0.2 -j DNAT --to-destination 10.0.0.2 # open port 80/443 iptables -A INPUT -d 10.0.0.2 -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT iptables -A INPUT -d 10.0.0.2 -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT # related/established traffic iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 

您不需要configurationnode2上的eth0。 相反,您需要在node1上configuration56.0.0.2 IP地址,以便唯一地使用它来映射到node2。

如果node2应该有自己的IP地址,那么你不需要端口转发,你需要代理ARP和路由。

在node2上禁用eth0并将公共IP添加到任何其他接口,例如:

 ip addr add 56.0.0.2/32 dev eth1 

在node1上通过eth1build立到node2的路由:

 ip route add 56.0.0.2 dev eth1 

并在eth0上启用代理ARP响应(因此,node1将响应node2的ARP请求):

 echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp 

这将使所有到node2的stream量都经过node1。 然后,您可以设置iptables规则来限制它像其他任何转发stream量。 这不会执行任何应用程序级别的代理,但是您仍然可以使用iptables规则来实现这一点。

永久设置这些通常取决于分配,我不太了解Ubuntu,但'proxy_arp'设置可以在/etc/sysctl.conf中设置:

 net.ipv4.conf.eth0.proxy_arp = 1 

在node2的eth1上的IP地址应该被添加到接口configuration中(但是没有任何networking掩码或者前缀长度为'/ 32'),那么也应该有一个地方把静态路由(/ etc / sysconfig / static-系统)。