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:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 9 comments… read them below or add one }
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
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.
Hi ,
Can you please let me know how to add the route command in Linux.
Regards
Sandheep
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.
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
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)”
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
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]#
Dear Pankaj,
please try /sbin/route or locate where the route is