Salta al contenuto
Note per Studenti Cisco Routers Report

Cisco Routers

In questa pagina 9

See also: Network Devices - Hub, Switch and RouterDevices that interconnect networks differ by the highest layer of the stack they read. Hub (layer 1): a repeater, regenerates the signal and sends it out of all ports, all stations share the capacity. Bridge and switch (layer 2): read the MAC address and forward only to the right port, learning the table (FDB) from source addresses. Router (layer 3): reads the IP address and joins independent networks (internetwork). Switches and bridges isolate traffic and are plug and play; the router gives optimal routing but must be configured.Network Devices - Hub, Switch and Router →, Forwarding and Routing TablesForwarding moves each packet one hop at a time toward its destination; it is direct when the destination is on a local network (ARP gives its MAC) and indirect otherwise (the packet goes to the next hop or default gateway given by the routing table). With netmasks, delivery is direct on interface x if the destination AND the mask equals the interface address AND the mask; otherwise the table is scanned from the longest mask (longest prefix match) and the default route 0.0.0.0/0 always matches; route aggregation shortens tables.Forwarding and Routing Tables →.

Laboratory 4 is done with real devices, not Katharà: two Cisco routers and three Linux PCs. For the PCs the commands are those of Static Routing and Diagnostic Tools in KatharàLab 2 builds by hand the routing tables of two LANs (195.11.14.0/24 and 200.1.1.0/24) joined by routers r1 and r2 over 100.0.0.8/30: an active interface adds only its directly connected network, hosts use a default route, routers need static routes in both directions, and ping, route -n, tcpdump and traceroute diagnose the result (ttl=62 after two routers).Static Routing and Diagnostic Tools in Katharà →; for Cisco routers a different syntax is learned. The task is to build a linear topology, configure addresses and routing tables of all elements, and check with ping the communication between every pair.

The linear topology

 pcB (eno1: lab network, unchanged)
 pcB enp2s0 .1 --- .2 FE0/0 r1 FE0/1 .1 --- .2 eno1 pcC enp2s0 .1 --- .2 FE0/0 r2 FE0/1 .1 --- .2 eno1 pcD
          192.168.2x.0/24        192.168.3x.0/24                192.168.4x.0/24         192.168.5x.0/24

The value x is the number of the bench row of the PC: PC 1-4 →x=0\to x=0, 5-8 →1\to1, 9-12 →2\to2, 13-16 →3\to3, 17-20 →4\to4, 21-24 →5\to5; for PC number nn, x=⌊(n−1)/4⌋x=\lfloor(n-1)/4\rfloor. For x=2x=2 the networks are 192.168.22.0/24, 192.168.32.0/24, 192.168.42.0/24, 192.168.52.0/24. If pcD is pc24 (x=5x=5), its eno1 is 192.168.55.2/24.

PC eno1 enp2s0
pcB unchanged (lab network) 192.168.2x.1/24
pcC 192.168.3x.2/24 192.168.4x.1/24
pcD 192.168.5x.2/24 unused
router FE 0/0 FE 0/1
r1 192.168.2x.2/24 192.168.3x.1/24
r2 192.168.4x.2/24 192.168.5x.1/24

eno1 is the PC's native interface, enp2s0 the second card (if it does not appear, ifconfig -a lists also down interfaces). FE 0/0 and FE 0/1 are the router's FastEthernet interfaces. On each network the device on the left takes .1, the one on the right .2.

Accessing a Cisco router

The router has no screen or keyboard: a PC is attached to its console port with a serial cable. Connect the PC serial port (/dev/ttyUSB0) to the router console, connect the Ethernet cables to FE 0/0 and FE 0/1, then (login rdclab, sudo for admin privileges):

bash
rdclab@pcXX# minicom -D /dev/ttyUSB0 -8b 9600    # -D serial port; -8b 8 data bits; 9600 baud

Exit minicom with Ctrl+A then X. If the prompt routerXX# appears you are already privileged; otherwise press Enter several times.

Cisco command modes

The router has a hierarchy of modes; the prompt says where you are.

mode prompt how to enter how to leave
User EXEC routerXX> initial access logout ends the session
Privileged EXEC routerXX# enable (with password) disable back to User EXEC
Global Configuration routerXX(config)# configure terminal exit, end or Ctrl+Z
Interface Configuration routerXX(config-if)# interface FastEthernet 0/0 exit (one level up), end (to Privileged)
Router Configuration routerXX(config-router)# router <protocol> exit, end

Seeing and changing system parameters needs Privileged EXEC (#). end (or Ctrl+Z) returns to Privileged EXEC from any configuration mode. Router Configuration is for routing protocols and is not used in this lab.

Configuring router addresses

Router1# configure terminal                         ! enter global configuration
Router1(config)# no ip routing                      ! turn IP forwarding off (reset state)
Router1(config)# ip routing                         ! turn it on: the router now routes between interfaces
Router1(config)# interface FastEthernet 0/0         ! configure interface FE 0/0
Router1(config-if)# ip address <ip> <mask>          ! address and mask (e.g. 192.168.22.2 255.255.255.0)
Router1(config-if)# no shutdown                     ! activate the interface (off by default)
Router1(config-if)# interface FastEthernet 0/1
Router1(config-if)# ip address <ip> <mask>
Router1(config-if)# no shutdown
Router1(config-if)# end                             ! back to Privileged EXEC

Text after ! is a Cisco comment. ip address uses the mask written in full (255.255.255.0), not the prefix. The network of the interface is address AND mask: 192.168.22.2 AND 255.255.255.0 == 192.168.22.0. no shutdown turns the interface on: Cisco interfaces start off (in Katharà up was enough); the prefix no cancels a command.

Example (x=2x=2). r1: FE 0/0 →\to 192.168.22.2 255.255.255.0; FE 0/1 →\to 192.168.32.1 255.255.255.0. r2: FE 0/0 →\to 192.168.42.2, FE 0/1 →\to 192.168.52.1.

Routes on Cisco routers

From global configuration:

ip route <destination> <mask> <gateway address>      ! add a static route
ip route <destination> <mask> <interface>            ! same, giving the output interface
no ip route <destination> <mask> <gateway address>   ! delete it
ip route 0.0.0.0 0.0.0.0 <gateway address>           ! default route

Formula. ip route <network> <mask> <next hop>: "to reach <network>/<mask> send to <next hop>", with the mask in full. The default route is network 0.0.0.0 with mask 0.0.0.0.

Example (x=2x=2). On r1, to reach the network of pcD: ip route 192.168.52.0 255.255.255.0 192.168.32.2 (through eno1 of pcC). Directly connected networks are in the table automatically.

Mask and wildcard. ip address and ip route use the mask; other commands (access lists, OSPF network) use the wildcard, its complement: 255.255.255.255−mask255.255.255.255-\text{mask} octet by octet. 255.255.255.0 →\to 0.0.0.255; /30 →\to 0.0.0.3; /20 →\to 0.0.15.255. A 00 means "this bit must match", a 11 "do not care".

Check commands from Privileged EXEC: show interfaces (state and addresses), show ip route (routing table), show ip cache (routing cache).

Configuring the PCs

bash
ifconfig <interface> <address> netmask <mask> broadcast <broadcast> up   # address and activation
route add default gw <gateway> dev <interface>                            # default route
route add -net <network> netmask <mask> gw <gateway> dev <interface>      # static route
sysctl -w net.ipv4.ip_forward=1                                           # IP forwarding enabled (pcC only)

The last line is for PCs acting as routers: pcC sits between r1 and r2 and must forward packets from one interface to the other; without net.ipv4.ip_forward=1 the Linux kernel drops them (in Katharà forwarding is already on). It needs sudo.

Complete configuration (example x=2x=2)

pcB (keeps eno1):

bash
ifconfig enp2s0 192.168.22.1 netmask 255.255.255.0 broadcast 192.168.22.255 up
route add -net 192.168.32.0 netmask 255.255.255.0 gw 192.168.22.2 dev enp2s0
route add -net 192.168.42.0 netmask 255.255.255.0 gw 192.168.22.2 dev enp2s0
route add -net 192.168.52.0 netmask 255.255.255.0 gw 192.168.22.2 dev enp2s0

r1 (Cisco):

interface FastEthernet 0/0
 ip address 192.168.22.2 255.255.255.0
 no shutdown
interface FastEthernet 0/1
 ip address 192.168.32.1 255.255.255.0
 no shutdown
exit
ip route 192.168.42.0 255.255.255.0 192.168.32.2
ip route 192.168.52.0 255.255.255.0 192.168.32.2

pcC (in the middle):

bash
ifconfig eno1 192.168.32.2 netmask 255.255.255.0 broadcast 192.168.32.255 up
ifconfig enp2s0 192.168.42.1 netmask 255.255.255.0 broadcast 192.168.42.255 up
sysctl -w net.ipv4.ip_forward=1
route add -net 192.168.22.0 netmask 255.255.255.0 gw 192.168.32.1 dev eno1       # left: via r1
route add -net 192.168.52.0 netmask 255.255.255.0 gw 192.168.42.2 dev enp2s0     # right: via r2

r2 (Cisco):

interface FastEthernet 0/0
 ip address 192.168.42.2 255.255.255.0
 no shutdown
interface FastEthernet 0/1
 ip address 192.168.52.1 255.255.255.0
 no shutdown
exit
ip route 192.168.22.0 255.255.255.0 192.168.42.1
ip route 192.168.32.0 255.255.255.0 192.168.42.1

pcD:

bash
ifconfig eno1 192.168.52.2 netmask 255.255.255.0 broadcast 192.168.52.255 up
route add default gw 192.168.52.1 dev eno1     # only exit: r2

A ping from pcB to pcD, step by step (destination 192.168.52.2):

node route used next hop TTL on exit
pcB 192.168.52.0/24 192.168.22.2 (r1) 64 (starts at pcB)
r1 ip route 192.168.52.0 255.255.255.0 192.168.32.2 192.168.32.2 (pcC) 63
pcC 192.168.52.0/24 192.168.42.2 (r2) 62
r2 connected network (FE 0/1) direct delivery to pcD 61

pcD receives TTL 6161 (r1, pcC, r2 each subtracted 11). The reply starts at pcD with TTL 6464 and returns symmetrically, arriving at pcB with 64−3=6164-3=61, the ttl=61 read in ping. More hops also raise the RTT: the lab sheet asks to note times from near to far.

Rule for a linear topology. Each node has a route for every far network, with next hop the neighbour on the side where that network lies; the two adjacent networks are connected and need no routes. E.g. r1 sends the 4x and 5x networks to the right.

Required checks

At every step, check with ping the communication between every pair of devices and note the times, from near to far, up to pcB ↔\leftrightarrow pcD. The final test is a traceroute:

bash
traceroute 192.168.52.2      # from pcB to pcD: crosses r1, pcC and r2

The path shows 192.168.22.2 (r1), 192.168.32.2 (pcC, acting as router) and 192.168.42.2 (r2), then pcD. In Wireshark the IP headers of the probes show increasing TTL and ICMP time exceeded from the routers. The lab ends with the Finish button.

Common mistakes

  • Forgetting no shutdown: the interface stays off (show interfaces gives administratively down).
  • Writing the prefix (/24) in Cisco commands: the full mask is required.
  • Forgetting sysctl -w net.ipv4.ip_forward=1 on pcC: packets arrive and do not leave.
  • A wrong value of x.
  • Missing a route: every node must know all far networks (forward and return).
  • Typing at the wrong prompt: ip route in Global Configuration, ip address in Interface Configuration.

Versione ripasso

  • LAB4, real devices. Linear topology pcB - r1 - pcC - r2 - pcD with networks 192.168.2x.0/24 (pcB-r1), 3x (r1-pcC), 4x (pcC-r2), 5x (r2-pcD). On each network the left device takes .1, the right .2. x=⌊(n−1)/4⌋x=\lfloor(n-1)/4\rfloor for PC nn (PC 1-4 →0\to0 ... 21-24 →5\to5). For x=2x=2: 192.168.22.0/24, 32, 42, 52.
  • Addresses. pcB enp2s0 .2x.1 (eno1 untouched); pcC eno1 .3x.2, enp2s0 .4x.1; pcD eno1 .5x.2; r1 FE 0/0 .2x.2, FE 0/1 .3x.1; r2 FE 0/0 .4x.2, FE 0/1 .5x.1. ifconfig -a if enp2s0 is missing.
  • Access. Serial cable /dev/ttyUSB0 to the console, minicom -D /dev/ttyUSB0 -8b 9600, exit Ctrl+A then X, sudo for privileges.
  • Modes. User EXEC routerXX>; enable gives Privileged EXEC #; configure terminal gives (config)#; interface FastEthernet 0/0 gives (config-if)#; router <protocol> gives (config-router)#. exit one level up; end or Ctrl+Z to #; disable to >; logout.
  • Commands on r1 (x=2x=2).
no ip routing
ip routing
interface FastEthernet 0/0
 ip address 192.168.22.2 255.255.255.0       ! mask in full, not the prefix
 no shutdown                                 ! Cisco interfaces start off
interface FastEthernet 0/1
 ip address 192.168.32.1 255.255.255.0
 no shutdown
exit
ip route 192.168.42.0 255.255.255.0 192.168.32.2   ! network, mask, next hop
ip route 192.168.52.0 255.255.255.0 192.168.32.2
  • Routes. ip route <network> <mask> <gateway> from (config)#; no ip route ... deletes; default ip route 0.0.0.0 0.0.0.0 <gateway>. Checks from #: show interfaces, show ip route, show ip cache. Wildcard =255.255.255.255−=255.255.255.255-mask (/24 gives 0.0.0.255, /30 gives 0.0.0.3).
  • Linux PCs. ifconfig <if> <ip> netmask <m> broadcast <b> up, route add default gw <gw> dev <if>, route add -net <net> netmask <m> gw <gw> dev <if>. Middle PC: sysctl -w net.ipv4.ip_forward=1.
  • Full configuration (x=2x=2). pcB: enp2s0 192.168.22.1, three routes via 192.168.22.2 to 32, 42, 52. pcC: eno1 192.168.32.2, enp2s0 192.168.42.1, ip_forward=1, routes 192.168.22.0 via 192.168.32.1 and 192.168.52.0 via 192.168.42.2. r2: FE 0/0 192.168.42.2, FE 0/1 192.168.52.1, routes to 192.168.22.0 and 192.168.32.0 via 192.168.42.1. pcD: eno1 192.168.52.2, default via 192.168.52.1.
  • Rule. Every node needs a route for every far network, next hop the neighbour on that side; adjacent networks are connected.
  • Checks. ping between all pairs, from near to far, noting times; final traceroute 192.168.52.2 from pcB crosses r1 (192.168.22.2), pcC (192.168.32.2), r2 (192.168.42.2); TTL 64 at pcD gives ttl=61 at pcB (64−364-3).
  • Mistakes: missing no shutdown (administratively down); /24 instead of the mask; ip_forward off on pcC; wrong xx; missing route; wrong mode (ip route in Global, ip address in Interface).