【问题标题】:PF, load balanced gateways, and SquidPF、负载平衡网关和 Squid
【发布时间】:2010-06-27 21:02:41
【问题描述】:

所以我有一个运行 PF 和 Squid 的 FreeBSD 路由器,它有三个网络接口:两个连接到上游提供商(分别为em0em1),一个用于我们服务的 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

谢谢!

【问题讨论】:

标签: firewall load-balancing freebsd bsd squid


【解决方案1】:

如果您希望所有传出的 squid 请求都转到特定接口上的特定 IP 地址,您应该能够使用 squid.conf 中的“tcp_outgoing_address”选项来指定 em0 上的 IP 地址。

【讨论】:

    猜你喜欢
    • 2015-10-28
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    • 2019-07-17
    • 2012-04-25
    • 2011-04-21
    • 1970-01-01
    • 2021-04-28
    相关资源
    最近更新 更多