Networking section

From SaruWiki
Revision as of 21:52, 22 June 2008 by Saruman! (talk | contribs) (First outline of nonperistent and persistent routing)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Routes under Debian

When you need to add a networking route, there generally are two ways to do it:

  1. manually adding a route at the command prompt: this means that the machine will "understand" the route for as long as it is running. However, when you reboot the machine, it will have "forgotten" the route. This is called a non-persistent route.
  2. adding a route to the networking configuration files, so that it will be in place regardless of reboots or network restarts. This is called a persistent route.

Manipulating non-persistent routes

From the days of yore, the venerable route command enables us to view, add, change and delete routes. Its most known use is for printing the current routing table:

#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   UG    0      0        0 eth1    *        U     0      0        0 eth0   *        U     0      0        0 eth1
default         UG    0      0        0 eth1

The addition of -n makes sure the route command does not try to substitute DNS names for IP addresses it knows. The second most used incarnation of route lies in the addition of a route, as has happened in the previous example. The route was added to the routing table using something like this:

#route add -net netmask gw

However, there is a newer command available to us, that gives us a bit more options (however, at the cost of losing the well-known output format): this is the ip command, which is part of the essential iproute2 package:

#ip route show via dev eth1  src dev eth0  proto kernel  scope link  src dev eth1  proto kernel  scope link  src
default via dev eth1

This is the output from the same system as the previous example. However, we see something interesting here: "ip" is capable of adding extra information to the route, like the first line shows (it's using "via"). The addition of that particular route would go like this:

#ip route add via src

Ofcourse, being capable of adding routes means we also need to be capable of deleting them:

#route del -net netmask
#ip route del

As you can see, we only need to specify the target of the route to delete, not the options

Manipulating persistent routes