首页 文章

PF,负载 balancer 网关和Squid

提问于
浏览
0

所以我有一个运行PF和Squid的FreeBSD路由器,它有三个网络接口:两个连接到上游提供商(分别为 em0em1 ),另一个用于我们服务的LAN( re0 ) . 有一些负载均衡配置PF . 基本上,它通过一个接口( em0 )将所有流量路由到端口 1-1024 ,而通过另一个接口( em1 )将所有其他流量路由到端口 1-1024 .

现在,我还在框上运行了一个Squid代理,它透明地将任何来自LAN的HTTP请求重定向到 127.0.0.1 中的端口 3128 . 由于Squid将此请求重定向到HTTP外部,它应该遵循负载 balancer 规则 em0 ,不是吗?问题是,当我们测试它时(通过从局域网中的计算机浏览到http://whatismyip.com,它报告 em1 接口的外部IP!当我们关闭Squid时,报告 em0 的外部IP,如预期的那样 .

如何使用我们设置的负载 balancer 规则使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

谢谢!

1 回答

  • 1

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

相关问题