Intermediate · Routing: static routes and OSPF · topic 32 of 57 · 30 min
Static and default routes
Explanation
Why type routes by hand?
A router knows its connected networks automatically. To reach any other network it needs a route. You can either run a routing protocol, which learns routes by itself, or type static routes. A static route never changes on its own: it uses no CPU or bandwidth for updates and does exactly what you said. That is good for small, stable networks and bad for big, changing ones.
The basic command
R1(config)# ip route 192.168.20.0 255.255.255.0 10.0.12.2
R1(config)# ip route 192.168.20.0 255.255.255.0 GigabitEthernet0/1
R1(config)# ip route 192.168.20.0 255.255.255.0 GigabitEthernet0/1 10.0.12.2The format is ip route, then the destination network, its subnet mask (not a prefix length), then where to send the packets.
- Next hop IP (first line): the most common form. The router does a second lookup to find which interface leads to 10.0.12.2. This is called a recursive lookup.
- Exit interface (second line): the route shows as directly connected. Fine on point-to-point serial links. On Ethernet it is a poor choice, because the router must ARP for every destination address and depends on the next router answering for them (proxy ARP).
- Fully specified (third line): both the interface and the next hop. No recursive lookup, and it works cleanly on Ethernet.
A static route goes into the routing table only if it is usable: the exit interface must be up, or the next hop must be reachable through some other route. Check with show ip route static.
Default route
R1(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.1
R1# show ip route | include 0.0.0.0
Gateway of last resort is 203.0.113.1 to network 0.0.0.0
S* 0.0.0.0/0 [1/0] via 203.0.113.1Small offices and branches usually need just one default route pointing at the ISP or the head office router. This is called a stub network: there is only one way out.
Host routes and floating static routes
A host route has mask 255.255.255.255 (/32) and matches exactly one address, for example a single server you want to reach over a special path: ip route 10.9.9.9 255.255.255.255 10.0.13.3.
A floating static route is a backup. You add an administrative distance at the end of the command, higher than the main route's AD. While the main route exists, the backup "floats" out of the table. When the main route disappears, the backup is installed.
! Main path through the leased line (AD 1, the default for static routes)
R1(config)# ip route 0.0.0.0 0.0.0.0 10.0.12.2
! Backup through broadband, AD 5: used only if the first route disappears
R1(config)# ip route 0.0.0.0 0.0.0.0 198.51.100.1 5A static route with a next hop disappears only when the router can no longer reach that next hop. If the ISP fails beyond the modem while your interface stays up, the route stays and traffic is lost. Larger networks add tracking (Cisco IP SLA) to remove the route when a test ping fails; check your platform's documentation for it.
IPv6 static routes
R1(config)# ipv6 unicast-routing
R1(config)# ipv6 route 2001:db8:20::/64 2001:db8:0:12::2
R1(config)# ipv6 route ::/0 2001:db8:0:12::2
R1(config)# ipv6 route ::/0 GigabitEthernet0/1 fe80::2Without ipv6 unicast-routing the router will not forward IPv6 packets at all. ::/0 is the IPv6 default route.
When static routing is good, and when it is not
| Good fit | Poor fit |
|---|---|
| A branch with one link to head office | Dozens of routers with many paths |
| A default route to the ISP | Networks that change often |
| A backup route (floating static) | Anywhere you need automatic failover around many failures |
Troubleshooting: the missing return route
The most common static routing problem: R1 has a route to the LAN behind R2, but R2 has no route back to the LAN behind R1. PC1's ping reaches PC2, but the reply dies at R2, so ping shows "Request timed out". Every conversation needs a route in both directions.
- Ping step by step: the gateway first, then the next router, then the far LAN.
- Run traceroute (tracert on Windows) to see the last router that answers.
- On each router, run show ip route and check routes to BOTH the destination and the source network.
- Check typing mistakes: a wrong mask, a wrong next hop, or a next hop that is not on a connected subnet.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Static and default routes · 1/8
In this lesson you will write static routes: routes you type by hand.
Prefer a video by a teacher? Find free videos on “ccna static route default route floating static packet tracer” on YouTube ↗
In real life: A chain of pharmacy stores
A pharmacy chain in Tamil Nadu has 60 small stores. Each store router has one LAN for the billing PCs and one link to the head office in Chennai. Running a routing protocol in every store would add work for no benefit, so each store router has a single default route to head office, and a floating static default over a 4G backup with a higher AD. The head office router has one static route per store LAN, written from a spreadsheet.
Store17(config)# ip route 0.0.0.0 0.0.0.0 10.200.17.1
Store17(config)# ip route 0.0.0.0 0.0.0.0 192.168.8.1 10
HO(config)# ip route 172.17.17.0 255.255.255.0 10.200.17.2Practice (0/3 done)
Write static_route(prefix, next_hop, ad=None) that returns the Cisco IOS command for a route given in CIDR form. Example: static_route("192.168.20.0/24", "10.0.12.2") returns "ip route 192.168.20.0 255.255.255.0 10.0.12.2". If ad is given, add it at the end (a floating static route). Use the ipaddress module to get the mask.
R1 has "ip route 192.168.20.0 255.255.255.0 10.0.12.2". PC1 (192.168.10.10) pings PC2 (192.168.20.10) and gets "Request timed out". R2 has no static routes. What is the most likely cause?
Packet Tracer lab. Build: PC1 (192.168.10.10/24) to R1 G0/0 (192.168.10.1); R1 G0/1 (10.0.12.1/30) to R2 G0/1 (10.0.12.2/30); R2 G0/0 (192.168.20.1/24) to PC2 (192.168.20.10/24). Use two 2911 routers. Make PC1 and PC2 ping each other with static routes only. Then add a second link R1 G0/2 (10.0.21.1/30) to R2 G0/2 (10.0.21.2/30) as a floating backup with AD 5, shut R1 G0/1 and check that the ping still works.
Quick quiz
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- OSPF concepts: link state, areas and neighboursRouting: static routes and OSPF · same module
- Configuring and verifying single-area OSPFRouting: static routes and OSPF · same module
- Routing: sending each request to the right codeBackend Development · APIs and request handling
- Network basics: IP addresses, routes, DNS and the ip commandLinux and Red Hat (RHCSA to RHCE) · Software and networking
- Troubleshooting tools and common faultsTroubleshooting and the CCNA exam
- Pages and client-side routingFull-Stack Development · Building the frontend
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
What is the default administrative distance of a static route?
Answer: 1
Static routes have AD 1 unless you add a different number at the end of the command.
The main path is learnt by OSPF. Which AD makes a static route a correct floating backup?
Answer: 130
The backup must have a higher AD than OSPF's 110, so 130 works. The others would beat OSPF.
Which command is a default route?
Answer: ip route 0.0.0.0 0.0.0.0 10.0.0.1
Network 0.0.0.0 with mask 0.0.0.0 (0.0.0.0/0) matches every address.
An IPv6 static route uses next hop fe80::2. What else must the command include?
Answer: The exit interface
Link-local addresses are valid only on one link, so the router needs the exit interface too.
Where is a static default route the best choice?
Answer: A stub branch office with one link to head office
A stub network has only one way out, so one default route is simple and enough.
A route has administrative distance 255. What happens?Related
Answer: It is never installed in the routing table
AD 255 means the source is not trusted at all, so the route is never used.
Which command shares a router's static default route with its OSPF neighbours?Related
Answer: default-information originate
default-information originate, under router ospf, advertises the default route as O*E2.
Which route handles GET /products?sort=price?Related
Answer: GET /products
The query string is not part of routing. The handler of GET /products reads it.
Which command shows the default gateway?Related
Answer: ip route
The "default via" line in ip route is the gateway.
From Network basics: IP addresses, routes, DNS and the ip command
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 3 more topics in “Routing: static routes and OSPF” before its exam: OSPF concepts: link state, areas and neighbours, Configuring and verifying single-area OSPF, First hop redundancy: HSRP, VRRP and GLBP.
- Module 7 exam: static routes, OSPF and HSRP · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, IP services: DHCP, DNS, NAT and more. 57 topics left in the course before the final exam.