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.

Show the routing table with iproute2:

Or show the routing table using :

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 using the  command:

Or show routing table using :

On older systems you possibly will use the 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
For users of netifrc, to add a permanent static route, open your favorite text editor to and adjust accordingly. Make sure to refer to your current routing table for help.

With dhcpcd as network manager the static route goes into Dhcpcd instead.

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 0.0.0.0/0 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 its own IP network segment, and there is no specific route found in the routing table for target IP network

External resources

 * Longest prefix match (on Wikipedia)