Ip route add – RTNETLINK answers: File exists

iprouting

On the Linux box there are 2 interfaces:

Bond0: inet addr:170.242.57.113  Bcast:170.242.57.255  Mask:255.255.255.0
Eth4    : inet addr:172.21.136.124  Bcast:172.21.137.255  Mask:255.255.254.0

Because eth4 is on a different network, I want to setup a new route, therefore

used route-eth4
ADDRESS0=172.21.136.0
NETMASK0=255.255.254.0
GATEWAY0=172.21.137.251

But this failled, looked into ifup and worked out that /etc/sysconfig/network-scripts/ifup-routes was the script setting up the routing, issuing the following command

ip route  add 172.21.136.0/23 via 172.21.137.251 dev eth4
RTNETLINK answers: File exists

Looks like the route can’t be added for /23

But works if I do it with 2 /24

ip route  add 172.21.136.0/24 via 172.21.137.251 dev eth4
ip route  add 172.21.137.0/24 via 172.21.137.251 dev eth4
netstat –nr

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irttIface
172.21.137.0    172.21.137.251  255.255.255.0   UG        0 0          0 eth4
172.21.136.0    172.21.137.251  255.255.255.0   UG        0 0          0 eth4
170.242.57.0    0.0.0.0         255.255.255.0   U         0 0          0 bond0
172.21.136.0    0.0.0.0         255.255.254.0   U         0 0          0 eth4
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth4
0.0.0.0         170.242.57.251  0.0.0.0         UG        0 0          0 bond0

It works fine and I don’t understand why it’s not working for the /23

Address:   172.21.136.124        10101100.00010101.1000100 0.01111100
Netmask:   255.255.254.0 = 23    11111111.11111111.1111111 0.00000000
Wildcard:  0.0.1.255             00000000.00000000.0000000 1.11111111
=>
Network:   172.21.136.0/23       10101100.00010101.1000100 0.00000000 (Class B)
Broadcast: 172.21.137.255        10101100.00010101.1000100 1.11111111
HostMin:   172.21.136.1          10101100.00010101.1000100 0.00000001
HostMax:   172.21.137.254        10101100.00010101.1000100 1.11111110
Hosts/Net: 510                   (Private Internet)

Any idea?

Best Answer

It works fine and I don’t understand why it’s not working for the /23

Because it's already there - this is what RTNETLINK answers: File exists is telling you.

your netstat -rt output contains this route:

172.21.136.0    0.0.0.0         255.255.254.0   U         0 0          0 eth4

which is conflicting with ip route add 172.21.136.0/23 via 172.21.137.251 dev eth4.