Computer Networks / Practical class / Practical class 11
Practical class · Computer Networks

Static routing and configuration

This is session 1 on static routing (basics). You will type ip route commands by hand on three routers linking the Andijan, Namangan and Fergana branches, learn to read the routing table and program the “longest prefix” rule in Python. Complex cases — backup routes, summarization and troubleshooting — are in practical class 12 (session 2).

:ik-kitob: Practical class 11 ⏱ 2 academic hours (80 minutes) 🚇 Packet simulators ⚡ Every route is drawn by hand
11

Lesson goals and plan

By the end of the lesson you will…

  • read the C, L, S, S* entries in a routing table and explain what each one means
  • determine, for each router, which networks are “directly connected” and which need a static route
  • write the ip route command in Cisco IOS correctly, with a next-hop and with an exit interface
  • understand the “return route” problem and check two-way connectivity with ping
  • shorten the configuration with a default route (0.0.0.0/0)
  • write the longest prefix match search in Python with the ipaddress module

Plan (according to the syllabus)

  1. Static routing and configuration

The golden rule of static routing: a packet needs a path both to get there and to come back. If ping fails, first ask “did it get there?”, then “is there a path for the reply?” This class is part 1; the continuation (backup routes, faults) is in practical class 12.

What does a router do when it does not know where to send a packet?

The answer is short and harsh: it drops the packet. A router does not “guess” and does not “ask” its neighbour (unless a dynamic protocol is enabled). All it knows is the networks attached to it and the routes the administrator wrote by hand. Today you become that administrator: you will draw a “map” for three branch routers and send the first ping from a computer in Andijan to a computer in Fergana.

Key terms

Theory reminder

In practical class 10 you saw what routing is: the router looks at the destination IP of the packet, finds the best-matching entry in the table and sends the packet along that path (lecture 11). The table is filled from three sources: directly connected networks, static routes (today) and dynamic protocols (practical classes 13–14).

Table 11.1. Codes in show ip route
CodeMeaningExample
CConnected — the network where the interface is locatedC 192.168.1.0/24 is directly connected, GigabitEthernet0/0
LLocal — the router’s own interface address (/32)L 192.168.1.1/32 is directly connected, GigabitEthernet0/0
SStatic — a manually entered route; [1/0] = [administrative distance / metric]S 192.168.3.0/24 [1/0] via 10.0.12.2
S*Static default route (candidate default)S* 0.0.0.0/0 [1/0] via 10.0.12.2

Command syntax

Cisco IOS — global configuration modeR1(config)# ip route NETWORK MASK NEXT-HOP [AD]
R1(config)# ip route 192.168.3.0 255.255.255.0 10.0.12.2          # via next hop (recommended)
R1(config)# ip route 192.168.3.0 255.255.255.0 g0/1               # via exit interface
R1(config)# ip route 0.0.0.0 0.0.0.0 10.0.12.2                    # default route
R1(config)# no ip route 192.168.3.0 255.255.255.0 10.0.12.2       # delete
Table 11.2. Commands you will need today
Command (short form)ModeRole
enable (en)R1>Enter privileged mode → R1#
configure terminal (conf t)R1#Configuration mode → R1(config)#
ip route …R1(config)#Add a static route
end(config)Return to privileged mode
show ip route (sh ip ro)R1#View the table; in config mode — do show ip route
show ip interface briefR1#Interfaces, IP addresses and their status
ping, tracerouteR1#Check reachability and the path
write / copy run startR1#Save the configuration (so that it is not lost on reboot)

Static routing and configuration

Session 1

In the course syllabus this topic is split into two sessions. Today (practical class 11) — the basics: reading the table, finding the missing networks, ip route and the default route, LPM. Practical class 12 — the continuation: a four-router network, floating (backup) routes, administrative distance, summarization, recursive lookup and troubleshooting.

Scenario: the training centre at ADU has three branches. Each has its own local network (LAN) and a router. The routers are linked by point-to-point links (/30). Your task is to make all the branches “see” each other.

R1R2R3 AndijanNamanganFergana 10.0.12.0/30 g0/1 .1.2 g0/1 10.0.23.0/30 g0/2 .1.2 g0/2 192.168.1.0/24PC1 .10 (gw .1) 192.168.2.0/24PC2 .10 (gw .1) 192.168.3.0/24PC3 .10 (gw .1) g0/0g0/0g0/0
Fig. 11.1. Topology: 5 networks (3 LANs + 2 /30 links). Each router knows only the networks attached to it.

Worked task 1. Who is missing what?

Condition: for each router, determine the directly connected networks and the networks that need a static route.

  1. List of all networks

    192.168.1.0/24, 192.168.2.0/24, 192.168.3.0/24, 10.0.12.0/30, 10.0.23.0/30 — 5 in total.

  2. Analyse R1

    Connected: 192.168.1.0/24 (g0/0), 10.0.12.0/30 (g0/1). Missing: 192.168.2.0/24, 192.168.3.0/24, 10.0.23.0/30 — 3 networks. The next hop for all of them is R2’s address facing us, 10.0.12.2.

  3. Analyse R2

    Connected: 192.168.2.0/24, 10.0.12.0/30, 10.0.23.0/30. Missing: 192.168.1.0/24 (→ 10.0.12.1) and 192.168.3.0/24 (→ 10.0.23.2) — 2 networks.

  4. Analyse R3

    Connected: 192.168.3.0/24, 10.0.23.0/30. Missing: 192.168.1.0/24, 192.168.2.0/24, 10.0.12.0/30 — all via 10.0.23.1, 3 networks.

  5. Total

    3 + 2 + 3 = 8 static routes. Both the forward and the return direction are counted for every path.

Worked task 2. Configuring the routers

  1. R1 (Andijan)
    R1> enable
    R1# configure terminal
    R1(config)# ip route 192.168.2.0 255.255.255.0 10.0.12.2
    R1(config)# ip route 192.168.3.0 255.255.255.0 10.0.12.2
    R1(config)# ip route 10.0.23.0 255.255.255.252 10.0.12.2
    R1(config)# end
    R1# show ip route
  2. The first check — and the first “disappointment”

    Now if you press “PC1 → ping 192.168.3.10”, you get U.U.U: the packet reaches R2, but R2 does not yet know 192.168.3.0. A static route must be present on all routers along the path.

  3. R2 (Namangan)
    R2(config)# ip route 192.168.1.0 255.255.255.0 10.0.12.1
    R2(config)# ip route 192.168.3.0 255.255.255.0 10.0.23.2
  4. The second check

    Ping again: now the packet reaches PC3, but the reply does not come back (.....) — R3 does not know the path to 192.168.1.0. This is the return route problem.

  5. R3 (Fergana) — and victory
    R3(config)# ip route 192.168.1.0 255.255.255.0 10.0.23.1
    R3(config)# ip route 192.168.2.0 255.255.255.0 10.0.23.1
    R3(config)# ip route 10.0.12.0 255.255.255.252 10.0.23.1

    Now !!!!! — Success rate is 100 percent.

Lab: router console

The console below runs Cisco IOS commands in a simplified way: enable, conf t, ip route, no ip route, show ip route, show run, show ip int brief, ping, traceroute, interface, shutdown. The router buttons switch between consoles, and the PC buttons below send ping from the computers. For every failed ping the console also prints the reason (a real router has no such “advisor”!). Run the commands above and close tasks 1–4 with “Check the task”.

:ik-terminal: Router console: Andijan — Namangan — Fergana

R1>
Press the “Check the task” button.
Tip

Commands can be abbreviated: en, conf t, sh ip ro. To look at the table without leaving configuration mode use do sh ip ro. To recall the previous command press the ↑ key. Delete a wrongly entered route with no ip route ….

Default route: “everything else goes that way”

R1 and R3 are edge (stub) routers: they have only one way to the outside world. There is no need to write every remote network separately on them — one default route is enough:

R1(config)# ip route 0.0.0.0 0.0.0.0 10.0.12.2      # R1: every foreign network → R2
R3(config)# ip route 0.0.0.0 0.0.0.0 10.0.23.1      # R3: every foreign network → R2

The 0.0.0.0/0 prefix has 0 bits — it matches any address, but being the shortest prefix it is chosen only when no other entry matches. Your home Wi-Fi router works exactly this way: it sends everything outside the local network to the provider. R2 is the central (transit) router: it needs specific routes for the LANs on both sides. The result is 4 routes instead of 8 — that is the Boss task in the console.

Warning

If two neighbouring routers point default routes at each other (R1 → R2, R2 → R1), a packet sent to an unknown address “plays tennis” between them until the TTL expires — a routing loop. That is why a default route is normally used only on edge routers, in the “towards the Internet” direction. Finding loops is the topic of practical class 12.

The router’s brain in Python: longest prefix match lookup

Behind every ping in the console the router performs one operation: it finds in the table the entry that matches the address and has the longest prefix. With Python’s ipaddress module this takes a few lines:

import ipaddress
tarmoq = ipaddress.ip_network("192.168.0.0/16")
ip = ipaddress.ip_address("192.168.3.10")
print(ip in tarmoq)            # True — the address belongs to this network
print(tarmoq.prefixlen)        # 16 — prefix length
print(tarmoq.netmask)          # 255.255.0.0

Independent tasks

6 tasks from easy to hard: each is a small “automation” from an administrator’s daily work. Write input() without a prompt; the “Check” button runs the tests.

Note the result: 162 routes for 10 branches! If one new branch is added — every router has to be edited by hand. This very problem gave rise to dynamic routing (practical class 13).

Common mistakes

ErrorSignFix
Return route forgottenping: ..... (the request arrives, no reply)On the routers at the destination side add a route to the source network
No route on an intermediate router along the pathping: U.U.U; traceroute stops at that routerCheck every router along the path
The next hop is the address of a distant routerThe route does not enter the table or goes the wrong wayThe next hop is the address of a directly connected neighbour
Network with a host address (192.168.3.10 /24)%Inconsistent address and maskNetwork address: 192.168.3.0
Wrong mask (/24 instead of /30)Some addresses work, some do notCompare with the prefix in the topology
Skipping enable and going straight to conf t% Invalid inputFirst enable
Configuration not savedRoutes disappear after the router rebootswrite or copy running-config startup-config

Hint: first work out why the program prints nothing (how is the input line being split?), then compare the output line with the sample.

Boss level

Boss level: branch chain auto-configurator

A company wants to link k branches across the valley in a chain. According to the plan: the LAN of branch Ri is 192.168.i.0/24; the link between Ri and Ri+1 is 10.0.i.0/30, where Ri is 10.0.i.1 and Ri+1 is 10.0.i.2. The program reads k and prints for every router all the necessary static route commands (no default routes). Order: the «Ri:» header, then first the LANs (from 1 to k, skipping its own), then the links (from 1 to k−1, skipping the ones it is attached to). Next hop: 10.0.(i−1).1 for networks on the left, 10.0.i.2 for those on the right. +60 XP

Also complete the “Boss” task in the console: make the whole network work with 4 routes (a default route on R1 and R3, specific routes for the two LANs on R2).

Reinforcement

Review questions

What is static routing, and what are its advantages and disadvantages?

Routes written by the administrator by hand. Advantages: simple, predictable, does not consume router resources, secure (no updates are exchanged). Disadvantages: does not adapt automatically when the network changes, and in a large network the number of entries grows sharply.

What do the codes C, L, S and S* mean?

C — a directly connected network, L — the router’s own interface address (/32), S — a static route, S* — a static default route.

Explain the syntax of the ip route command.

ip route NETWORK MASK (NEXT-HOP | INTERFACE) [AD] — in global configuration mode; the network address is written without host bits.

What is the difference between routes written with a next hop and with an exit interface?

The next hop is the IP address of the neighbouring router; the router works out for itself which port to leave through. An exit interface sends the packet straight out of that port; it is convenient on point-to-point links, but on Ethernet it can cause ARP problems.

Why is a route in both directions needed for ping to work?

Ping is a request (Echo Request) and a reply (Echo Reply). For the reply packet to get to the source network, the routers on the destination side must have a route as well.

When is a default route used and what is the risk?

On edge routers — when there is a single way out, “towards the Internet”. The risk: if two routers point default routes at each other, a loop appears for unknown addresses.

What is the longest prefix rule?

If several entries match an address, the one with the greatest prefix length (the most specific network) is chosen; 0.0.0.0/0 is the very last resort.

What is the difference between the U.U.U and ..... results?

U — some router along the path replied “no route to the address” (ICMP Destination Unreachable). A dot — no reply came at all (timeout): the packet or the reply was lost, most often because there is no return route.

Independent work

The independent-study topic in the course syllabus: “Fundamentals of routing and static and dynamic routing methods.” (6 hours). The part related to this class: design static routing for the topology of your variant.

  1. Draw the topology diagram and assign an IP address to every interface (/30 links, /24 LANs).
  2. For each router, build a table of “connected / missing” networks.
  3. Write all the ip route commands (in two variants: with specific routes and with default routes).
  4. Test it in Cisco Packet Tracer (or in a similar topology in the lesson console) and attach screenshots of the ping and traceroute results.
Assessment criteria (individual assignment)
CriterionPoints
The addressing plan is correct, with no overlaps1
The missing networks are correctly determined for each router1
The ip route commands are syntactically and logically correct (both variants)2
Simulator test results (ping, traceroute) are attached1

Summary

A router does only what it knowsA packet for a network that is not in the table is dropped.
C and LConnected networks appear by themselves when the interface comes up.
ip routeNETWORK MASK NEXT-HOP; the next hop is a direct neighbour.
Two directionsThe forward and return paths; on every intermediate router.
Default route0.0.0.0/0 — for edge routers; sharply reduces the number of routes.
LPMThe longest matching prefix is chosen.
DiagnosticsU.U.U — no route; ..... — no reply came back; traceroute shows where it stopped.
Next stepPractical class 12 (session 2): backup routes, AD, summarization, troubleshooting.

Your lesson results

Your results are saved in this browser. Read all the sections and complete the exercises and assignments.

My personal notes