Static routing: where should the packet go
This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.
Key points
- The best route in the table is chosen by longest prefix match: a /24 always beats a /16, and a /16 always beats the default route.
- If there are two routes to the same network, the one with the lower distance enters the table (connected 0, static 10). If the distances are equal, the one with the lower priority is used.
- A default route is created without typing
dst:set gatewayandset deviceare enough, becausedstdefaults to 0.0.0.0/0. get router info routing-table allshows only active routes;get router info routing-table databasealso shows the inactive ones.- The FortiGate checks the return path to the source of an incoming packet (RPF). If there is no route to the source through that port, the packet is dropped.
How the routing table is read
When a packet arrives, the FortiGate compares the destination IP with the routing table and picks the most specific match. This is called longest prefix match.
| Destination | Routes in the table | Chosen |
|---|---|---|
| 10.10.30.10 | 0.0.0.0/0, 10.10.0.0/16, 10.10.30.0/24 | 10.10.30.0/24 |
| 10.10.99.5 | 0.0.0.0/0, 10.10.0.0/16, 10.10.30.0/24 | 10.10.0.0/16 |
| 8.8.8.8 | 0.0.0.0/0, 10.10.0.0/16, 10.10.30.0/24 | 0.0.0.0/0 |
When you give ports an IP, their networks enter the table by themselves (connected routes). For everything else you have to write a route.
The default route
In our lab the internet is behind port1 and the provider's address is 203.0.113.1.
FGT-HQ # config router static FGT-HQ (static) # edit 1 FGT-HQ (1) # set gateway 203.0.113.1 FGT-HQ (1) # set device port1 FGT-HQ (1) # next FGT-HQ (static) # end
GUI: Network > Static Routes > Create New.
We did not type dst because its default is 0.0.0.0 0.0.0.0. A route to a specific network looks like this (the branch LAN is behind a neighbouring router on port4):
FGT-HQ # config router static FGT-HQ (static) # edit 2 FGT-HQ (2) # set dst 10.20.0.0 255.255.255.0 FGT-HQ (2) # set gateway 10.255.1.2 FGT-HQ (2) # set device port4 FGT-HQ (2) # set comment "Filial LAN" FGT-HQ (2) # next FGT-HQ (static) # end
A difference from Cisco: on a FortiGate a static route names both the gateway and the device (the outgoing port).
Viewing the table
FGT-HQ # get router info routing-table all Routing table for VRF=0 S* 0.0.0.0/0 [10/0] via 203.0.113.1, port1, [1/0] C 10.10.10.0/24 is directly connected, port2 C 10.10.30.0/24 is directly connected, port3 S 10.20.0.0/24 [10/0] via 10.255.1.2, port4, [1/0] C 10.255.1.0/30 is directly connected, port4 C 203.0.113.0/30 is directly connected, port1
Sis static,Cis connected,*marks a candidate default route.[10/0]: the first number is the distance, the second the metric.- The trailing
[1/0]: the first number is the priority, the second the weight.
Distance and priority
With two providers you write two default routes. Which one will be used? (The example below is a separate scenario: port4 is connected to a second provider.)
| Situation | Result |
|---|---|
| Distances differ (10 and 20) | Only the lower one (10) enters the table. The other is a standby and is visible in database. |
| Same distance, different priority | Both are in the table, but outgoing traffic uses the one with the lower priority. |
| Same distance and priority | Both are used and sessions are shared between them (ECMP). |
FGT-HQ (static) # edit 3 FGT-HQ (3) # set gateway 198.51.100.1 FGT-HQ (3) # set device port4 FGT-HQ (3) # set distance 20 FGT-HQ (3) # next
When a port goes down, the static route bound to it leaves the table by itself and the standby route takes over. But if the port stays "up" and the problem is inside the provider, the FortiGate does not know. For that you need a link monitor or SD-WAN (section 5).
To see inactive routes:
FGT-HQ # get router info routing-table databaseRPF: checking the source address
On the first packet of every new session the FortiGate checks: does the route to this packet's source address go through the port the packet arrived on? If not, the packet is treated as spoofed and dropped. This is the reverse path forwarding (RPF) check.
In practice it looks like this: a packet from 10.20.0.5 arrives on port4, but the table has no route for 10.20.0.0/24 and the default route points to port1. The FortiGate drops the packet without even looking at the policies. The debug output says reverse path check fail, drop.
There are two modes:
- Feasible path (default): any route to the source through that port is enough; it does not have to be the best route.
- Strict: the best route to the source must go through exactly that port. It is enabled with
set strict-src-check enableunderconfig system settings.
Watch out on a real device: most "there is a policy but traffic does not pass" complaints are caused by routing. First check with get router info routing-table all that there is a route both to the destination and to the source, and only then look at the policy.
Blackhole and policy routes
- A blackhole route silently drops traffic:
set blackhole enable. We will use it in the VPN lessons so that traffic for internal addresses does not leak to the internet when a tunnel is down. - A policy route (
config router policy) looks at criteria other than the destination: source address, incoming port, protocol. Policy routes are checked before the routing table, so use them with care.
🧪 Hands-on lab · Topology: FGT (fortigate), ISP (pc), PC1 (pc)
Default route
The WAN port of the FortiGate (port1, 203.0.113.2/30) is connected to the provider (ISP, 203.0.113.1). Write a default route: gateway 203.0.113.1, outgoing port port1. If you do not type dst, it defaults to 0.0.0.0/0. Finally look at the table with get router info routing-table all and test with execute ping 203.0.113.1.
Checked:
- Gateway 203.0.113.1
- Outgoing port port1
- Routing table viewed
- The FortiGate pings the ISP
Check yourself
5 questions · answers are shown instantly · 3 correct answers complete the lesson
1The table has 0.0.0.0/0, 10.10.0.0/16 and 10.10.30.0/24. Which route does a packet to 10.10.30.10 take?
2There are two default routes: one with distance 10, the other with 20. What appears in the routing table?
3What happens if you do not type set dst when writing a default route?
4Which command shows inactive (standby) routes?
5There is no route through port4 to the source of a packet that arrived on port4. What does the FortiGate do?
Comments
Sign in to comment.