7

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!

4 Answers4

2

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.

1

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.

Andrew
  • 8,002
  • 3
  • 36
  • 44
0

As others have stated your IP on eth0:1 of 192.168.1.101/16 will mean that you already have a static route for that subnet. It looks like you need to add a gateway for that interface pointing to 192.168.255.254.

HostBits
  • 11,796
  • 1
  • 25
  • 39
0

I know it's a bit late, but I'd also like to clarify what is "route" made for. You said :

I want all my traffic except the 192.168.0.0/16 to be marked as coming from my 178.xxx.xxx.xxx address

route command allows you to determine a route based on a destination, not on a source. You need to configure your services to use an IP according to the gateway you want to be used. As Mathias Weidner said, you do not need a gateway since you are directly connected (same subnet = no routing)