Technical Tip: FortiGate IP route selection, and how to change the administrative distance (preference) of a routing protocol
Description
This article describes how the FortiGate selects routes in the routing table from the different routing protocols and how to change the route preference.
Scope
FortiGate.
Solution
How does it work:
- The same IP destination prefix may be learned from different routing protocols (ex: multiple default routes 0.0.0.0/0.0.0.0).
- The routing table will, however, contain only one entry (or more if they have been learned from the same protocol supporting ECMP and have the same 'distance'. ECMP is currently applicable to static and OSPF).
- The following shows the default distance (preference) settings on a FortiGate (configurable for all types except direct interfaces):
- Directly connected 0
- Static routes 10
- EBGP routes 20
- OSPF routes 110
- RIP routes 120
- IBGP routes 200
- Note 1: The term 'distance' is sometimes also referred to as 'weight' by other manufacturers.
- Note 2: the 'distance' has got only local significance on the FortiGate, and has no impact on a route redistribution.
Case study:
- Assume that a default route is learned via BGP, and another default route is configured as static route. By default, only the static default route will be in the routing table.
- It may however be necessary that the preferred default route is the one received by BGP, and the static route kept as backup.
- In this case, it will be necessary to adapt the route distances.
Route distance seen from the GUI:

The distance of the routes can be seen also after executing below command, as below:
get router info routing-table all
Codes: K - kernel, C - connected, S - static, R - RIP, B - BGP
O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
V - BGP VPNv4
* - candidate default
Routing table for VRF=0
S* 0.0.0.0/0 [10/0] via 10.191.47.254, port1, [1/0] <- Distance is 10
C 10.112.0.0/20 is directly connected, port2
C 10.191.32.0/20 is directly connected, port1
Solution
How to change the route distance: some examples.
config router rip
config distance
edit 1
set distance 130
next
end
end
config router static
edit 1
set device "internal"
set distance 20
set gateway 172.31.225.254
next
end
config router ospf
set distance-external 105
set distance-intra-area 100
end
config router bgp
set distance-external 30
set distance-internal 210
end
distance-external: distance for routes external to the AS i.e., eBGP (min value:1, max value:255, default:20)
distance-internal: distance for routes internal to the AS i.e., iBGP (min value:1, max value:255, default:200)
Note:
- New values are only given as examples.
- Distance changes might need a reboot or an 'exec router restart' to be effective.
Related article:
