将LDAP通信从应用程序服务器路由到代理到Internet

在这里输入图像说明

我已经包含了一个绘图,所以你知道它是如何工作的。 (红色= LDAP连接,蓝色= HTTP / AJP在后端)

问题:我们希望将客户应用程序服务器连接到客户的LDAP(或者让他们这样做)。

现在,如果我们用应用程序服务器的公共接口来做到这一点,那么我们希望随着时间的推移禁用这个接口。 我们希望将所有需要的stream量路由到代理,并将数据包传送到目的地。

现在这也将用于其他服务,但主要的是LDAP(如果我们有LDAP的话,configuration额外的服务并不那么困难)。 我们不想redirect所有的stream量,因为我们仍然需要stream量来到我们的后端服务(数据库等)。

解决scheme将是:

  1. 从应用程序服务器启动LDAP请求。
  2. 将所有LDAP请求+stream量从应用程序服务器发送到eth1到代理eth1
  3. 将所有来自eth1的LDAP通信redirect到eth0(代理),以便能够访问Internet。

我想知道如何用IPTABLES以最安全和可扩展的方式来解决这个问题(使之自动化)。

所以我正在寻找最好的IPTABLES解决scheme来实现我们的应用服务器和代理

编辑:

使用2个stream浪箱进行testing: 主机0 =应用程序服务器主机1 =代理

仍然与此结合。 但是我越来越近了。

我的所有LDAPstream量正在发送到代理服务器,但我只是得到[S]和[S.]回来,没有连接。

这是我做的。

应用服务器:

iptables -t mangle -A OUTPUT -p tcp --dport 389 -j MARK --set-mark 0x1 iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE $echo 1 LDAP >> /etc/iproute2/rt_tables $ip rule add fwmark 0x1 lookup LDAP $ip route add default via 192.168.1.2 table LDAP [root@host0 ~]# sysctl -A | grep rp_filter net.ipv4.conf.all.rp_filter = 0 net.ipv4.conf.all.arp_filter = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.arp_filter = 0 net.ipv4.conf.lo.rp_filter = 1 net.ipv4.conf.lo.arp_filter = 0 net.ipv4.conf.eth0.rp_filter = 1 net.ipv4.conf.eth0.arp_filter = 0 net.ipv4.conf.eth1.rp_filter = 1 net.ipv4.conf.eth1.arp_filter = 0 [root@host0 ~]# sysctl -A | grep net.ipv4.ip_forward net.ipv4.ip_forward = 1 

代理 :

 iptables -t nat -A POSTROUTING -p tcp -o eth0 --dport 389 -j SNAT --to 10.0.2.15 [root@host1 ~]# sysctl -A | grep rp_filter net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.all.arp_filter = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.arp_filter = 0 net.ipv4.conf.lo.rp_filter = 1 net.ipv4.conf.lo.arp_filter = 0 net.ipv4.conf.eth0.rp_filter = 1 net.ipv4.conf.eth0.arp_filter = 0 net.ipv4.conf.eth1.rp_filter = 1 net.ipv4.conf.eth1.arp_filter = 0 [root@host1 ~]# sysctl -A | grep net.ipv4.ip_forward net.ipv4.ip_forward = 1 

这是应用程序服务器的eth1(专用)上的tcpdump

 13:31:51.629687 IP 192.168.56.10.59528 > ec2-23-20-46-132.compute-1.amazonaws.com.ldap: Flags [S], seq 1571039960, win 14600, options [mss 1460,sackOK,TS val 18491218 ecr 0,nop,wscale 3], length 0 13:31:51.749145 IP ec2-23-20-46-132.compute-1.amazonaws.com.ldap > 192.168.56.10.59528: Flags [S.], seq 1604232705, ack 1571039961, win 65535, options [mss 1460], length 0 13:31:52.630908 IP 192.168.56.10.59528 > ec2-23-20-46-132.compute-1.amazonaws.com.ldap: Flags [S], seq 1571039960, win 14600, options [mss 1460,sackOK,TS val 18492219 ecr 0,nop,wscale 3], length 0 13:31:54.633277 IP 192.168.56.10.59528 > ec2-23-20-46-132.compute-1.amazonaws.com.ldap: Flags [S], seq 1571039960, win 14600, options [mss 1460,sackOK,TS val 18494222 ecr 0,nop,wscale 3], length 0