How do you add a route to Linux

Hello All,

I need to add a route to linux and do not know how.  I know nothing about linux so I need a step by step answer.

This is what I do in windows, I go to a command prompt and type the followng

Route add -p 172.16.0.0 mask 255.255.255.0 192.168.0.3

Route add -p 192.168.5.0 mask 255.255.255.0 192.168.0.3

How and where to you do that in linux?

Thank you

Mike

MickaelEAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

grbladesCommented:
Hi MickaelE,
You can use this syntax:-
route add -net 16.0.0.0 gw 192.168.0.0 netmask 25.255.255.0
0
paranoidcookieCommented:
route add gw 192.168.0.1

where 192.168.0.1 is the address of the gateway

man route
0
grbladesCommented:
This method will not be persistant (the -p parameter in windows). You can add the command to the end of /etc/rc.d/rc.local so that it runs whenever the computer starts if you wish it to be permanent.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

MickaelEAuthor Commented:
Hi Grblades,

Would you mind using my numbers in the example, I am not sure which goes where?

Mike
0
paranoidcookieCommented:
Dont know for other linuxes but in debian /etc/network/interfaces

auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
0
MickaelEAuthor Commented:
This is for Redhat linux
0
grbladesCommented:
In redhat you can edit /etc/sysconfig/network and set a line such as:-
GATEWAY=10.0.0.2
This only sets the default route. If you need additional static routes edit the rc.local file as I described previously.
0
deurkCommented:
In rc.local file for next reboots and in console for actual session:

route add -net 172.16.0.0 netmask 255.255.255.0 gw 192.168.0.3
route add -net 192.168.5.0 netmask 255.255.255.0 gw 192.168.0.3

Hope this helps.
0
wesly_chenCommented:
> Would you mind using my numbers in the example,
> Route add -p 172.16.0.0 mask 255.255.255.0 192.168.0.3
==> # /sbin/route add -net 172.16.0.0 netmask 255.255.255.0 gw 192.168.0.3

> Route add -p 192.168.5.0 mask 255.255.255.0 192.168.0.3
==> # /sbin/route add -net 192.168.5.0 netmask 255.255.255.0 gw 192.168.0.3

Need to be root to do it.

Wesly
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
deurkCommented:
Errr... I just wrote that ^^
0
kidomanCommented:
Hi,

Not wanting to duplicate answers (deliberately or otherwise) I would suggest that you use the newer "iproute2" package available in most newer linuxes.

The commands in that case would be:

ip route add 172.16.0.0/24 via 192.168.0.3
ip route add 192.168.5.0/24 via 192.168.0.3

Explanation:

ip route is the command you are invoking. You are telling the command to add a route for network 172.16.0.0/24 (this is equivalent to having 24 bits for network id, i.e. netmask = 255.255.255.0 A single 255 represent 8 bits.) via the gateway address 192.168.0.3. Similarly for the second route.

To make these persistent. Simply execute the following line on you favorite shell (konsole, bash, etc.)

echo "ip route add 172.16.0.0/24 via 192.168.0.3" >> /etc/rc.local
echo "ip route add 192.168.5.0/24 via 192.168.0.3" >> /etc/rc.local

THis is a very good method of appending lines to the /etc/rc.local file in linux. This file is like a autoexec.bat file and is executed every time you reboot. So next time you reboot, these two lines (i.e. the text inside the quotes.) will be present in this file and thus will be executed and you will again have your routes setup.

Cheers,

Karan
0
thribhuCommented:
hi,

This is exact
If u want to assign route for NIC 1
 
route add -net 172.16.0.0 netmask 255.255.255.0 gw 192.168.0.3 dev eth0
route add -net 192.168.5.0 netmask 255.255.255.0 gw 192.168.0.3 dev eth0

if u restart the system the route may not exist.....

so edit this file /etc/rc.local file and add your static routes using the route statement. I mean add the above lines.

even your reboot the system the routes exist................
0
deurkCommented:
lol the guy got the points... what a rip off ^^
0
MickaelEAuthor Commented:
Hi

You are right.  Sorry I clicked on the wrong accept button.  Is there a way to correc it?
0
grbladesCommented:
If you ask here http://www.experts-exchange.com/Community_Support/ a moderator will unaccept the answer for you.
0
huynhcaokyCommented:
lol, poor you, Deurk!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Networking

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.