NETWORKING · CCNA V1.1 · CHAPTER 5

Routers and routing

How a router decides where to send each packet, how you read its routing table and how you teach it routes by hand.

50 min read · 3 sessionsDomain 3 · IP Connectivity (25%)Level: intermediateAGLE method · A, G, L, E
AGLE methodSelf-studyAll the chapter text, at your own pace.

From point A to point B

Point A: you can already assign addresses and split a network into subnets, but each network is still an island: devices only talk to their own subnet. Point B: by the end you will explain how a router forwards a packet, read any line of its routing table, predict which route it will choose and configure static, default and floating routes in IPv4 and IPv6.

This chapter opens the IP Connectivity domain of the v1.1 exam, worth 25%: topics 3.1 (interpret the components of the routing table), 3.2 (determine how a router makes a forwarding decision by default) and 3.3 (configure and verify IPv4 and IPv6 static routing). It also reviews inter-VLAN routing from topic 2.1 with router-on-a-stick and SVIs.

What a router does

Routing is the process by which a layer 3 device carries a packet toward its destination. The router does two jobs: it chooses the best route to each destination network and it switches the packet from the interface it came in on to the exit interface of that route.

  • It works at layer 3 of the OSI model and decides with the destination IP address.
  • It joins different networks: each interface is a different network and broadcast domain.
  • It does not forward broadcasts, so it segments the network.
  • It can be a dedicated device or a function of a layer 3 switch, with physical and logical interfaces (subinterfaces, SVIs, loopbacks).
  • For PCs it is the default gateway: the way out to any network other than their own.

There are two ways for a router to learn remote networks:

Static routingDynamic routing
Who creates the routesThe administrator, one by oneA routing protocol that exchanges them between routers
Where it fitsSmall networks, default routes and backupsMedium and large networks
Topology changesDoes not adapt on its ownAdapts and finds another path
OverheadNo CPU or bandwidthUses CPU, memory and some bandwidth

Routed and routing protocols

Two similar names, two different jobs:

  • Routed protocol: carries the user’s data end to end. IPv4 and IPv6 are routed protocols.
  • Routing protocol: works between routers to discover networks and choose the paths the routed protocol will travel. OSPF, EIGRP, RIP and BGP are routing protocols.
Classifying routing protocolsRouting protocols are split into IGPs, which work inside an autonomous system, and EGPs, which connect autonomous systems. Among IGPs there are distance vector protocols (RIP), link-state protocols (OSPF, IS-IS) and advanced distance vector or hybrid (EIGRP). BGP, the internet’s EGP, is path vector.IGP INSIDE THE AS · EGP BETWEEN ASESIGP · inside an ASEGP · between ASesDistance vectorRIPv2Sees the networkthrough its neighborLink stateOSPF · IS-ISKnows the whole areatopologyAdvanced distancevectorEIGRPFast, with neighborsand backupsPath vectorBGPChooses by attributesand AS listEvery current protocol is classless: it sends the mask

IGP and EGP, and the four kinds of protocols. Diagram: The House of Routing.

An autonomous system (AS) is a set of networks under one administration, such as a company’s or a provider’s network. IGPs work inside an AS and EGPs connect autonomous systems to each other; the only EGP in use today is BGP.

TypeHow it worksExamples
Distance vectorKnows the network through what its neighbors tell it (“routing by rumor”). Sends its table periodically and converges slowly.RIPv2
Link stateEvery router knows the full map of its area and computes the shortest-path tree. Converges fast.OSPF, IS-IS
Advanced distance vector (hybrid)Keeps neighbors, sends only changes and stores backup routes. Converges very fast.EIGRP
Path vectorChooses by attributes and by the list of ASes each route crossesBGP

Depending on whether they send the mask in their updates, protocols are classful (RIPv1, IGRP, now obsolete) or classless (RIPv2, OSPF, EIGRP, IS-IS, BGP). Only classless protocols support VLSM and CIDR. For CCNA v1.1 the dynamic protocol you must master is OSPF.

The forwarding process

It all starts at the host. Before sending a packet, the PC compares the destination’s network with its own (with the AND operation from chapter 4):

  1. If the destination is on its own subnet, it finds the destination’s MAC with ARP and delivers the frame directly.
  2. If it is on another subnet, it sends the frame to the MAC of its default gateway, although the final destination’s IP is inside.
A packet’s trip from router to routerPC A sends a packet to a server on another network. Since the destination is outside its subnet, it hands it to its default gateway. Each router receives the frame, takes the packet out, looks up the destination in its table, lowers the TTL and builds a new frame for the next link. The source and destination IPs do not change; the MACs change at every hop.IPS STAY THE SAME · MACS CHANGE AT EVERY HOPPC A10.1.1.10R1G0/0 10.1.1.1R2G0/1 10.2.2.1Server10.2.2.20Default gatewayFrame 1MAC A → MAC R1Frame 2MAC R1 → MAC R2Frame 3MAC R2 → MAC SrvSource IP 10.1.1.10 → destination IP 10.2.2.20 on all three legs1 FCS and MAC · 2 de-encapsulate · 3 look up the table, lower TTL · 4 encapsulate · 5 transmit

IPs travel end to end; frames are rebuilt on every link. Diagram: The House of Routing.

Every router repeats five steps:

  1. Receives the frame: checks the FCS and that the destination MAC is its own (or a broadcast meant for it). If something fails, it drops it.
  2. De-encapsulates: removes the layer 2 header and trailer and keeps the IP packet.
  3. Looks up the destination in the routing table, subtracts 1 from the TTL (if it reaches 0, it drops the packet and reports it with ICMP) and recomputes the header checksum.
  4. Encapsulates the packet in a new frame for the exit interface. On Ethernet it uses ARP to learn the next hop’s MAC.
  5. Transmits the frame out of the exit interface.
The key idea: without NAT, the source and destination IP addresses do not change along the way. What changes at every hop is the layer 2 frame: source MAC, destination MAC and even the link type (Ethernet, serial and so on). If the router has no route for the destination, it drops the packet.

Reading the routing table

The routing table is the list of networks the router knows and the path to each one. You see it with show ip route:

R_CCS_01# 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
       * - candidate default
Gateway of last resort is 172.17.0.2 to network 0.0.0.0

S*    0.0.0.0/0 [1/0] via 172.17.0.2
      172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks
C        172.16.0.0/16 is directly connected, FastEthernet0/0
L        172.16.0.1/32 is directly connected, FastEthernet0/0
      172.17.0.0/16 is variably subnetted, 2 subnets, 2 masks
C        172.17.0.0/16 is directly connected, Serial0/0/0
L        172.17.0.1/32 is directly connected, Serial0/0/0
S     172.18.0.0/16 [1/0] via 172.17.0.2
O     172.20.0.0/16 [110/65] via 172.23.0.4, 00:02:11, Serial0/1/0

Read each route from left to right:

FieldExampleWhat it means
CodeOHow the route was learned: C connected, L local, S static, O OSPF, D EIGRP, R RIP, B BGP. The asterisk marks the candidate default route.
Prefix and mask172.20.0.0/16The destination network
[Administrative distance/metric][110/65]How trustworthy the source is and the path cost for that protocol
Next hopvia 172.23.0.4The neighbor router the packet is sent to
Age00:02:11How long ago the route was learned or updated (dynamic routes only)
Exit interfaceSerial0/1/0Where the packet goes out
Gateway of last resort172.17.0.2Where packets go when no other route matches

Every active interface with an IP creates two routes: the C route to its network and the L route, a /32 with the interface’s own address. If the interface goes down, both disappear.

For your notes. show ip route 172.20.1.5 tells you which route the router would use for that exact address. show ip route static, connected or ospf filter by source.

How it picks the best route

When a packet arrives, the router applies these rules in order:

  1. Longest prefix match: of all the routes that contain the destination, the one with the longest prefix, that is the most specific, wins.
  2. To install a route in the table, if two different sources offer the same prefix, the one with the lower administrative distance wins.
  3. If the same protocol offers several paths to the same prefix, the lower metric wins.
  4. If everything ties, the router installs several paths and load-balances across them (ECMP). OSPF and EIGRP use up to 4 paths by default (maximum-paths).
The longest match ruleFor destination 10.1.1.10 three routes match: 10.0.0.0/8, 10.1.0.0/16 and 10.1.1.0/24. The router picks the one with the longest prefix, the /24, regardless of administrative distance or metric. The default route 0.0.0.0/0 is used only if nothing else matches.THE LONGEST PREFIX WINSDestination10.1.1.1000001010.00000001.00000001.0000101010.0.0.0/8/8 bitsmatches10.1.0.0/16/16 bitsmatches10.1.1.0/24/24 bitswins: 24 matching bits0.0.0.0/0/0 bitslast resort

10.1.1.10 matches three routes; the /24 wins. Diagram: The House of Routing.

Exam tip. Administrative distance and metric do not compete with longest match. An OSPF route to 10.1.1.0/24 beats a static route to 10.1.0.0/16 for destination 10.1.1.10, even though the static has distance 1, because they are different prefixes and the /24 is more specific.

Administrative distance

Administrative distance (AD) measures trust in a route’s source: the lower, the better. It is compared only when two different sources offer exactly the same prefix.

Administrative distanceAdministrative distance tells how trustworthy a route’s source is. When two sources offer the same prefix, the router installs the lower value: connected 0, static 1, internal EIGRP 90, OSPF 110, RIP 120, external EIGRP 170 and iBGP 200. 255 means the route is not used.THE LOWER THE DISTANCE, THE MORE TRUSTConnected0Static1eBGP20Internal EIGRP90OSPF110IS-IS115RIP120External EIGRP170iBGP200Unknown: not used255It only breaks ties for the same prefix learned from different sources

Default administrative distances in Cisco IOS. Diagram: The House of Routing.

Route sourceADRoute sourceAD
Connected0OSPF110
Static1IS-IS115
EIGRP summary route5RIP120
External BGP (eBGP)20External EIGRP170
Internal EIGRP90Internal BGP (iBGP)200
Unknown (not used)255

Metric

The metric compares paths within the same protocol, and each one computes it in its own way: RIP counts hops (maximum 15), OSPF adds up link costs (based on bandwidth) and EIGRP combines bandwidth and delay. That is why comparing an OSPF metric with a RIP metric makes no sense: that is what administrative distance is for.

Static routes

A static route tells the router, by hand, how to reach a network. The basic syntax is:

ip route network mask { next-hop | exit-interface [next-hop] } [distance]
Static routes in both directionsR1 and R2 are joined by a 172.17.0.0/16 serial link. R1 knows its LAN 172.16.0.0/16 and R2 its own, 172.18.0.0/16. Each router needs a static route to the other’s LAN; if the return route is missing, ping fails even though the forward path works.EACH ROUTER NEEDS THE WAY THERE AND THE WAY BACKLAN 1172.16.0.0/16R1R2LAN 2172.18.0.0/16S0/0/0 · 172.17.0.0/16.1.2R1ip route 172.18.0.0 255.255.0.0 172.17.0.2R2ip route 172.16.0.0 255.255.0.0 172.17.0.1Without the return route, the reply never comes back

A route there on R1 and a route back on R2. Diagram: The House of Routing.

R_CCS_01(config)# ip route 172.18.0.0 255.255.0.0 172.17.0.2
R_MIA_01(config)# ip route 172.16.0.0 255.255.0.0 172.17.0.1
R_CCS_01# show ip route static
S     172.18.0.0/16 [1/0] via 172.17.0.2
R_CCS_01# ping 172.18.0.10
!!!!!

There are three ways to say where the route goes:

FormExampleComment
Next hopip route 172.18.0.0 255.255.0.0 172.17.0.2The most common. The router does a recursive lookup to find which interface reaches 172.17.0.2.
Exit interfaceip route 172.18.0.0 255.255.0.0 serial0/0/0Shows as “directly connected”. Fine on point-to-point links; on Ethernet it relies on proxy ARP and is not recommended.
Fully specifiedip route 172.18.0.0 255.255.0.0 g0/1 10.0.0.2Interface and next hop: the clearest option on Ethernet links

And by what they cover:

  • Network route: to a subnet, such as 172.18.0.0/16.
  • Host route: to a single address, with a /32 mask (ip route 10.9.9.9 255.255.255.255 172.17.0.2).
  • Default route: to 0.0.0.0/0, for everything that is unknown.
  • Floating route: a backup static with a high administrative distance.

A static route enters the table only if its exit interface is up or its next hop is reachable. Remember to always configure the return route: ping has to go there and come back.

Default route

A branch with a single way out does not need to know every internet network. The default route, 0.0.0.0/0, matches any destination, but with the shortest possible prefix: it is used only when no more specific route exists.

Default route and gateway of last resortA branch with a single way out to the internet does not need to know every network in the world: a default route 0.0.0.0/0 toward the provider is enough. In the table it shows as S* and as the gateway of last resort.0.0.0.0/0: EVERYTHING I DO NOT KNOWLAN10.10.0.0/16BranchR1Provider203.0.113.1Internetip route 0.0.0.0 0.0.0.0 203.0.113.1Gateway of last resort is 203.0.113.1 to network 0.0.0.0S* 0.0.0.0/0 [1/0] via 203.0.113.1

Everything not in the table goes out toward the provider. Diagram: The House of Routing.

R1(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.1
R1# show ip route | include last resort|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

A layer 2 switch does not use routes: you configure ip default-gateway for its management traffic. As soon as you enable ip routing on a layer 3 switch, you need a default route like on any router.

Floating static routes

A floating route is a backup static route that you give a higher administrative distance than the primary route. While the primary exists, the floating route stays out of the table; if the primary disappears, the floating route “floats up” and is installed.

Floating static routeR1 learns the headquarters network through OSPF, with administrative distance 110, over the primary link. It also has a static route with distance 200 over the backup link. While OSPF works, the static stays out of the table; if the primary link fails, the static floats up and is installed.THE BACKUP WAITS OUTSIDE THE TABLER1Headquarters10.50.0.0/16Primary · OSPF · AD 110Backup · static · AD 200ip route 10.50.0.0 255.255.0.0 192.0.2.2 200The floating route’s AD must be higher than the primary route’s

OSPF over the primary link and a static with AD 200 over the backup. Diagram: The House of Routing.

! primary: default route through provider 1
R1(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.1
! backup: same route through provider 2, with AD 5
R1(config)# ip route 0.0.0.0 0.0.0.0 198.51.100.1 5
R1# show ip route static
S*    0.0.0.0/0 [1/0] via 203.0.113.1

If the primary is a static (AD 1), any higher value works. If it is dynamic, the floating route must exceed that protocol’s AD: more than 110 to back up OSPF and more than 90 for internal EIGRP. If you set a lower AD, the “floating” route replaces the dynamic route and stops being a backup.

Watch out: the primary route has to leave the table for the floating route to come in. If the primary link stays up but the problem is further away, a static route with a next hop stays installed. In production this is combined with IP SLA and track, which are not on the exam.

IPv6 static routes

The logic is the same: prefix, next hop or interface and, optionally, administrative distance. First the router must have IPv6 routing enabled with ipv6 unicast-routing.

R1(config)# ipv6 unicast-routing
! network route with a global next hop
R1(config)# ipv6 route 2001:db8:2::/64 2001:db8:12::2
! default route
R1(config)# ipv6 route ::/0 2001:db8:12::2
! link-local next hop: the interface is required
R1(config)# ipv6 route 2001:db8:3::/64 gigabitethernet0/1 fe80::2
! floating backup
R1(config)# ipv6 route ::/0 2001:db8:13::3 200
R1# show ipv6 route static

If the next hop is a link-local address (FE80::/10), the router needs the exit interface, because the same link-local can repeat on several links. An IPv6 host route uses /128. In the IPv6 chapter you will see full addressing.

Router-on-a-stick and SVIs

In chapter 3 you saw that each VLAN is a subnet and that a layer 3 device is needed to move between them. Videos 3 and 4 of this chapter configure it step by step.

Router-on-a-stick with a native VLAN

R_CCS_01(config)# interface fastethernet0/0
R_CCS_01(config-if)# no shutdown
R_CCS_01(config-if)# interface fastethernet0/0.100
R_CCS_01(config-subif)# encapsulation dot1Q 100
R_CCS_01(config-subif)# ip address 192.168.0.1 255.255.255.0
R_CCS_01(config-subif)# interface fastethernet0/0.200
R_CCS_01(config-subif)# encapsulation dot1Q 200
R_CCS_01(config-subif)# ip address 192.168.1.1 255.255.255.0
R_CCS_01(config-subif)# interface fastethernet0/0.99
R_CCS_01(config-subif)# encapsulation dot1Q 99 native
R_CCS_01(config-subif)# ip address 172.16.99.1 255.255.255.0

Each subinterface is its VLAN’s default gateway and creates its own connected route. The native keyword tells which VLAN arrives untagged; you can also put the native VLAN’s IP directly on the physical interface. The native VLAN must match the switch’s.

SVIs on a layer 3 switch

MLS1(config)# ip routing
MLS1(config)# vlan 10
MLS1(config-vlan)# vlan 20
MLS1(config-vlan)# interface vlan 10
MLS1(config-if)# ip address 10.1.10.1 255.255.255.0
MLS1(config-if)# no shutdown
MLS1(config-if)# interface vlan 20
MLS1(config-if)# ip address 10.1.20.1 255.255.255.0
MLS1(config-if)# no shutdown
MLS1(config-if)# exit
MLS1(config)# ip route 0.0.0.0 0.0.0.0 10.1.99.2

An SVI is up/up only if the VLAN exists on the switch, has at least one active port (an access port in that VLAN or a trunk carrying it in forwarding state) and the SVI is not shut down.

Troubleshooting

When a ping between networks fails, walk the path methodically:

StepWhat you checkCommand
1The PC’s IP, mask and default gatewayipconfig · ip a
2That the router’s interfaces are up/up with the right IPshow ip interface brief
3That every router on the path has a route to the destinationshow ip route 172.18.0.10
4That the return route exists on the router at the other endshow ip route on the remote router
5Where the path breakstraceroute (router) · tracert (Windows)
6Subinterfaces, native VLAN and trunks (if there are VLANs)show interfaces trunk · show vlan brief
Typical mistakes: the return route is missing; a wrong next hop or one that belongs to no connected network; a wrong mask on the route; a floating route with a lower AD than the primary; the encapsulation dot1Q tag does not match the switch’s VLAN; an SVI down because the VLAN does not exist or has no active ports; ip routing not enabled on the layer 3 switch.

For your notes. A traceroute that shows asterisks from a given hop usually points to the router where the route is missing or where the reply finds no way back.

What you take away

  • A router chooses the best route and switches the packet to the exit interface. It does not forward broadcasts.
  • IP is a routed protocol; OSPF, EIGRP, RIP and BGP are routing protocols. IGP inside the AS; EGP (BGP) between ASes.
  • At every hop the MACs change and the TTL drops; the source and destination IPs stay the same.
  • Table: code, prefix, [AD/metric], next hop, age and interface. C and L appear with each active interface.
  • Decision order: longest match; then AD between different sources; then metric; then load balancing.
  • AD: connected 0, static 1, eBGP 20, EIGRP 90, OSPF 110, RIP 120, external EIGRP 170, iBGP 200.
  • ip route network mask next-hop; always configure the return route.
  • Default route: ip route 0.0.0.0 0.0.0.0 …, shown as S* and the gateway of last resort.
  • Floating: the same route with a higher AD than the primary (above 110 to back up OSPF).
  • IPv6: ipv6 unicast-routing and ipv6 route; with a link-local next hop, give the interface.

In the next chapter you stop writing routes by hand: routers learn them on their own with OSPF, the dynamic routing protocol the CCNA requires.

AGLE methodInstructor-guidedThe class slides and videos.

Slides

These slides support the guided class: view them here, full screen, or download the PDF for your notes. Part 1 is the chapter’s theory base; Part 2 goes with videos 1 and 2; and Part 3 with videos 3 and 4.

Class videos

The videos are in Spanish. The translation of the videos is in development.

Each part of the chapter has its own video. Tap a card and the video opens right here, over the page; use the Close button or the Esc key to go back to where you were. Use them alongside the slides of the same part.

When you play a video, it loads from YouTube (no cookies until you open it). See the full playlist on YouTube.

AGLE methodLabsHands-on practice in Packet Tracer.

Packet Tracer labs

The labs are in Spanish. The translation of the labs is in development.

Download each lab's files and open them with Cisco Packet Tracer. Tap the name to see the two downloads.

Lab 1The routing process

You enable OSPF on the Caracas router R_CCS_01 with router ospf 1 and its networks in area 0, save the configuration and check the table with show ip route. Then, in Simulation mode, you follow a ping and watch how the ARP frame and the IP packet travel from router to router. Console and enable password: gj123.

Lab 2Static routing

With the 172.16.0.0 network split into a /16 per branch, you configure R_CCS_01’s interfaces, create a static route to the Miami LAN (172.18.0.0/16) and, on R_MIA_01, the return route to Caracas (172.16.0.0/16). You verify with show ip route and a ping from PC_MIA_01. Console and enable password: gj123.

Lab 3Inter-VLAN routing with router-on-a-stick

In Caracas you create subinterfaces FastEthernet0/0.100 (192.168.0.1/24) and 0/0.200 (192.168.1.1/24) with encapsulation dot1Q, bring up the trunk on SW_CCS_01 and assign the ports to VLANs 100 and 200 so the PC and the server can talk across VLANs. Console and enable password: gj123.

AGLE methodContinuous assessmentExam-style questions to measure your progress.

Chapter assessment

There are 100 single-choice questions, split into 10 tabs of 10. Each tab mixes every topic in the chapter and rises in level: questions 1 to 3 are low difficulty, 4 to 8 are medium and 9 to 10 are high.

We do not save your answers. They run in your browser and, if you close or reload the page, you start from zero. Getting it wrong here is the cheapest way to learn.

Additional resources

These links take you to official sites outside this portal. Use them to practice, go further and confirm what you learned.

To study and practice

Exam and certification

Cisco documentation

Source and credits. Chapter built from Jesús Espinoza’s “Routers and IPv4 routing” notes (parts 1 and 2) and slides (CCNA 200-301, part 5), paraphrased, updated and aligned with the official CCNA 200-301 v1.1 exam topics. Text drafted with AI assistance; original diagrams by The House of Routing. Technical details were checked against official Cisco documentation.

Navigate