Why ip route add doesn't work, but ip route add with less details and then change works?
Solution 1
According to your interfaces file you are already in the network 192.168.0.0/16, so you should not need a gateway to this network.
Solution 2
If I adjust my results for your IP setup (I'm on a 192.168.x.0/24):
$ sudo ip route add 192.168.0.0/16 via 192.168.255.254 src 192.168.1.101
I get
RTNETLINK answers: No such process
But
$ sudo ip route add 192.168.0.0/16 via 192.168.1.254 src 192.168.1.101
works. I suspect it's because 192.168.255.254 is not on your local subnet or a known route, so you need a route to it first.
Related videos on Youtube
Loïc d'Anterroches
Updated on September 18, 2022Comments
-
Loïc d'Anterroches almost 2 years
I have a problem with ip route add. Surprisingly, I can add the route then change it, but I cannot directly add it:
# ip route add 192.168.0.0/16 via 192.168.255.254 src 192.168.1.101 RTNETLINK answers: No such process
but:
# ip route add 192.168.0.0/16 dev eth0 # ip route change 192.168.0.0/16 via 192.168.255.254 src 192.168.1.101
My interfaces file is:
iface lo inet loopback auto eth0 iface eth0 inet static address 178.xxx.xxx.xxx netmask 255.255.255.192 network 178.xxx.xxx.xxx broadcast 178.xxx.xxx.xxx gateway 178.xxx.xxx.xxx auto eth0:1 iface eth0:1 inet static address 192.168.1.101 netmask 255.255.0.0
I am a bit lost I must say. I am fine with adding then changing but it is not satisfying to not understand why it works in two steps and not directly. I have been reading man pages after man pages without understanding.
Updated with the help of the answers:
I have now a gateway on
eth0
andeth0:0
, but as I want all my traffic except the192.168.0.0/16
to be marked as coming from my178.xxx.xxx.xxx
address, I added a routing rule. Maybe havingeth0
with the192.168.1.101
ip and then the178.xxx.xxx.xxx
ip oneth0:0
would work without routing rule, but here it goes:auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 178.xxx.xxx.131 netmask 255.255.255.192 network 178.xxx.xxx.128 broadcast 178.xxx.xxx.191 gateway 178.xxx.xxx.190 up /sbin/ip route add default via 178.xxx.xxx.190 dev eth0 table 125 up /sbin/ip rule add from 178.xxx.xxx.128/26 table 125 post-down /sbin/ip route del default via 178.xxx.xxx.190 dev eth0 table 125 post-down /sbin/ip rule del from 178.xxx.xxx.128/26 table 125 auto eth0:0 iface eth0:0 inet static address 192.168.1.101 netmask 255.255.0.0 gateway 192.168.255.254
I have also disabled
rp_filter
:echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter
Thanks for your help!
-
HostBits over 13 years192.168.255.254 is on the 192.168.0.0/16 local subnet.
-
Loïc d'Anterroches over 13 yearsYes, so, it looks like I had to put the gateway and add some routing stuff to get my source ip right.
-
rjt almost 12 yearsip route add 192.168.0.0/16 dev eth0:0 via 192.168.1.254 src 192.168.1.101