Skip to content

Intermediate · Routing: static routes and OSPF · topic 32 of 57 · 30 min

Static and default routes

Explanation

A static route is a route you type by hand: "to reach this network, send packets to this next hop". A default route (0.0.0.0/0) catches everything the router has no better route for. A floating static route has a higher administrative distance so it is used only when the main route disappears. Always remember that the reply needs a route back too.

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.

Think of it like this: A static route is like a direction board painted on a wall: "Platform 5 this way". It is simple and always there. But if the platform changes, nobody repaints the board until someone walks over with a brush. A routing protocol is like an announcement system that updates itself.

The basic command

output
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.2
Cisco IOS: three ways to write the same route: next hop, exit interface, and fully specified.

The 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

output
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.1
Cisco IOS: 0.0.0.0 with mask 0.0.0.0 matches every address, but it is the least specific route, so it is used only when nothing else matches.

Small 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.

output
! 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 5
Cisco IOS: the number at the end is the administrative distance of this static route.
Careful: If the main path is learnt by OSPF (AD 110), a floating static backup must have an AD above 110, for example 115 or 130. An AD of 5 would beat OSPF and be used all the time.

A 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

output
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::2
Cisco IOS: IPv6 uses the prefix length directly. With a link-local next hop (fe80::), you must also give the exit interface.

Without 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 fitPoor fit
A branch with one link to head officeDozens of routers with many paths
A default route to the ISPNetworks 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.

  1. Ping step by step: the gateway first, then the next router, then the far LAN.
  2. Run traceroute (tracert on Windows) to see the last router that answers.
  3. On each router, run show ip route and check routes to BOTH the destination and the source network.
  4. 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

Static routes

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.

output
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.2
Cisco IOS: a store with a main and a backup default route, and the head office route back to the store LAN.

Practice (0/3 done)

Task 1 · Code · Python

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.

Task 2 · Question

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?

Task 3 · Practice

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

Question 1

1.What is the default administrative distance of a static route?

Question 2

2.The main path is learnt by OSPF. Which AD makes a static route a correct floating backup?

Question 3

3.Which command is a default route?

Question 4

4.An IPv6 static route uses next hop fe80::2. What else must the command include?

Question 5

5.Where is a static default route the best choice?

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.

From How a router forwards: the routing table

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.

From Configuring and verifying single-area OSPF

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.

From Routing: sending each request to the right code

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

  1. 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.
  2. Module 7 exam: static routes, OSPF and HSRP · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, IP services: DHCP, DNS, NAT and more. 57 topics left in the course before the final exam.

← Previous: How a router forwards: the routing table