Last updated · reviewed for accuracy

Static routes & OSPF in IOS

A router with no routes is a paperweight with fans. This lesson adds routes both ways you will meet in real networks: by hand with ip route, and automatically with OSPF.

Static routes: telling the router by hand

A static route is one line: ip route, the destination network, its mask, and where to send it (the next-hop router address). It never changes unless you change it.

ios: routerstatic route
! reach 10.20.0.0/16 via the router at 10.0.0.2
R1(config)# ip route 10.20.0.0 255.255.0.0 10.0.0.2

Static routes are perfect when there is exactly one way to get somewhere: a branch office with a single uplink does not need a routing protocol to figure that out.

The default route: everything else, that way

A default route matches any destination not matched by something more specific. In IOS it is a static route to network 0.0.0.0 with mask 0.0.0.0: the classic quad-zero route pointing at your internet gateway.

ios: routerquad zero
R1(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.1

Remember the longest-prefix rule: the default route has the shortest possible prefix (/0), so it only wins when nothing else matches, which is exactly the job of “everything else goes to the internet.”

OSPF: let the routers work it out

OSPF is enabled with router ospf and a process ID, then network statements that tell OSPF which interfaces join in. The network command uses a wildcard mask and an area; small networks put everything in area 0.

ios: routerospf
R1(config)# router ospf 1
R1(config-router)# network 10.0.0.0 0.0.0.255 area 0
R1(config-router)# network 192.168.1.0 0.0.0.255 area 0

The wildcard mask is the subnet mask inverted: 0.0.0.255 means /24. If wildcards feel like dark magic, the Subnet Calculator shows the wildcard for any prefix. Once two routers with matching network statements see each other, they exchange routes automatically and react when links fail: the whole point of dynamic routing.

Read the routing table back

show ip route displays every route the router knows and a letter code for how it learned it: C for connected, S for static, O for OSPF. The gateway of last resort line shows the default route.

ios: routershow ip route
R1# show ip route
Codes: C - connected, S - static, O - OSPF ...
Gateway of last resort is 203.0.113.1 to network 0.0.0.0

C    10.0.0.0/24 is directly connected, Gig0/0
S    10.20.0.0/16 [1/0] via 10.0.0.2
O    192.168.2.0/24 [110/2] via 10.0.0.2, 00:04:11, Gig0/0

The last Cisco lesson unpacks every bracket and number in this output line by line.

The concept behind these commands

This is the hands-on companion to Static vs dynamic routing and OSPF basics: those explain when to choose each approach; this one gives you the keystrokes.

Frequently asked questions

When should I use a static route instead of OSPF?

Static wins when the path never changes and there are few of them: single uplinks, labs, small branches. OSPF wins when there are multiple paths or too many routers to maintain by hand.

What does ip route 0.0.0.0 0.0.0.0 mean?

The default route: 0.0.0.0 0.0.0.0 matches every destination at the shortest possible prefix, so more specific routes always win first. Everything unmatched goes to this next hop.

What is the wildcard mask in the OSPF network command?

The inverse of the subnet mask: 0 bits must match, 1 bits are ignored. A /24 → wildcard 0.0.0.255. The same notation appears again in ACLs.