Setting the Route

In order to send network traffic, your computer must know to what interface data should be sent. If you only have one Ethernet card, it might seem obvious what interface to use, but it's not quite that simple. Every Linux computer supports a network interface known as the loopback device, which refers to the host computer itself. This interface is locked to the IP address, and is configured automatically. You might also use PPP dial-up networking or have a second NIC. For these reasons, you must set up a routing table, or route, which is a set of rules for the transmission of network traffic.

Routing for a Local Network

Suppose that you're setting up a local network on one interface (let's call it eth0). You want h traffic destined for computers on this interface to go through eth0, but you want other traffic to R

go through another interface, such as a PPP dialup link or another Ethernet board. In order to configure eth0, you use the route command, which has the following basic syntax:

route add | del target [gw gateway]

To add a route, you use the add parameter and specify the target address or addresses. For instance route add

In this example, I've specified an address that ends in .0, which is an indication that this is a network address, not just an address for a single computer. In this case, the system sends all data for the 192.168.33.x network through this route. Because you've already bound eth0 to (using the ifconfig command), Linux can determine that this route is associated with the eth0 device.

Setting the Default Route

Most networked computers have at least two routes: one for the loopback device, and one for everything else. The "everything else" entry sends data through a router, or gateway, computer. The router knows how to send data on to computers on the Internet at large. Thus, your computer doesn't need to know how to access, say,; it simply sends all requests for this—or any other address for which it doesn't have a more explicit route—to the gateway system. You set the default route using the gw option to the route command. For instance route add gw

The IP address is shorthand for any address. You can use default in place of this number, if you like. The address in this example is the IP address of your network's router. You can obtain this address from your network's administrator.

When you start a dial-up PPP session, the pppd program automatically adds appropriate routes to direct your Internet traffic.

As with ifconfig, you can use the route command without any options to examine the status of your routing table. On a simple network configuration, the result might look something like this:

Kernel IP routing table

Destination Gateway Genmask


Flags Metric Ref U 0 0

Use Iface 0 eth0 0 lo 0 eth0

The routing table is arranged from most- to least-specific addresses:

• This address is for a small network (a Class C network). Chances are all the computers on this network are linked to the computer more-or-less directly, on the same coaxial cable or connected to the same hub or switch.

• This is the loopback network. In reality, there's just one computer on this network (the host computer itself), but Linux configures the route as if it were a large (Class A) network.

• default The default route sends data through the gateway machine, for anything that doesn't match either of the two preceding destinations.

After you've set the default route, you should be able to access any computer on the network, albeit only by IP address. To use the more familiar computer names, such as, you must configure your system to use a DNS server.

Was this article helpful?

0 0
The Ultimate Computer Repair Guide

The Ultimate Computer Repair Guide

Read how to maintain and repair any desktop and laptop computer. This Ebook has articles with photos and videos that show detailed step by step pc repair and maintenance procedures. There are many links to online videos that explain how you can build, maintain, speed up, clean, and repair your computer yourself. Put the money that you were going to pay the PC Tech in your own pocket.

Get My Free Ebook

Post a comment