Linux – Adding a route via a different subnet on linux

linuxrouting

Here's my configuration :

IP adress : 192.168.1.4 Netmask : 255.255.255.0 Default gw :
192.168.1.200

Routing table :

    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.1     192.168.1.254   255.255.255.255 UGH   0      0        0 venet0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 venet0
0.0.0.0         192.168.1.200   0.0.0.0         UG    0      0        0 venet0

When I try to add a route via the subnet 192.168.2.0, I get the following RTNETLINK answers: No such process
Example :

#ip route add 8.8.8.8/32 via 192.168.2.1 dev venet0:0
#RTNETLINK answers: No such process

Is there a way to accomplish this kind of thing ?

And one more question : I'd like to be able to forward all my incoming trafic to the gateway at 192.168.2.1 … How Can I do this ? This doesn't work of course :

#ip route add default via 192.168.2.1
#RTNETLINK answers: No such process

Best Answer

No. Source-based routing has been deprecated manymany years ago.

Some routers accept such a statement (called indirect next-hop), but locally (at your 192.168.1.4) it would result in this - and that's all you can do:

#ip route add 8.8.8.8/32 via 192.168.1.254 dev venet0:0

Anything behind 192.168.1.254 lies only in the responsibility of 192.168.1.254. Do you have access to this device?

To the second question - I do not understand, what you want to do...