LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux route add question (https://www.linuxquestions.org/questions/linux-newbie-8/linux-route-add-question-946015/)

HarryBoy 05-20-2012 12:08 PM

Linux route add question
 
On my SLES linux computer when I run 'route' from the command line I get the following:


Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.51.56.254 0.0.0.0 UG 0 0 0 eth1
10.51.56.0 * 255.255.255.0 U 0 0 0 eth1
loopback * 255.0.0.0 U 0 0 0 lo
link-local * 255.255.0.0 U 0 0 0 eth0
192.168.200.0 * 255.255.255.0 U 0 0 0 eth0


I am experimenting with adding other routes manually and from this link: http://www.labtestproject.com/linnet/routing.html

I try to do:
route add -host 10.10.0.5 netmask 255.255.0.0 gw 10.51.56.254

But I get the following error:
route: netmask 0000ffff doesn't make sense with host route
Usage: route [-nNvee] [-FC] [<AF>] List kernel routing tables
route [-v] [-FC] {add|del|flush} ... Modify routing table for
blah blah


1. Can you tell me why this is happening based on my route table
2. Also, what is the difference in adding a host route and a network route??

Thanks

Ser Olmy 05-20-2012 12:37 PM

Quote:

Originally Posted by HarryBoy (Post 4683261)
I try to do:
route add -host 10.10.0.5 netmask 255.255.0.0 gw 10.51.56.254

You're first telling route that you want to add a host route (-host), that is, a route to a single host. But then you say that the route is actually for a /16 network (netmask 255.255.0.0). Which is it?

HarryBoy 05-20-2012 12:54 PM

Thanks for your reply, I'new to routes etc.

What I'm trying to do is to create a c++ cgi that, when called, will add routes and remove them from my route table.

So, in this case, is there any example route that I can add to my route table above just for test purposes (So I can add and delete it)

Thanks

Ser Olmy 05-20-2012 01:29 PM

Quote:

Originally Posted by HarryBoy (Post 4683284)
So, in this case, is there any example route that I can add to my route table above just for test purposes (So I can add and delete it)

Sure:
Code:

route add -host 192.168.255.254 gw 10.51.56.253
The above will add a route to the IP address 192.168.255.254 via 10.51.56.253. Using -host is the same as specifying a /32 netmask. The same could be accomplished with route add -net 192.168.255.254 netmask 255.255.255.255 gw 10.51.56.253.

The first IP address can be any non-local address, and it's probably best to test with an IP address you know you know won't need to contact. The second address has to be local, but it doesn't necessarily have to be assigned to anything.


All times are GMT -5. The time now is 06:03 AM.