【发布时间】:2010-06-27 21:02:41
【问题描述】:
所以我有一个运行 PF 和 Squid 的 FreeBSD 路由器,它有三个网络接口:两个连接到上游提供商(分别为em0 和em1),一个用于我们服务的 LAN(re0)。有一些使用 PF 配置的负载平衡。基本上,它通过一个接口 (em0) 将所有流量路由到端口 1-1024,并通过另一个接口 (em1) 将其他所有流量路由到端口。
现在,我还在盒子上运行了一个 Squid 代理,它将任何来自 LAN 的 HTTP 请求透明地重定向到 127.0.0.1 中的端口 3128。既然 Squid 把这个请求重定向到外面的 HTTP,它应该通过em0 遵循负载均衡规则,不是吗?问题是,我们在测试的时候(从局域网内的电脑浏览到http://whatismyip.com,报em1接口的外部IP!当我们关闭squid时,报em0的外部IP ,正如预期的那样。
如何使 Squid 符合我们设置的负载平衡规则?
这是我在/etc/pf.conf 中的相关设置:
ext_if1="em1" # DSL
ext_if2="em0" # T1
int_if="re0"
ext_gw1="x.x.x.1"
ext_gw2="y.y.y.1"
int_addr="10.0.0.1"
int_net="10.0.0.0/16"
dsl_ports = "1024:65535"
t1_ports = "1:1023"
...
squid=3128
rdr on $int_if inet proto tcp from $int_net \
to any port 80 -> 127.0.0.1 port $squid
pass in quick on $int_if route-to lo0 inet proto tcp \
from $int_net to 127.0.0.1 port $squid keep state
...
# load balancing
pass in on $int_if route-to ($ext_if1 $ext_gw1) \
proto tcp from $int_net to any port $dsl_ports keep state
pass in on $int_if route-to ($ext_if1 $ext_gw1) \
proto udp from $int_net to any port $dsl_ports
pass in on $int_if route-to ($ext_if2 $ext_gw2) \
proto tcp from $int_net to any port $t1_ports keep state
pass in on $int_if route-to ($ext_if2 $ext_gw2) \
proto udp from $int_net to any port $t1_ports
pass out on $ext_if1 route-to ($ext_if2 $ext_gw2) from $ext_if2 to any
pass out on $ext_if2 route-to ($ext_if1 $ext_gw1) from $ext_if1 to any
我尝试添加以下规则,但它什么也没做:
pass in on $int_if route-to ($ext_if2 $ext_gw2) \
proto tcp from 127.0.0.1 to any port $t1_ports keep state
谢谢!
【问题讨论】:
-
在网上搜索档案后,我能找到的最接近的是unsolved discussion。
标签: firewall load-balancing freebsd bsd squid