Static routing

What is a Route
A route is a rule, set in your kernel, to determine which physical network interface or which gateway to use, to reach a particular network (or single host). There are many types of routed protocols this article simply covers routing of the IP protocol. IP routes are stored in the kernel.

To see the current routing table on your host use:

netstat is a part of the default installed package

show the routing table with

Adding a Static Route
To add a static route you have to know the IP and the subnet mask of a network you wish to route, and the gateway to that network. In this example we route the network 10.10.10.0 with the netmask 255.255.255.0 to the gateway 192.168.1.50. needs CIDR style netmasks, so it will be in this example10.10.10.0/24

Adding a static route with

Show the routing table:

Or as a system user you show the routing table as this:

On older systems you possibly will use the route command instead of the upper described to add a static route:

The routing table is sorted from most specific routes to most general, and this is how it is read by the routing process. Longest prefix match - means the the smallest network, or the network with the largest netmask, or the most specific route f.e. 255.255.255.255 is at first position in a routing table

Adding a Permanent Static Route
To add a permanent static route, open your favorite text editor to /etc/conf.d/net and adjust accordingly. Make sure to refer to your current routing table for help.

Both statements above mean:
 * 1) IP packets destined to the 10.10.10.0/24 network are send to 192.168.1.50
 * 2) IP packets destined to all 0.0.0.0/0 other networks are send to 192.168.1.1

The default route is used if:
 * the host has no physical or logical IP interface in the target network segment
 * the host has to send IP packets outside of his own network segment and there is no specific route in the routing table

External resources

 * http://en.wikipedia.org/wiki/Longest_prefix_match