Monday, October 19, 2009

FreeBSD and multiple gateways

Question: How to add multiple gateways to a FreeBSD?
Answer: No you can not do this (at least directly) on FreeBSD. FreeBSD don't support multiple gateways.
Workaround solution: If you have a server with 2 set of IPs and each set have there own gateway.

  • First, you must select one of the gateway to be a default gateway.
  • Then, You need ipfw (or any FreeBSD firewall solution),
    Check that your kernel support ipfw, if not, recompile your kernel with the following options(IPDIVERT and DUMMYNET is not required, but if you add IPFW/IPFW2 it better to also add these two options)
    #Firewall & NAT & DummyNet 
    options IPFIREWALL
    options IPDIVERT
    options DUMMYNET
    options IPFW2
    add the following rule to your ipfw rules set.
     ipfw add rule_no fwd second_gateyway_ip ip from ip_of_this_gateway to not me
    For example, I have 2 ip set (,, for gateway and (, for gateways I chose as the default gateway. So, my ipfw rules are
     ipfw add 100 fwd ip from to not me
    ipfw add 110 fwd ip from to not me

No comments: