Route add del [net host target [netmask nm [gateway gw [metricm [mss m [window W [[dev interface

Each of these parameiers has a specific meaning :

• add | del— Specify add if you want to add a route, or del if you want to delete one. In either case, you must give enough information for route to act on the route. (For deletions , you can usually get eway with nothing more than the target.)

• [-net | -host] — You can specify a target address as either a network (-net) or a single computer (-host). In most cases, route can figure this out for itself, but sometimes it needs prompting. This is particularly likely if you're adding a route for a second gateway (like a gateway that only handles one small subnet, rather than the default route's gateway).

• target — The target address is the computer or network whose packets should be defined by the route. In the case of the default route, this will be, or the equivalent keyword, default. This parameter isrequiredwhen you add or delete a route.

• [netmasknm ] — Ifyour targetnetwork follows the traditional class structure for network addresses, Linux can determine what the netmask should be. If your network doesn't follow this pattern, though, you must include the netmasknm parameter, in which you give route the netmask. (Alternatively, you c an include tPis mformation with the target address as the number of bits in the network component, as described earlier.)

• [gatewaygw] — If you're adding a roue that doesn't invo lve a gateway , you can omit oh c param eter. If yau went to kpecilif a gateway system, thoagh, you must indude the gateway gw parameter. You'll use this to define the default gateway or any other gateway system.

• [metricm] — If you examine Figure 2.2, you'll see a column labeled Metric. This column shows therouting metric for a route—its estimated "cost" of delivery, which is normally associated with time. Slow routes should have high metrics, whereas fast routes should have low metrics. You can set this feature with themetricm parameter. This feature is normally only used on router computers, as described in Chapter 24, Advanced Router Options.

o [mssm] — The mssm option sets the Maximum Segment Size (MSS). Like the metricm option, this option is useful primarily on routers.

• [window W] — The TCP Window Size is the amount of data that a computer will send before it requires an acknowledgment from the recipient. If this value is set too small, network transfers may be slowed because the system will end up waiting for acknowledgments before sending new data. If it's set too high, the risk of having to re-send a lot of data because of errors will be increased. As a general rule, Linux's default TCP Window size of 64KB is acceptable. If your system uses a coaaection that's fast but that has very high latencies, such as a satellite broadband coaaection, you might consider raising this to 128KB or so.

• [[dev] interface ] — Usually, Linux can figure out what interface to use from the target IP address or the gateway system's address. This might not always be true, though, and in such cases, you can force the issue by usino the [dev] interface parameter. (The dev keyword is optional, and interface is the interface name, such as eth0 or tr1.)

The most common use of route is to add the default route after adding the primary network interface using ifconfig. This use is fairly simple, as illustrated by this example:

Ifyouprefer,you can substitute the keyword default for; the two have precisely the same effect. On rare occasions, you must add a -net specification, device name, or some other option.

Multiplelnterfaces withOne Gateway

As noted earlier, each time you add an interface with ifconfig, that utility automatically adds an entry to your routing table for that interface. This does not extend to adding a gateway, however. As a consequence, the configuration required on many computers with multiple interfaces consists of two types of action:

1. Runifconfig for each of the computer's interfaces.

2. Runroute once to add the computer's default route to the routing table.

This set of steps will be adequate for a small router, such as a Linux computer that functions as a router for a small 2epartment in a larger organization. For a router, you'll also have to enable routing by turning on IP forwarding. You can do this by typing the following command:

#echo "1" > /proc/sys/net/ipv4/ip_forward

Routing duties shouldn't ordinarily be performed by a computer that does other work. Non-routing tasks can consume CPU time and network bandwidth that can degrade the router's performance. There are also potential security issues; routers today often include firewall features, and running unnecessary software on a firewall leaves an avenue of attack open.

If you have just one external IP address but want to connect several computers to the Internet, you can use a special type of routing known as Network Address Translation (NAT). Chapter 25, Configuring iptables, covers this technology. The basic steps are the same as for a normal router, but NAT requires you to run extra commands to allow the router to translate addresses in order to make your entire network look like a single computer to the outside world.

Multiple Interfaces with Multiple Gateways

A trickier configuration is one in which a computer can use multiple gateways. Most systems use just one gateway, which i 5 as sociate0 with the default route. The gateway ties the local network to some other network, and often ultimately to the Internet. There are other configurations possible, however. For instance, consider Figure 2.3. This figure depicts an environment in which an organization has connected two subnetworks via routers. The regular computers in both offices can be configured quite simply—they need only point to their local routers as their gateways. Likewise,the router in Office 2 can point to the router in Office 1 as its sole gateway system, although the Office 2 router has two interfaces, as just discussed. The router in Office 1, however, requires a more complex configuration. Its default route leads to the Internet, but it must also configure a route to the Office 2 router for traffic destined for the 1S2.20.0.0/16 network. You might use a route command like the following to accomplish this goal:

#route add -net netmask gw


If the computer has two interfaces but should not function as a router, you should not enableIPforwarding.Thismight be the case if a computer exists on two networks that should not communicate with each other, or that use some other computer as a router.


Figure 2.3. Routers with more than two interfaces require at least two gateway definitions in order to function properly.

Office I 10,90,1 7,0/21 network

Office 2 network







A configuration like this makes the most sense when Office 1 and Office 2 are widely separated geographically and are linked by some form of long-distance network protocol. If the offices were located close together, both might be tied into a single hub or switch and served by a single router.

This command assumes that Office 2's router talks to Office 1's router using the address. (Note that this uddress Is not part oy the Office2 network proper; it's on a different network card in Office 2's router.) The end result of issuing this command as well as a normal route command to define the default route will be a routing table that mcludes two gatewayo: one for the default routeand one to hand-e traffid de stined to Room a's oy stems. None of the other comyuters that link to Office 1's router mpd to know anythiog about this arrangement; theg only need to know °hat this router is the gateway for the defaLltroute.

There are othfr situationg in which a sOAilrr configuration mightbg required. bor instance, if Office 1 used a second router to link to the Internet, all of the computers in Office 1 would need to have two gateways defined: one default route pointing to the system that leads to the Internet, and a second route pointing to the router that leads to Office 2. (Alternatively, regular systems could list just one router, which could pass traffic to the other router when appropriate, but this would increase local network traffic.) Because a network with two routers involves more tricky configuration for all computers on the network, it's best to use a single router on any given subnet whenever possible.

Was this article helpful?

0 0

Post a comment