# port based traffic redirection



## loko (Nov 20, 2008)

Hello,
Can you help me with the following situation:
I have two internet service providers and I am trying to redirect all internal traffic who has destination port 80 or 443 to ISP1 and all the rest to ISP2. 

Thanks in advance!


----------



## gelraen (Nov 20, 2008)

with IPFW you can do something like


```
ipfw add fwd $ISP1 ip from $internal_net to any 80 out
ipfw add fwd $ISP1 ip from $internal_net to any 443 out
```

Check ipfw(8) and handbook for more details


----------



## DutchDaemon (Nov 20, 2008)

I'm assuming you're doing this on a router running BSD? I think pf with the route-to option should be able to do what you require.

Warning: totally untested pseudocode syntax ahead


```
pass in on $int_if route-to ($ext_if1 $ext_gw1) inet proto tcp from $lan_net to any port { 80, 443 } flags S/SA modulate state
pass in on $int_if route-to ($ext_if2 $ext_gw2) inet proto tcp from $lan_net to any port { !80, !443 } flags S/SA modulate state
pass in on $int_if route-to ($ext_if2 $ext_gw2) inet proto { udp, icmp } from $lan_net to any keep state
```
You need pass out rules as well, etc.


----------

