Linux route add command

by Vivek Gite on February 7, 2008 · 9 comments

Q. How do I add new / default gateway using route command under Linux?

A. You can use any one of the following tool to add route:

=> route command : show / manipulate the IP routing table

=> ip command : show / manipulate routing, devices, policy routing and tunnels

Linux route add using route command

Route all traffic via 192.168.1.254 gateway connected via eth0 network interface:
# route add default gw 192.168.1.254 eth0

Linux route add using ip command

Just like above but with ip command:
# ip route add 192.168.1.0/24 dev eth0

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 9 comments… read them below or add one }

1 Chris Jackson October 29, 2008

Changes to survive a reboot can be set in
/etc/sysconfig/networking/devices/route-ethX

Other profiles for switching between different configurations can be found in
/etc/sysconfig/networking/profiles/default/route-ethX

Reply

2 Momo February 14, 2009

Dear All,

I have a problem , my default route will go away when i reboot my system, regarding to this matter that all info was issued under interface network-script.

Please advice,
Momo.

Reply

3 sandheep February 23, 2009

Hi ,

Can you please let me know how to add the route command in Linux.

Regards
Sandheep

Reply

4 sunil sharma August 6, 2010

Hi
add the route command in linux

# route add -net 10.10.1.1/24 ethx
Alternate is by ip command
# ip route add 10.10.2.2/24 ethx
after that configure gateway,netmask and ip in route-ethx file located in /etc/sysconfig/network-scripts dir.

Thanks.

Reply

5 Prosper Mbabazi May 15, 2009

Adding the route command in Linux

Route traffic via 192.168.0.5 gateway destined to 192.168.1.16 :

route add -net 192.168.1.16 netmask 255.255.255.240 gw 192.168.0.5

This will handle all the traffice from your client systems destined to the 192.168.1.16 subnet.
The resources that will be accessed are in the range 192.168.1.16 – 192.168.1.30

I have tried it on Suse Linux, and i belive other flavors are similar or close to this .

Thanks

Prosper

Reply

6 Mr-lol July 30, 2009

To add default route for a host:
#route add 192.168.0.1 gw 10.0.0.1
“where 192.168.0.1 is destination host, gw commad to specify gateway and 10.0.0.1 is the gateway to destination host. (Test on Feroda 11)”

Reply

7 Alex December 14, 2010

Another way to add route at startup (testing on CentOS)

edit file /etc/rc.d/rc.local (add to end of file your route):
/sbin/route add -net 192.168.11.0 netmask 255.255.255.0 gw 10.0.0.1

After reboot check your route table:
/sbin/route

Reply

8 Pankaj March 16, 2011

i want to add below command in Linux server.but here it is showing error

[root@plnotxsmsc01 rc.d]# route add -net 10.202.11.0 gw 10.102.13.241
bash: route: command not found
[root@plnotxsmsc01 rc.d]#

=====

[root@plnotxsmsc01 rc.d]# uname -a
Linux plnotxsmsc01 2.6.18-128.el5xen #1 SMP Wed Dec 17 12:01:40 EST 2008 x86_64 x86_64 x86_64 GNU/Linux
[root@plnotxsmsc01 rc.d]#

Reply

9 Ranjith June 7, 2011

Dear Pankaj,

please try /sbin/route or locate where the route is

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 11 + 8 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: