Chapter 6. Routing with Linux

Linux on ordinary commodity hardware can handle small to medium routing needs just fine. The low- to mid-range commercial routers use hardware comparable to ordinary PC hardware. The main difference is form factor and firmware. Routers that use a real-time operating system, like the Cisco IOS, perform a bit better under heavy loads than Linux-based routers. Big companies with large, complex routing tables and ISPs need the heavy-duty gear. The rest of us can get by on the cheap just fine. You don't want poor-quality hardware; that's always a bad idea. You just don't need to spend the moon for simple routing like this chapter covers.

The highest-end routers use specialized hardware that is designed to move the maximum number of packets per second. They come with multiple fat data buses, multiple CPUs, and Ternary Content Addressable Memory (TCAM) memory. TCAM is several times faster than the fastest system RAM, and many times more expensive. TCAM is not used in lower-cost devices, and no software can shovel packets as fast as TCAM.

But, for the majority of admins, this is not an issue because you have an ISP to do the heavy lifting. Your routing tables are small because you're managing only a few networks that are directly under your care.

In this chapter, we're going to perform feats of static routing using the route and ip commands, and dynamic routing using two interior routing protocols, Routing Information Protocol (RIP) and Open Shortest Path First (OSPF).

How do you know which one to use? RIP is the simplest to implement. Every 30 seconds it multicasts its entire routing table to your whole network, and all RIP routers update their routing tables accordingly. RIP is known as a distance-vector routing algorithm because it measures the distance of a route by the number of hops, and it calls the path to the next hop a vector. RIP is limited to 15 hops; if any destination is farther than that, RIP thinks it is unreachable.

RIP works fine for managing stable, less-complex networks.

OSPF is a link-state algorithm, which means a router multicasts its information when changes have occurred, and routine updates every 30 minutes. Each OSPF router contains the entire topology for the network, and is able to calculate on its own the best path through the network.

As your network grows, it becomes apparent that updates are the bottlenecks. When you're riding herd on 50 or 100 or more routers, they're going to spend a lot of time and bandwidth talking to each other. OSPF solves this problem by allowing you to divide your network into areas. These must all be connected to a common backbone, and then the routers inside each area only need to contain the topology for that area, and the border routers communicate between each area.

You'll need to know several similar methods for doing the same things. The net-tools package is the old standby for viewing, creating and deleting routes, viewing information on interfaces, assigning addresses to interfaces, bringing interfaces up and down, and viewing or setting hostnames. The netstat command is a utility you'll use a lot for displaying routes, interface statistics, and showing listening sockets and active network connections. These are the commands that come with net-tools:

Debian puts hostname in a separate package. dnsdomainname, domainname, nisdomainname, and ypdomainname are all part of hostname.

In fact, the different Linux distributions all mess with net-tools in various ways, so yours may include some different commands.

iproute2 is supposed to replace net-tools, but it hasn't, and probably never will. iproute2 is for policy routing and traffic shaping, plus it has some nice everyday features not found in net-tools, and it has the functionality of net-tools. It includes these commands:

ip and tc are the most commonly used iproute2 commands. ip does the same jobs as route, ifconfig, iptunnel, and arp. Just like net-tools, iproute2 varies between distributions. tc is for traffic-shaping.

It would be lovely to have to know only one of these, but you're going to encounter both, so you might as well get familiar with all of them.