Fortigate firewall BGP conditional advertisement with multi-home (dual ISP) configuration

In today's blog we will look at an interesting BGP feature called conditional advertisement. We will implement conditional advertisement in Fortigate firewall which is connected with two different service provider for internet connectivity.

Our topology looks like below - 

01 - Topology BGP Conditional Advertisement

We have a Fortigate firewall cluster (Active/Passive) with two service providers (ISPs). Each ISP is providing two routers for redundancy. From the customer firewall we will always use Sp-01 as primary provider for internet connectivity. We will only use Sp-02 if both routers from Sp-01 is non functional/reachable. Customer firewall will use ecmp for routing towards the active service provider. 

Customer firewall's (Internet-Fw) BGP routing policy is given below - 
  • In normal condition accept only a default route from both service provider's routers. But install only the Sp-01's advertised default route in the routing table with ecmp.
  • In normal condition advertise the firewall's internal-network (10.20.1.0/24) only to Sp-01. Suppress internal-network announcement to Sp-02 using BGP conditional advertisement.
  • When Sp-01 is not reachable (detected by removal of default route from Sp-01), use BGP conditional advertisement to announce internal-network (10.20.1.0/24) to Sp-02.
  • If Sp-01 connection is restored; withdraw the announcement of internal-network to Sp-02 and announce them only to Sp-01 again.
We will not cover the HA-configuration of the firewall in this blog. We have also configured relevant firewall rules needed for internal<->external connectivity.

For simplicity we are connecting all the internal and external networks through network switches as our main goal is to configure/verify BGP conditional advertisement from Internet-Fw's perspective.

Internal-Network is configured with 10.20.1.0/24. External-Network is configured with 10.10.11.0/24. The service provider's routers are connected back-to-back using - 10.10.12.0/24 (Sp-01) and 10.10.13.0/24 (Sp-02). All BGP connections  (ebgp and ibgp) is established with loopback interface (10.10.0.0/24).

BGP conditional advertisement configuration

Sp-01-R-01 Configuration

!!! Routing loopback interface
interface Loopback0
 description Routing-Loopback
 ip address 10.10.0.2 255.255.255.255

!!! Interface connected to Customer-Firewall
interface Ethernet0/0
 description Internet_Fw
 ip address 10.10.11.2 255.255.255.0

!!! Interface connected between Sp-01's routers.
interface Ethernet0/1
 description Sp-01-R-02
 ip address 10.10.12.1 255.255.255.0

!!! Interface connected to upstream internet router.
interface Ethernet0/2
 description Internet
 ip address 172.29.225.81 255.255.255.0

!!! BGP Configuration.
router bgp 64513
 bgp router-id 10.10.0.2
 bgp log-neighbor-changes
 no bgp default ipv4-unicast
 
 !!! EBGP neighbor - Internet-Fw configuration.
 neighbor 10.10.0.1 remote-as 64512
 neighbor 10.10.0.1 description Internet-Fw
 neighbor 10.10.0.1 ebgp-multihop 2
 neighbor 10.10.0.1 update-source Loopback0
 neighbor 10.10.0.1 ha-mode graceful-restart

 !!! IBGP neighbor - Sp-01-R-02 configuration.
 neighbor 10.10.0.3 remote-as 64513
 neighbor 10.10.0.3 description Sp-01-R-02
 neighbor 10.10.0.3 update-source Loopback0
 
 address-family ipv4
  
  !!! Advertise the default route into BGP.
  !!! No inbound/outbound route-filtering for neighbors for simplicity.
  network 0.0.0.0

  !!! Activation of Internet-FW neighbor in ipv4 address family.
  neighbor 10.10.0.1 activate
  neighbor 10.10.0.1 soft-reconfiguration inbound

  !!! Activation of Sp-01-R-02 neighbor in ipv4 address family.
  neighbor 10.10.0.3 activate
  neighbor 10.10.0.3 next-hop-self

!!! Static default route to upstream router.
ip route 0.0.0.0 0.0.0.0 172.29.225.1

!!! Static route to Internet-Fw loopback 0.
ip route 10.10.0.1 255.255.255.255 10.10.11.1

!!! Static route to Sp-01-R-02 loopback 0.
ip route 10.10.0.3 255.255.255.255 10.10.12.2


Sp-01-R-02 Configuration

interface Loopback0
 description Routing-Loopback
 ip address 10.10.0.3 255.255.255.255

interface Ethernet0/0
 description Internet_Fw
 ip address 10.10.11.3 255.255.255.0

interface Ethernet0/1
 description Sp-01-R-01
 ip address 10.10.12.2 255.255.255.0

interface Ethernet0/2
 description Internet
 ip address 172.29.225.82 255.255.255.0

router bgp 64513
 bgp router-id 10.10.0.3
 bgp log-neighbor-changes
 no bgp default ipv4-unicast

 neighbor 10.10.0.1 remote-as 64512
 neighbor 10.10.0.1 description Internet-Fw
 neighbor 10.10.0.1 ebgp-multihop 2
 neighbor 10.10.0.1 update-source Loopback0
 neighbor 10.10.0.1 ha-mode graceful-restart

 neighbor 10.10.0.2 remote-as 64513
 neighbor 10.10.0.2 description Sp-01-R-01
 neighbor 10.10.0.2 update-source Loopback0

 address-family ipv4
  network 0.0.0.0
  neighbor 10.10.0.1 activate
  neighbor 10.10.0.1 soft-reconfiguration inbound

  neighbor 10.10.0.2 activate
  neighbor 10.10.0.2 next-hop-self

ip route 0.0.0.0 0.0.0.0 172.29.225.1
ip route 10.10.0.1 255.255.255.255 10.10.11.1
ip route 10.10.0.2 255.255.255.255 10.10.12.1

Sp-02-R-01 Configuration

interface Loopback0
 description Routing-Loopback
 ip address 10.10.0.4 255.255.255.255

interface Ethernet0/0
 description Internet_Fw
 ip address 10.10.11.4 255.255.255.0

interface Ethernet0/1
 description Sp-02-R-02
 ip address 10.10.13.1 255.255.255.0

interface Ethernet0/2
 description Internet
 ip address 172.29.225.83 255.255.255.0

router bgp 64514
 bgp router-id 10.10.0.4
 bgp log-neighbor-changes
 no bgp default ipv4-unicast

 neighbor 10.10.0.1 remote-as 64512
 neighbor 10.10.0.1 description Internet-Fw
 neighbor 10.10.0.1 ebgp-multihop 2
 neighbor 10.10.0.1 update-source Loopback0
 neighbor 10.10.0.1 ha-mode graceful-restart

 neighbor 10.10.0.5 remote-as 64514
 neighbor 10.10.0.5 description Sp-02-R-02
 neighbor 10.10.0.5 update-source Loopback0

 address-family ipv4
  network 0.0.0.0

  neighbor 10.10.0.1 activate
  neighbor 10.10.0.1 soft-reconfiguration inbound

  neighbor 10.10.0.5 activate
  neighbor 10.10.0.5 next-hop-self

ip route 0.0.0.0 0.0.0.0 172.29.225.1
ip route 10.10.0.1 255.255.255.255 10.10.11.1
ip route 10.10.0.5 255.255.255.255 10.10.13.2

Sp-02-R-02 Configuration

interface Loopback0
 description Routing-Loopback
 ip address 10.10.0.5 255.255.255.255

interface Ethernet0/0
 description Internet_Fw
 ip address 10.10.11.5 255.255.255.0

interface Ethernet0/1
 description Sp-02-R-01
 ip address 10.10.13.2 255.255.255.0

interface Ethernet0/2
 description Internet
 ip address 172.29.225.84 255.255.255.0

router bgp 64514
 bgp router-id 10.10.0.5
 bgp log-neighbor-changes
 no bgp default ipv4-unicast

 neighbor 10.10.0.1 remote-as 64512
 neighbor 10.10.0.1 description Internet-Fw
 neighbor 10.10.0.1 ebgp-multihop 2
 neighbor 10.10.0.1 update-source Loopback0
 neighbor 10.10.0.1 ha-mode graceful-restart

 neighbor 10.10.0.4 remote-as 64514
 neighbor 10.10.0.4 description Sp-02-R-01
 neighbor 10.10.0.4 update-source Loopback0

 address-family ipv4
  network 0.0.0.0
  neighbor 10.10.0.1 activate
  neighbor 10.10.0.1 soft-reconfiguration inbound

  neighbor 10.10.0.4 activate
  neighbor 10.10.0.4 next-hop-self

ip route 0.0.0.0 0.0.0.0 172.29.225.1
ip route 10.10.0.1 255.255.255.255 10.10.11.1
ip route 10.10.0.4 255.255.255.255 10.10.13.1

Internet-Fw Cluster Configuration

config system interface
    !!! Internal-Network which will be advertised to service providers.
    edit "port5"
        set vdom "root"
        set ip 10.20.1.1 255.255.255.0
        set allowaccess ping
        set description "Internal-Network"
    next
    !!! External-Network to reach SP routers.
    edit "port6"
        set vdom "root"
        set ip 10.10.11.1 255.255.255.0
        set allowaccess ping
        set description "External-Network"
    next
    !!! BGP routing-loopback.
    edit "loopback0"
        set vdom "root"
        set ip 10.10.0.1 255.255.255.255
        set allowaccess ping
        set type loopback
    next
end

!!! Static routes to reach Sp-01 and and Sp-02 routers loopbacks.
config router static
    edit 2
        set dst 10.10.0.2 255.255.255.255
        set gateway 10.10.11.2
        set device "port6"
        set comment "Sp-01-R-01-Loopback0"
    next
    edit 3
        set dst 10.10.0.3 255.255.255.255
        set gateway 10.10.11.3
        set device "port6"
        set comment "Sp-01-R-02-Loopback0"
    next
    edit 4
        set dst 10.10.0.4 255.255.255.255
        set gateway 10.10.11.4
        set device "port6"
        set comment "Sp-02-R-01-Loopback0"
    next
    edit 5
        set dst 10.10.0.5 255.255.255.255
        set gateway 10.10.11.5
        set device "port6"
        set comment "Sp-02-R-02-Loopback0"
    next
end

config router aspath-list
    !!! AS-Path access list that matches AS-Path that begins with AS64513 (Sp-01).
    edit "Asp_Sp-01_64513"
        config rule
            edit 1
                set action permit
                set regexp "^64513_"
            next
        end
    next
end

config router prefix-list
    !!! Prefix-list to match only the default route.
    edit "Pfx_Default_Route"
        config rule
            edit 1
                set prefix 0.0.0.0 0.0.0.0
                unset ge
                unset le
            next
        end
    next
    !!! Prefix-list to match internal-networks that will be advertised to ebgp neighbors.
    edit "Pfx_Local_Network"
        config rule
            edit 1
                set prefix 10.20.1.0 255.255.255.0
                unset ge
                unset le
            next
        end
    next
end

config router route-map
    !!! Incoming route-map to Sp-01 that allows default route with higher local preference.
    edit "Rmap_Sp-01_In"
        config rule
            edit 1
                set match-ip-address "Pfx_Default_Route"
                set set-local-preference 200
            next
        end
    next
    !!! Incoming route-map to Sp-02 that allows default route with lower local    preference.
    edit "Rmap_Sp-02_In"
        config rule
            edit 1
                set match-ip-address "Pfx_Default_Route"
                set set-local-preference 100
            next
        end
    next
    !!! Outgoing route-map to Sp-01 that allows internal-networks only.
    edit "Rmap_Sp-01_Out"
        config rule
            edit 1
                set match-ip-address "Pfx_Local_Network"
            next
        end
    next
    !!! Outgoing route-map to Sp-02 that allows internal-networks only.
    edit "Rmap_Sp-02_Out"
        config rule
            edit 1
                set match-ip-address "Pfx_Local_Network"
            next
        end
    next
    !!! Conditional route-map that matches a default route received from AS64513 (Sp-01).
    edit "Rmap_Sp-02_Cond_Rule"
        config rule
            edit 1
                set match-as-path "Asp_Sp-01_64513"
                set match-ip-address "Pfx_Default_Route"
            next
        end
    next
    !!! If route-map "Rmap_Sp-02_Cond_Rule" is false; routes allowed by "Rmap_Sp-02_Cond_Out" will be advertised to Sp-02 routers.
    edit "Rmap_Sp-02_Cond_Out"
        config rule
            edit 1
                set match-ip-address "Pfx_Local_Network"
                set set-aspath "64512 64512 64512"
            next
        end
    next
end

config router bgp
    set as 64512
    set router-id 10.10.0.1
    !!! Enable multipath for ebgp ecmp.
    set ebgp-multipath enable
    config neighbor
        edit "10.10.0.2"
            !!! Enable graceful-restart capability.
            set capability-graceful-restart enable
            !!! Enable ebgp-multihop because neighborship are established over loopback interface.
            set ebgp-enforce-multihop enable
            set ebgp-multihop-ttl 2
            set soft-reconfiguration enable
            set description "Sp-01-R-01"
            set remote-as 64513
            !!! Apply inbound route-map.
            set route-map-in "Rmap_Sp-01_In"
            !!! Apply outbound route-map.
            set route-map-out "Rmap_Sp-01_Out"
            set update-source "loopback0"
        next
        edit "10.10.0.3"
            set capability-graceful-restart enable
            set ebgp-enforce-multihop enable
            set ebgp-multihop-ttl 2
            set soft-reconfiguration enable
            set description "Sp-01-R-02"
            set remote-as 64513
            set route-map-in "Rmap_Sp-01_In"
            set route-map-out "Rmap_Sp-01_Out"
            set update-source "loopback0"
        next
        edit "10.10.0.4"
            set capability-graceful-restart enable
            set ebgp-enforce-multihop enable
            set ebgp-multihop-ttl 2
            set soft-reconfiguration enable
            set description "Sp-02-R-01"
            set remote-as 64514
            !!! Apply inbound route-map.
            set route-map-in "Rmap_Sp-02_In"
            !!! Apply outbound route-map.
            set route-map-out "Rmap_Sp-02_Out"
            set update-source "loopback0"
            !!! Allow "Rmap_Sp-02_Cond_Out" only if "Rmap_Sp-02_Cond_Rule" is true.
            !!! "Rmap_Sp-02_Cond_Rule" true means both the default route advertised from Sp-01 is removed from BGP Routing Information Base (BGP -RIB).  
            config conditional-advertise
                edit "Rmap_Sp-02_Cond_Out"
                    set condition-routemap "Rmap_Sp-02_Cond_Rule"
                    set condition-type non-exist
                next
            end
        next
        edit "10.10.0.5"
            set capability-graceful-restart enable
            set ebgp-enforce-multihop enable
            set ebgp-multihop-ttl 2
            set soft-reconfiguration enable
            set description "Sp-02-R-02"
            set remote-as 64514
            !!! Apply inbound route-map.
            set route-map-in "Rmap_Sp-02_In"
            !!! Apply outbound route-map.
            set route-map-out "Rmap_Sp-02_Out"
            set update-source "loopback0"
            !!! Allow "Rmap_Sp-02_Cond_Out" only if "Rmap_Sp-02_Cond_Rule" is true.
            !!! "Rmap_Sp-02_Cond_Rule" true means both the default route advertised from Sp-01 is removed from BGP Routing Information Base (BGP -RIB).  
            config conditional-advertise
                edit "Rmap_Sp-02_Cond_Out"
                    set condition-routemap "Rmap_Sp-02_Cond_Rule"
                    set condition-type non-exist
                next
            end
        next
    end
    config network
        !!! Advertise the internal-network into BGP.
        edit 1
            set prefix 10.20.1.0 255.255.255.0
        next
    end
end

Verification

First we will verify when Sp-01 routers are working as expected - no network disruption between customer-fw and Sp-01.

!!! BGP RIB information
# get router info bgp network 
VRF 0 BGP table version is 1, local router ID is 10.10.0.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric     LocPrf      Weight RouteTag   Path
!!! Default route received from Sp-01 and higher local preference because of incoming route-map.
*  0.0.0.0/0            10.10.0.2          0             200       0           0             64513     i <-/->
*>                         10.10.0.3          0             200        0          0              64513    i <-/1>
!!! Default route received from Sp-02 and lower local preference because of incoming route-map.
*                           10.10.0.4          0             100       0           0             64514     i <-/->
*                          10.10.0.5          0             100        0          0              64514    i <-/->
!!! Internal-network advertised to BGP.
*> 10.20.1.0/24   0.0.0.0                            100      32768     0              i <-/1>

!!! Routing table - bgp routes.
# get router info routing-table bgp 
Routing table for VRF=0
!!! Default route from Sp-01 is installed in the routing table because of higher local preference.
!!! Both default routes from Sp-01 is installed because of ebgp-multipath.
B*      0.0.0.0/0 [20/0] via 10.10.0.3 (recursive via 10.10.11.3, port6), 18:04:19, [1/0]
                        [20/0] via 10.10.0.2 (recursive via 10.10.11.2, port6), 18:04:19, [1/0]

Let's verify routing from Test-Pc-01 (10.20.1.11/24) through Sp-01 (AS64513) - 

Test-Pc-01:~# traceroute 1.1.1.1
traceroute to 1.1.1.1 (1.1.1.1), 30 hops max, 60 byte packets
 1  10.20.1.1 (10.20.1.1)  1.979 ms  1.793 ms  1.925 ms
 !!! Traffic routed through Sp-01-R-01.
 2  10.10.11.2 (10.10.11.5)  1.901 ms  1.881 ms  1.849 ms
 3  * * *
 4  * * *
 5  * * *
 6  * * *
 7  * * *
 8  * * *
 9  1.1.1.1 (1.1.1.1)  5.827 ms  5.796 ms  5.777 ms

When we are receiving a default route from Sp-01, our internal-network 10.20.1.0/24 will only be advertised to Sp-01. We will not advertise the internal-network to Sp-02 because the conditional route-map check "Rmap_Sp-02_Cond_Rule" is false when it is checked against the BGP-RIB.

!!! No internal-network route is advertised to Sp-02-R-01.
# get router info bgp neighbors 10.10.0.4 advertised-routes 
% No prefix for neighbor 10.10.0.4

!!! No internal-network route is advertised to Sp-02-R-02.
# get router info bgp neighbors 10.10.0.5 advertised-routes
% No prefix for neighbor 10.10.0.5

Now we will disrupt to connection towards Sp-01 by shutting down both Sp-01 ebgp neighbors in customer-fw (internet-fw).

config router bgp
    config neighbor
        !!! Manual shutdown of ebgp neighbor - Sp-01-R-01.
        edit "10.10.0.2"
            set shutdown enable
        next
        !!! Manual shutdown of ebgp neighbor - Sp-01-R-02.
        edit "10.10.0.3"
            set shutdown enable
        next
    end
end

After shutting down Sp-01 ebgp neighborship, let have a look at BGP-RIB again from the firewall - 

!!! BGP RIB information
# get router info bgp network 
VRF 0 BGP table version is 1, local router ID is 10.10.0.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric     LocPrf      Weight RouteTag   Path
!!! Default route received from Sp-02 only because Sp-01 is not available.
*> 0.0.0.0/0          10.10.0.4          0             100       0           0             64514     i <-/->
*                          10.10.0.5          0             100        0          0              64514    i <-/->
!!! Internal-network advertised to BGP.
*> 10.20.1.0/24   0.0.0.0                            100      32768     0              i <-/1>

Now our conditional route-map check - "Rmap_Sp-02_Cond_Rule" will be true because there in no 0.0.0.0/0 route in the RIB for which AS-path begins with 64513. And because of that we will start advertising the internal-network - 10.20.1.0/24 towards Sp-02 which is allowed by route-map - "Rmap_Sp-02_Cond_Out".

!!! Internal-network 10.20.1.0/24 advertised to Sp-02-R-01.
# get router info bgp neighbors 10.10.0.4 advertised-routes 
VRF 0 BGP table version is 4, local router ID is 10.10.0.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete

      Network          Next Hop            Metric   LocPrf Weight RouteTag  Path
*> 10.20.1.0/24     10.10.0.1                     100     32768        0        64512 64512 64512 i <-/->

Total number of prefixes 1

!!! Internal-network 10.20.1.0/24 advertised to Sp-02-R-02.
# get router info bgp neighbors 10.10.0.5 advertised-routes
VRF 0 BGP table version is 4, local router ID is 10.10.0.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric     LocPrf Weight RouteTag Path
*> 10.20.1.0/24     10.10.0.1                     100  32768        0 64512 64512 64512 i <-/->

Total number of prefixes 1

Also default-route from Sp-02 routers will be installed in the routing table - 

# get router info routing-table bgp 
Routing table for VRF=0
B*      0.0.0.0/0 [20/0] via 10.10.0.5 (recursive via 10.10.11.5, port6), 02:02:19, [1/0]
                        [20/0] via 10.10.0.4 (recursive via 10.10.11.4, port6), 02:02:19, [1/0]

Let's verify routing from Test-Pc-01 (10.20.1.11/24) through Sp-02 (AS64514) -

Test-Pc-01:~# traceroute 1.1.1.1
traceroute to 1.1.1.1 (1.1.1.1), 30 hops max, 60 byte packets
 1  10.20.1.1 (10.20.1.1)  1.979 ms  1.793 ms  1.925 ms
 !!! Traffic routed through Sp-02-R-02.
 2  10.10.11.5 (10.10.11.5)  1.901 ms  1.881 ms  1.849 ms
 3  * * *
 4  * * *
 5  * * *
 6  * * *
 7  * * *
 8  * * *
 9  1.1.1.1 (1.1.1.1)  5.827 ms  5.796 ms  5.777 ms
 
If you are using dual ISP for your internet connectivity - the recommendation is to always use both the ISPs and all the circuits (ecmp) - these high speed internet lines are expensive (try to avoid using them in active/passive manner). But if you cannot use both service providers at the same time; then with BGP's conditional advertisement to some extent we can automate SP failover. Also check your firewall support for ecmp and session-table management (firewalls from Fortigate have support for this).


Comments

Popular posts from this blog

Fortigate firewall AAA Configuration for management with TACACS+ protocol and Cisco ISE

802.1x wired authentication with Huawei VRP Switch - (Unified Mode)

High Availability (HA) Cluster Configuration With Fortigate Firewalls (Active-Passive)