9

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?

pevik
  • 286
  • 1
  • 12
rnoooo
  • 121
  • 1
  • 1
  • 2
  • 5
    Stop. Please go read [How does Subnetting Work](http://serverfault.com/questions/49765/how-does-subnetting-work). Keep reading until you understand why you got the "File Exists" error. I'm not trying to be mean, but you're apparently lacking a bit in understanding IP Subnets. – Chris S Oct 21 '11 at 15:47

2 Answers2

8

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.

the-wabbit
  • 40,319
  • 13
  • 105
  • 169
  • But how does it know to route to the gateway 172.21.137.251, not sure to understand the meaning of 0.0.0.0 – rnoooo Oct 21 '11 at 14:30
  • 4
    0.0.0.0 is used for a gatway when the network is local. You don't need a gateway for that network you are connected to it. – Zoredache Oct 21 '11 at 15:42
  • 3
    Fwiw I don't think `File exists` is an acceptable error message. If it is a route that already exists, why not use `Route exists` as an error message? If not, which file is it that already exists? – moritz Jul 07 '12 at 17:37
3

The /23 is already in your table...

netstat -nr

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
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

Also keep in mind that ip route add 172.21.136.0/23 via 172.21.137.251 dev eth4 is a bit non-sensical since 172.21.137.251 is in 172.21.136.0/23

Mike Pennington
  • 8,266
  • 9
  • 41
  • 86