The route Command-Adding and Removing Routes

The UNIX route command is the generic interface to manipulate the kernel's IP routing table or cache. It essentially can add, delete, and monitor entries and can flush the entire forwarding table. The tool works a little bit differently on Linux systems. In addition, Linux provides the alternative ip utility from the iproute2 package with everything under one hood.

NOTE

You can retrieve everything there is to know about adding and deleting routes from the following man pages on BSD and Linux systems: route(4), route(8), rtentry(9), rtalloc(9), arp(4), arp(8), ifconfig(8). For Linux systems, you can access further information from the structures of the proc system and the manual page proc(5).


Example 8-1 shows the commands necessary to access routing-relevant proc information on Linux systems; Example 8-2 is a reminder of the routing table flags on Linux and FreeBSD as described by the route and netstat manual pages. These flags are implementation-specific, as is the representation of the routing table on NetBSD, FreeBSD, OpenBSD, and Linux. Specific details can be derived only from inspecting the kernel code.

Example 8-1. Retrieving Linux proc System Information

[root@callisto:~#] cat /proc/net/route

[root@callisto:~#] cat /proc/net/rt_cache

[root@callisto:~#] cat /proc/net/rt_cache_stat


Example 8-2. Linux and FreeBSD Routing Table Flags

### Linux ###

              U (route is up)

              H (target is a host)

              G (use gateway)

              R (reinstate route for dynamic routing)

              D (dynamically installed by daemon or redirect)

              M (modified from routing daemon or redirect)

              A (installed by addrconf)

              C (cache entry)

              ! (reject route)



### FreeBSD ###

1    RTF_PROTO1       Protocol specific routing flag #1

2    RTF_PROTO2       Protocol specific routing flag #2

3    RTF_PROTO3       Protocol specific routing flag #3

B    RTF_BLACKHOLE    Just discard pkts (during updates)

b    RTF_BROADCAST    The route represents a broadcast address

C    RTF_CLONING      Generate new routes on use

c    RTF_PRCLONING    Protocol-specified generate new routes on use

D    RTF_DYNAMIC      Created dynamically (by redirect)

G    RTF_GATEWAY      Destination requires forwarding by intermediary

H    RTF_HOST         Host entry (net otherwise)

L    RTF_LLINFO       Valid protocol to link address translation

M    RTF_MODIFIED     Modified dynamically (by redirect)

R    RTF_REJECT       Host or net unreachable

S    RTF_STATIC       Manually added

U    RTF_UP           Route usable

W    RTF_WASCLONED    Route was generated as a result of cloning

X    RTF_XRESOLVE     External daemon translates proto to link address