Pages

Saturday, December 26, 2009

Source Routing in Linux

This is about creating source routing in Linux kernel.
For this we'll be using 'iproute2'.
The first file we'll be looking at is 'rt_tables' file. The default complete path for this file is,
'/etc/iproute2/rt_tables'.
Use your favorite editor (gedit, or vi editor) to edit this file. In this file you will see some default values, which are all commented. You will also see some number appearing in them.
The lower the value, the higher the precedence of these numbers will be.
Actually this file holds the name of the routing tables that should looked up for specific instances.
We'll create a routing table name 'my_routes'.
Add the following line to the 'rt_tables' file.

1 my_routes

The next step is to add routes to the table. For this we will use the 'ip route add ' command.
For example we'll say, for all traffic going to 192.168.12.0/24 the next hop is 192.168.12.254 and this entry belongs to the table 'my_routes'.

'ip route add 192.168.12.0/24 via 192.168.1.254 table my_routes'

To add a default route (say the default route is 10.0.0.254)

'ip route add default via 10.0.0.254 table my_routes'

The next step is to say for traffic with a specific source to look-up the table 'my_routes' for routing entries.

'ip rule add from 10.0.0.0/24 table my_routes'

To view the entries,

'ip route show tables'

'ip rule show'

That's it.

Happy Source Routing!!!!