How to add route in Linux

30 Jun, 2008  |  Posted by Danesh  |  in HowTo, Linux

To view the current routing table run “route -n

[root@klmppswdr01p ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.41.42.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.41.41.0 10.41.42.8 255.255.255.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 10.41.42.1 0.0.0.0 UG 0 0 0 eth0

To add a route refer to the command below.

"route add -net 10.41.41.0 netmask 255.255.255.0 gw 10.41.42.8"

To delete a route refer to the command below.

"route del -net 10.41.41.0 netmask 255.255.255.0 gw 10.41.42.8"

The routing information above is not persistent across reboots. After a reboot, the routing information will be lost and you need to add them in again.

To make the routing information persistent, add the “route add” line as seen above into the /etc/rc.local file.

Sample /etc/rc.local file.

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
route add -net 10.41.41.0 netmask 255.255.255.0 gw 10.41.42.8

  • Digg
  • del.icio.us
  • BlinkList
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Furl
  • Google
  • Live
  • Facebook
  • Pownce
  • TwitThis
  • E-mail this story to a friend!
Tags: , , ,

3 Responses so far | Have Your Say!

  1. Wing Loon  |  July 2nd, 2008 at 12:08 am #

    You can shorten the command as below: -

    route add -net 10.41.41.0/24 gw 10.41.42.8

    Wing Loon - Gravatar
  2. Danny  |  July 2nd, 2008 at 5:17 am #

    Thanks WL. My network’s a bit weak ;)

    Danny - Gravatar
  3. Wing Loon  |  July 2nd, 2008 at 11:18 am #

    Hehehe… I am learning too. No worries, :)

    Wing Loon - Gravatar

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>