IP路由添加 – RTNETLINK答案:文件存在

在Linux上有两个接口:

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 

因为eth4在不同的networking上,所以我想设置一个新的路由

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

但是,这失败了,看着ifup,并解决/ etc / sysconfig / network-scripts / ifup-routes是设置路由的脚本,发出以下命令

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

看起来像路线不能被添加为/ 23

但是,如果我用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 

它工作正常,我不明白为什么它不工作的/ 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) 

任何想法?

它工作正常,我不明白为什么它不工作的/ 23

因为它已经在那里 – 这就是RTNETLINK answers: File exists告诉你。

你的netstat -rt输出包含这个路由:

 172.21.136.0 0.0.0.0 255.255.254.0 U 0 0 0 eth4 

这与ip route add 172.21.136.0/23 via 172.21.137.251 dev eth4相冲突。

/ 23已经在你的桌子上了…

 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 

另外请记住, ip route add 172.21.136.0/23 via 172.21.137.251 dev eth4有点不合理,因为172.21.137.251 172.21.136.0/23