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 and eth0:0, but as I want all my traffic except the 192.168.0.0/16 to be marked as coming from my 178.xxx.xxx.xxx address, I added a routing rule. Maybe having eth0 with the 192.168.1.101 ip and then the 178.xxx.xxx.xxx ip on eth0: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!