# 2 gateways on one NIC - auto fallover



## chrcol (Sep 23, 2011)

Ok basically I have 2 load balancer servers in front of a load of FreeBSD servers.  All the FreeBSD servers connect to the net via nat so one of the lb servers is the active gateway.  What I need to do is have it so when the first lb server goes down, the FreeBSD servers automatically start using the 2nd lb server as the nat gateway without intervention from me.  I am assuming I can add a second gateway/router with a lower priority than the default.  As I can on windows machines.  Is this possible and if so how? thanks.


----------



## ecazamir (Sep 23, 2011)

FreeBSD does not allow two routes to the same destination at the same time.
A routing protocol should be useful (bgpd, ospfd) if the gateways configuration do not use pfsync and doesn't allow transparent failover.


----------



## aragon (Sep 23, 2011)

CARP
Heartbeat

Both available on FreeBSD AFAIK.

Heartbeat is more tailored to building redundant application servers, while CARP seems to be more tailored to building redundant firewalls.  I'm sure either can serve both purposes though.


----------



## redw0lfx (Sep 23, 2011)

You should look into using Heartbeat on both gateways.  Configure with a virtual ip resource that fails over between them.  You would configure your servers to use the virtual ip for the gateway, which will bounce between both gateways.  The beauty out of using heartbeat, is that you can also have it run other apps/tasks/scripts during the failover.


----------



## chrcol (Oct 1, 2011)

I ended up using keepalived, heartbeat has horrific documentation and looks over complicated.

It's odd that FreeBSD has no native dual gateway function though, seems a very basic omission.

thanks.


----------



## wolfie (Oct 1, 2011)

Unless I've not understood what you've outlined, this is easily doable using Common Address Redundancy Protocol (CARP), which is build into the kernel. CARP will do the heartbeat monitoring as well and fail over automatically when required.

Check out the Handbook section and also CARP(4).

You may also want to check PFSYNC(4) which provides automatic pf state syncing between gateways.


----------

