views:

178

answers:

1

Hi,

So I have a FreeBSD router running PF and Squid, and it has three network interfaces: two connected to upstream providers (em0 and em1 respectively), and one for LAN (re0) that we serve. There is some load balancing configured with PF. Basically, it routes all traffic to ports 1-1024 through one interface (em0) and everything else through the other (em1).

Now, I have a Squid proxy also running on the box that transparently redirects any HTTP request from LAN to port 3128 in 127.0.0.1. Since Squid redirects this request to HTTP outside, it should follow the load balancing rule through em0, no? The problem is, when we tested it out (by browsing from a computer in the LAN to http://whatismyip.com, it reports the external IP of the em1 interface! When we turn Squid off, the external IP of em0 is reported, as expected.

How do I make Squid behave with the load balancing rule that we have set up?

Here's the related settings in /etc/pf.conf that I have:

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

I have tried appending the following rule, but it did nothing:

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

Thanks!

+1  A: 

If you want all outgoing squid requests to go to a specific IP address on a specific interface, you should be able to use the "tcp_outgoing_address" option in squid.conf to specify an IP address on em0.

janm