A router is a device that connects two networks together, forming an internetwork. Unlike bridges and switches, routers function at the network layer of the OSI reference model. This means that a router can connect LANs that run completely different data-link layer protocols (such as Ethernet and Token Ring), as long as all of the systems are running the same network layer protocol. Transmission Control Protocol/Internet Protocol (TCP/IP) is the most popular protocol suite in use today, and IP is TCP/IP's network layer protocol, so most of the router information you come across refers to IP routing.
When a computer on a LAN wants to transmit data to a computer on another LAN, the system sends its packets to a router on the local network, and the router forwards them to the destination network. In many cases, the destination system is not located on an adjacent network, so the router has to forward the packets to another router. On a large internetwork, such as the Internet, packets may have to pass through a dozen or more routers on the way to their destination.
The term "router" always refers to a hardware or software device that connects two LANs together at the network layer. In TCP/IP parlance, however, routers are often referred to using the term "gateway." For example, when you configure the TCP/IP client on a Microsoft Windows system, you supply the address of a default gateway, which is actually a router on the local network that the system uses to access other networks. Unfortunately, gateway can also refer to a hardware or software device that operates at the application layer and provides an interface between two programs. For example, an e-mail gateway enables people using one particular e-mail system to send messages to people using another e-mail system. Don't confuse the two.
Because routers operate at the network layer, they transcend the limitations of the data-link layer protocols. Packets arriving at the router travel upwards through the protocol stack to the network layer, and in the process, the data-link layer frame is stripped away. Once the router determines where to send the packet, it passes the data down to a different network interface which encapsulates it within a new frame for transmission. If the two data-link layer protocols involved support different sized packets, the router might have to fragment the network layer data and create multiple frames that are small enough for transmission.
Routers are more selective than hubs, bridges, and switches in the packets that they forward to other ports. Because they operate at the boundaries of LANs, they do not forward broadcast messages, except in certain highly specific cases. A router forwards a packet based on the destination address in the network layer protocol header, which specifies the packet's ultimate destination, and not the hardware address used at the data-link layer. A router has internal tables (called routing tables) that contain information about the networks around it, and it uses these tables to determine where to send each packet. If the packet is destined for a system on one of the networks to which the router is connected, the router transmits the packet directly to that system. If the packet is destined for a system on a distant network, the router transmits the packet across one of the adjacent networks to another router.
As an example, consider a typical corporate internetwork composed of a backbone and several segments connected to the backbone using routers, as shown in Figure 3.6. The computers on each segment use the router connecting it to the backbone as their default gateway. The computers transmit all of the packets they generate either to a specific system on the local network or to the default gateway. The gateway router strips the data-link layer frame from each packet and reads the destination address from its network layer protocol header.
Using the information in its routing tables, the gateway determines which router it must use to access the network on which the destination system is located. The gateway then constructs a new frame for the packet, using the backbone's data-link layer protocol (which can be different from the protocol used on the segment) and specifying the router leading to the destination network as the data-link layer destination address. When the packet reaches the next router, the process repeats itself, except that this router's tables indicate that the destination system is on the segment to which the router is attached. The router can therefore construct a frame that transmits the packet directly to the destination system.
When the packet has to pass through multiple networks on the way to its final destination, each router that processes it is referred to as a hop, as shown in Figure 3.7. In many cases, routers measure the efficiency of a given path through the network by the number of hops that are required to reach the destination. One of the primary functions of a router is to select the most efficient path to a destination, based on the data in its routing tables.
In addition to connecting networks at a single location, such as a corporate internetwork, routers can also connect distant networks using WAN links. Organizations with multiple branch offices often connect the networks in those offices by installing a router at each location, and connecting the routers together using leased telephone lines, or some other WAN technology, such as frame relay. Because each location has a separate broadcast domain, the only packets that pass over the WAN links are those destined for systems on the other networks. This minimizes the amount of traffic passing over those links, thus minimizing their cost.
The most common use for a WAN router is to connect a network to an Internet Service Provider (ISP), providing the computers on the network with access to the Internet. The Internet is the ultimate example of a routed network; thousands of LANs are connected together using many different kinds of routers. To connect your LAN to the Internet, you install a router that can connect to an ISP using any type of technology, from a dial-up modem to Integrated Services Digital Network (ISDN) to a leased line. The router is configured to forward all traffic not destined for the local network to the ISP, which relays it to the Internet.
The routing tables are the heart of a router; without them, there's no way for the router to know where to send the packets it receives. However, the question then arises of where the routing tables come from. Unlike bridges and switches, routers cannot compile routing tables from the information in the data packets they process. This is because the routing table contains more detailed information than is found in a data packet, and also because the router needs the information in the table to process the first packets it receives after being activated. A router can't forward a packet to all possible destinations in the way that a bridge can.
However, the process of building the routing table can still be either manual or automatic. Static routing is the process of manually creating routing table entries. A network administrator decides what the router should do when it receives packets addressed to systems on a particular network and adds entries to the routing table that reflect these decisions. This process is possible on a relatively small network with a handful of routers, but on a larger network, the manual configuration process is too much work and the routers are unable to modify their table to accommodate changes in network status.
The alternative to static routing is dynamic routing, in which routers use specialized protocols to exchange information about themselves and the networks around them. Routers have direct information about the LANs to which they are connected, and use routing protocols to send that information to other routers. When the routers on an internetwork share the contents of their tables using these protocols, all of the routers can have information about more distant networks as well.
There are many different routing protocols, particularly on the Internet, where routing is one of the most complex and vital parts of the internetwork infrastructure. Dynamic routing requires no direct participation by network administrators, other than to install and run the routing protocols, and it also enables routers to automatically modify the information in their tables when the network changes. For example, should a router malfunction, all of the routers that normally communicate with it remove that router from their tables after a given period of time. Those routers then inform others of the malfunction, and the entire network eventually stops trying to use that router. When the offending router is put back into service, the other routers update their tables and begin to use it again.
Part of a router's function is to select the most efficient route to each packet's destination. On a relatively small internetwork such as that pictured in Figure 3.6, there is only one possible route to any particular destination. However, on a more complex network, administrators often install more than one router on each network, to provide alternate routes in case of a malfunction. When multiple routes to a particular destination exist, routers include all of them in their routing tables, along with a value called a metric that specifies the relative efficiency of each route. The nature of the metric depends on the routing protocol used to generate it. In some cases, the metric is simply the number of hops between the router and the destination network. Other protocols use more complex computations to determine the metric.
Most people think of a router as a large, complex device costing tens or hundreds of thousands of dollars, used only on giant enterprise networks. Actually, routers can take many different forms and are far more commonly used than you may think. It is true that many routers are large, powerful, and very expensive. Generally speaking, routers are more expensive than switches, bridges, and hubs. You can indeed find routers on large corporate networks, where they're mounted in racks in data centers and in server closets. These types of routers connect segments to a backbone and provide an entire private internetwork with access to computers in their branch offices and/or the Internet.
However, there are also much smaller and less expensive routers on the market. In fact, if you use the Internet Connection Sharing (ICS) feature in Windows 2000, Windows 98 second edition (SE), or Windows Me to connect your home network to the Internet, you are actually using your computer as a router. Other software-based router products enable you to share dial-up, cable television (CATV) network, and Digital Subscriber Line (DSL) connections with a small network. There are also relatively small hardware routers on the market that you can use for connecting a LAN to the Internet.
For private internetworking, you can use any one of many hardware routers that cover a range of prices, or use a Windows 2000 or Windows NT system with two or more NICs installed in it to route IP traffic between networks. Every computer with a TCP/IP client has a routing table in it, even those that are not strictly functioning as routers. For example, when you use a computer on a LAN to connect to the Internet with a dial-up connection, the system uses its routing table to determine whether requests for network resources should go to the NIC providing the LAN connection or to the modem providing the Internet connection. Even though the system is not providing Internet access to the LAN, it still uses the routing table.