Static Routing
A router’s whole job is to move a packet one hop closer to its destination, and it decides each hop from a single table. This lesson explains the routing table, the three kinds of route, and how to add a static route by hand — with the real Cisco IOS commands. The lab that follows puts this into practice.
Routing: choosing the path
Routing is the process of selecting a path for a packet to travel from its source network to its destination network. A host only knows about its own subnet and a default gateway; it is the routers along the way that decide, hop by hop, where a packet goes next. Each router makes an independent, per-hop decision, and every decision comes from one place: the routing table.
The routing table
The routing table is the list of networks the router knows how to reach, and for each one, the interface or next-hop IP to use. The command that shows it is show ip route. Every line has this shape:
S 192.168.20.0/24 [1/0] via 10.0.0.2 ^ ^ ^ ^ ^ | | | | +-- metric | | | +----- administrative distance | | +--------- next-hop IP address | +------------------------- destination network +------------------------------ route source code (S = static)
The leading code tells you where the route came from. The most important codes:
| Code | Meaning |
|---|---|
| C | Directly connected network — the router has an interface in it. |
| L | Local route — the router’s own address on that interface (a /32 host route). |
| S | Static route — added manually by an administrator. |
| S* | Static default route (the candidate default). |
| O | OSPF (a dynamic route learned from a neighbour). |
| D | EIGRP — internal (dynamic). |
| R | RIP (dynamic). |
Connected, static, and dynamic routes
A router’s table can hold three kinds of route, and they come from three different places.
| Type | How it gets there | Typical use |
|---|---|---|
| Connected | Added automatically when you give an interface an IP address and bring it up. | Every active interface — the router always knows its own networks. |
| Static | Configured by hand with ip route. | Small, stable, or edge networks; precise control. |
| Dynamic | Learned automatically from neighbours using a routing protocol (OSPF, EIGRP, RIP). | Large or changing networks where manual configuration does not scale. |
When a static route is the right choice
A static route is a route an administrator enters manually. It is explicit, it never changes unless you change it, and the router does not advertise it to anyone. Static routes consume no CPU for route calculation and no bandwidth for routing updates. Use them when:
- Small networks — a handful of routers where dynamic protocols are overkill.
- Stub networks — a network with only one way out, so a single default route captures everything.
- Predictable paths — you want a specific, known next hop.
- Security by design — only the routes you explicitly allow can be used; nothing is learned automatically.
- The Internet edge — a default route pointing at the ISP.
The default route and the ip route command
A default route matches every destination. It is written 0.0.0.0 0.0.0.0 (IPv4), which represents “any network / any mask”. Routers use it as the gateway of last resort: if no more-specific route in the table matches the destination, the default route is used.
The ip route command
The IPv4 command is ip route. The general form is ip route <destination-network> <subnet-mask> <next-hop-ip or exit-interface>. You may specify the next-hop IP, the exit interface, or both:
| Form | Example | Notes |
|---|---|---|
| Next-hop only | ip route 192.168.20.0 255.255.255.0 10.0.0.2 |
The normal choice, especially on Ethernet/broadcast links. |
| Exit interface only | ip route 192.168.20.0 255.255.255.0 serial 0/0/0 |
Common on point-to-point links; the router sends straight out of that interface. |
| Both (fully specified) | ip route 192.168.20.0 255.255.255.0 serial 0/0/0 10.0.0.2 |
Most explicit; useful when it matters which interface is used. |
| Default route | ip route 0.0.0.0 0.0.0.0 203.0.113.1 |
Matches every destination — the gateway of last resort. |
Which route is used? Longest prefix match
The rule the router uses is longest prefix match: the most specific matching route wins. A default route has the shortest possible prefix (/0), so it only catches destinations that match no longer route. This is why a default route never breaks your specific routes — it simply waits behind them.
| Route in the table | Prefix | Used for |
|---|---|---|
| Static route to LAN B | 192.168.20.0/24 | Anything inside 192.168.20.0/24 |
| Connected WAN link | 10.0.0.0/30 | Anything inside 10.0.0.0/30 |
| Default route | 0.0.0.0/0 | Everything else — the gateway of last resort |
Administrative distance versus metric
When a router knows more than one route, it needs a rule to pick one. Two concepts do that, and the exam loves to test the difference:
- Administrative distance (AD) — a trustworthiness value for the source of the route. It compares routes to the same destination from different sources. Lower is better.
- Metric — the cost of the path, used to choose between routes from the same protocol. Each protocol measures it differently (hop count, bandwidth, etc.). Lower is better.
| Route source | Default administrative distance |
|---|---|
| Directly connected | 0 |
| Static | 1 |
| eBGP | 20 |
| EIGRP (internal) | 90 |
| OSPF | 110 |
| RIP | 120 |
A connected route (AD 0) always beats a static route (AD 1) to the same network, which always beats a route learned by OSPF (AD 110). In the output [1/0], the first number is the AD and the second is the metric.
130), it becomes a floating static route: it sits unused until the dynamic route disappears, then takes over as a backup.Example topology: configure and verify
Two routers, each serving one LAN, joined by a serial WAN link. Neither router knows the other’s LAN until we add a static route.
Step 1 — Address the interfaces (connected routes appear automatically)
! --- R1: LAN A interface and WAN serial interface --- R1> enable R1# configure terminal R1(config)# interface gigabitEthernet 0/0 R1(config-if)# description LAN A R1(config-if)# ip address 192.168.10.1 255.255.255.0 R1(config-if)# no shutdown R1(config-if)# exit R1(config)# interface serial 0/0/0 R1(config-if)# description WAN link to R2 R1(config-if)# ip address 10.0.0.1 255.255.255.252 R1(config-if)# clock rate 128000 R1(config-if)# no shutdown R1(config-if)# exit R1(config)# exit R1#
clock rate command is only needed on the DCE end of a serial link (here, R1). On modern packet-tracer/IOS gear the DCE side is whichever end supplies the clock. Gigabit Ethernet interfaces never need it.Step 2 — Give R2 its mirror-image addressing
! --- R2 --- R2> enable R2# configure terminal R2(config)# interface serial 0/0/0 R2(config-if)# ip address 10.0.0.2 255.255.255.252 R2(config-if)# no shutdown R2(config-if)# exit R2(config)# interface gigabitEthernet 0/0 R2(config-if)# description LAN B R2(config-if)# ip address 192.168.20.1 255.255.255.0 R2(config-if)# no shutdown R2(config-if)# exit R2(config)# exit R2#
Step 3 — Add the static routes
! --- On R1: reach LAN B through R2's WAN address --- R1# configure terminal R1(config)# ip route 192.168.20.0 255.255.255.0 10.0.0.2 ! exit-interface form would be: ! ip route 192.168.20.0 255.255.255.0 serial 0/0/0 R1(config)# exit ! --- On R2: reach LAN A through R1's WAN address --- R2# configure terminal R2(config)# ip route 192.168.10.0 255.255.255.0 10.0.0.1 R2(config)# exit
Step 4 — Verify the routing table
R1# show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
... (codes continue) ...
Gateway of last resort is not set
10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 10.0.0.0/30 is directly connected, Serial0/0/0
L 10.0.0.1/32 is directly connected, Serial0/0/0
192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.10.0/24 is directly connected, GigabitEthernet0/0
L 192.168.10.1/32 is directly connected, GigabitEthernet0/0
S 192.168.20.0/24 [1/0] via 10.0.0.2
Read the last line: S = static, [1/0] = AD 1 / metric 0, via 10.0.0.2 = the next hop. R1 now knows how to reach LAN B. R2’s table shows the mirror image (S 192.168.10.0/24 [1/0] via 10.0.0.1).
Step 5 — Prove connectivity with ping
R1# ping 192.168.20.10 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 192.168.20.10, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms ! For a default route at the Internet edge, add instead: R1(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.1 ! which then appears in the table as: ! 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
0.0.0.0 0.0.0.0) is the gateway of last resort at the Internet edge — and because it is less specific than any real network, the router uses a specific route whenever one exists.Key terms
| Term | Meaning |
|---|---|
| Routing | Selecting the path for a packet between networks, hop by hop, using the routing table. |
| Routing table | The list of known destination networks and their next hops or exit interfaces. |
| Connected route | A route to a network the router has an interface in; added automatically. |
| Static route | A route entered manually with the ip route command. |
| Dynamic route | A route learned automatically from other routers via a routing protocol. |
| Default route | The route 0.0.0.0 0.0.0.0 that matches any destination; the gateway of last resort. |
| Administrative distance | A value (0–255) expressing the trustworthiness of a route’s source; lower is preferred. |
| Metric | The cost of a path used to choose between routes from the same protocol. |
Review
Check what you have learned with these review questions.
Sources & references
- Postel, J. RFC 791: Internet Protocol (1981). rfc-editor.org/rfc/rfc791.
- Baker, F. (ed.). RFC 1812: Requirements for IP Version 4 Routers (1995) — forwarding, routing tables, and default routes. rfc-editor.org/rfc/rfc1812.
- Socolofsky, T. & Kale, C. RFC 1180: A TCP/IP Tutorial (1991) — routing and next-hop forwarding. rfc-editor.org/rfc/rfc1180.
- Cisco. IP Routing: Static Route Configuration Guide; Cisco IOS IP Command Reference (
ip route,show ip route). cisco.com. - Cisco. CCNA (200-301) Exam Topics, Domain 3.0 IP Connectivity. cisco.com.
Target exams: CCNA 200-301 v1.1 · CyberOps Associate 200-201. Last content verification: 2026-10-11.