将 LDAP 流量从应用程序服务器路由到代理再到互联网

将 LDAP 流量从应用程序服务器路由到代理再到互联网

在此处输入图片描述

我附上了一张图,以便您了解它的工作原理。(红色 = LDAP 连接,蓝色 = 后端的 HTTP / AJP)

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

现在,如果我们使用应用服务器的公共接口执行此操作,这将很容易,但我们希望随着时间的推移禁用此接口。我们希望将所有需要出去的流量路由到代理,然后代理会将数据包传送到目的地。

现在这也将用于其他服务,但主要的是 LDAP(如果我们有 LDAP,配置额外的服务并不难)。我们不想重定向所有流量,因为我们仍然需要流量到我们的后端服务(数据库等...)。

解决方案是:

  1. 从应用程序服务器启动 LDAP 请求。
  2. 将所有 LDAP 请求 + 流量从应用服务器发送到 eth1 到代理 eth1
  3. 将所有 LDAP 流量从 eth1 重定向到 eth0(代理)以便能够访问互联网。

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

所以我在寻找最好的 IPTABLES 解决方案在我们的应用服务器和代理上实现

编辑 :

使用 2 个 vagrant boxes 进行测试: Host0 = 应用服务器 Host1 = 代理

仍在为此努力。但我已更进一步。

我的所有 LDAP 流量都被发送到代理并返回,但我只得到了 [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

相关内容