Lecture #4 - Routing Basics

What Does a Router Do?

A router forwards packets between networks, one hop closer to its intended destination. The destination may be either a host on a directly connected network (ie. the router can perform direct delivery) or it may need to forward the IP datagram on to another router (ie. the next hop in the delivery process).

Routing Information Base

Each router has its own Routing Table or Routing Information Base (RIB), which lists all of the networks that are known to this router. Each entry (or route) within the routing table specifies a network address, a netmask and the IP address of the next hop. The interface(s) that the IP datagrams could be delivered through are also identified. A measure of desirability or a routing metric is also associated with each route.

Routes are installed into the routing table from various sources - they may be manually (statically) configured, or they may be learned via the use of a dynamic routing protocol (more on this in a later lecture!) Routes corresponding to directly connected networks are normally automatically configured when an IP address (and corresponding netmask) is assigned to a network interface.

Forwarding Information Base

It is possible (in fact it is quite common) for a router to know about multiple routes to the same destination network. As a result most routers create a Forwarding Information Base (FIB) which contains the preferred or selected route(s) for each known network. This is effectively a subset of the information stored within the routing table. Routing decisions are made based on the information stored within a router's FIB, reducing the overhead associated with making a routing decision.

Normally the route installed in the FIB is based on the path that has the "best metric" and is currently available, although it is also possible to have a router balance the load across a number of paths.

Whilst the routing decision is simple (it has to be because it has to be made for every packet), the development of the routing table and FIB can be quite complicated. In later lectures, we are going to examine a number of the routing protocols that are used to construct these tables.

Routing vs Switching (or Bridging)

In principle, routing and switching both perform the same sort of task.

Switches base the forwarding decision on the destination header in the link level header (in the outer layer of encapsulation). Routers base the forwarding decision on the destination header in the network level header (in the next layer of encapsulation). This effectively unlinks the addressing and delivery from the physical network.

Reasons for this "two layer" addressing scheme include:

If link level addresses had been allocated in "networks" as IP addresses had been, it may have been possible to avoid one level of encapsulation.

What is in a Router Anyway?

The design of a low end router is very similar to that of a conventional computer:

CPU
Runs the Operating System (OS) and routing program(s).
ROM
Holds a "monitor" program, sufficient to load the main operating system. May hold a small permanent part of the OS. On "real cheap routers"™ the ROM holds the entire OS.
NVRAM
Non-volatile ("battery backed" or semi-permanent) RAM which holds the configuration data.
Flash Memory
Some routers use this to hold the operating system. It is "permanent" memory, which can be re-written.
RAM
Holds the working/running copies of the operating system, routing tables, configuration files, etc. Also packets are queued here awaiting transmission.
Network Interfaces
Two or more adapters to interface with or "talk to" the network cabling eg. Ethernet, Serial, Optical.

When switched on, "mid range" routers copy the Operating System from Flash memory to RAM, copy the configuration file from NVRAM into RAM, then configure the interfaces and begin building their routing tables. Forwarding of datagrams commences when the router has enough information to determine where packets should be sent to.

Initiating Communication

Most Cisco routers have a serial "console port", through which the initial configuration is done. Additional configuration may be performed via a network based remote login or via the serial console.

Console Characteristics

Network Access

If configured, telnet or SSH can be used via one (or maybe more) of the routers network interfaces in order to administer the router. This is how routers are normally managed in the "real world"™.

SNMP can also be configured allowing for monitoring to be peformed.

Console Modes

Cisco routers implement several different input modes:

User Mode
User mode is "mostly harmless". Most commands are just for looking around. Obviously this still has some potential security/information leakage issues associated with it.
Privileged Mode
Allows for the use of "privileged" commands. Can enter Configuration Mode.
Configuration Mode
Allows for configuration changes to be made to the router. All commands have an immediate effect on the router's behaviour.
ROM MONitor (ROMMON) Set Up Mode
Used to recover from lost passwords and other nasty scenarios. To secure a router, some sort of locked enclosure is required.
Set Up Mode
Used initially to encourage the network administrator to enter some of the more important configuration information. This information can also be provided via Configuration Mode.

The console prompt changes to indicate which mode the router in:

Each mode has its own set of commands.

The Cisco console provides help on all available commands (it's terse though).

Commands are not accepted unless complete. Incomplete or syntactically wrong commands are flagged, showing where command interpretation failed.

Simply repeating the good part of the command with a question mark appended will cause the router to show the options available to complete the command.

A Sample Configuration

Entered in Configuration Mode:
no service config                Turn off "configure from network"
hostname R1                      Set router's name (harmless)
no cdp run                       Disable "Cisco Discovery Protocol"

interface Ethernet0/0            Configure a network interface
 ip address x.x.x.x y.y.y.y      Specify IP address and subnet mask
 no shutdown                     Make interface active
 half-duplex                     Obvious
!                                Finished doing Ethernet0/0
interface Ethernet1/0
 ip address p.p.p.p q.q.q.q
 no shutdown
 half-duplex
!
ip routing                       Enable routing of IP datagrams
router rip                       Use RIP to discover topology
 network x.x.x.x                 Broadcast & listen for RIP
 network p.p.p.p                 on these networks
!
end                              Back to Privileged Mode.

Then back in Privileged Mode, issue the following command to save the currently active ("running") configuration to NVRAM so that it will be loaded next time the router is turned on:

copy running-config startup-config

Some Useful Commands

? Can be used anywhere to find out what to type next.
show running-config (Privileged Mode) Displays currently active configuration file. This may be different to what was loaded at boot time (edited by network administrator).
show startup-config (Privileged Mode) Displays configuration that will be loaded next time the router is booted up.
show ip route (Privileged Mode) Ask router to display its view of the network.

Static Routing

The easiest way to provide routing information is through the use of static routes. These are manually specified by providing the router with the network, netmask and next hop address. For small networks static routing can be the easiest and quickest way to setup routing tables, however static routing does not scale well. Adding one additional network will most likely require an additional route to be manually configured on every router within the network.

However, static routing does have several advantages over the use of a routing protocol. Firstly, the network overhead is lower since there is no need to exchange information with other routers in order to learn about the network. Secondly, there is no risk of learning incorrect routes from a misconfigured (or misbehaving) router.

Under Cisco IOS a static route can be specified as follows:

ip route x.x.x.x y.y.y.y z.z.z.z

Where x.x.x.x is the network address, y.y.y.y is the netmask and z.z.z.z is the next hop router. In order for a static route to be accepted IP routing must be enabled with the ip routing command and the next hop router must already be reachable via an existing route.

Default Routes

A Default Route is a special form of static route - one that is used as a last resort when no other route exists for the destination network. These can be useful for situations when all "external" traffic leaves the network via one connection. They are also useful as a fallback position should the normal route become unavailable.

A default route is configured using the following:

ip route 0.0.0.0 0.0.0.0 z.z.z.z

Where z.z.z.z is the default gateway or router.

Load Balancing

Static routes can also be configured in a way that results in traffic being load balanced across two links. Under Cisco IOS, configuring two static routes to the same network will result in equal-cost load sharing. The following commands would result in two static routes to the same network (10.1.1.0/24):

ip route 10.1.1.0 255.255.255.0 10.1.2.1
ip route 10.1.1.0 255.255.255.0 10.1.3.1

Packets destined for this network would then be load balanced via the 10.1.2.1 and 10.1.3.1 routers.

Floating Routes

Static routing can also be used to implement backup routes, otherwise known as floating routes. In this situation the floating route is not used unless the primary route becomes unavailable, at which point the floating route takes over.

The configuration of a floating route is almost the same as for load sharing, however an additional parameter is specified to denote the administrative distance - this is simply a routing metric provided by the administrator:

ip route 10.1.1.0 255.255.255.0 10.1.2.1
ip route 10.1.1.0 255.255.255.0 10.1.3.1 50

The second route via 10.1.3.1 would not be used, only appearing in the FIB if the first route via 10.1.2.1 becomes unreachable.

Longest Prefix Match

Where a router has a number of routing table entries that all match a given IP address, the best match is found by:

  1. Beginning at the first bit of the IP address (the most significant bit), compare the IP address with the routing table entry.
  2. Continue bit by bit until a mismatch is found or all the IP address bits match.
  3. If the match length is less than the CIDR network mask, declare "no match".
  4. Continue for all likely routing table entries.
  5. The routing table entry chosen is the one having the greatest number of matching leading bits.