remetremet / RMT_ipfw

Automated FreeBSD IPFW2 (up to 20x WAN, up to 20x LAN, NAT, dualstack, QoS, traffic shaping, statefull or stateless. For a router, desktop, server, VPN server, ...
BSD 2-Clause "Simplified" License
7 stars 0 forks source link

Failover / Load balancing of multiple WANs #48

Open ztaozhang opened 2 years ago

ztaozhang commented 2 years ago

Hi, how to implement it.

remetremet commented 2 years ago

Let's assume you use a FreeBSD router. So there are FIBs - it must be enable in "/boot/loader.conf" and you set the number of FIBs (number of ISPs) you want. Maximum is 16 I think.

So now after restart you have multiple routing tables (one in each FIB) with multiple default GW (for each one ISP).

Failover is simple - tag your packets in firewall with FIB/ISP you want to use for the packet. And switch this settings by ISP availability. I'm using "ipfw sets" for this.

You can load balance your traffic based on source device/IP and/or destination server/IP easily (all traffic from PC 1 to ISP 2, all traffic from PC 2 to ISP 1, ...), you can load balance you traffic based on port/protocol/service (all SMTP via ISP 1, all HTTP via ISP 2).

The problem with load balancing is modern encrypted protocols - there are solutions to use statefull firewall to keep each session via single ISP so you will not disrupt SSL/TLS connection (for example), but as I tested it, it's not 100% :-( So I better stay with IP and port based load balancing (as I'm using it in this code).