ip route add - RTNETLINK 回答:文件存在

ip route add - RTNETLINK 回答:文件存在

在Linux机器上有2个接口:

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 位于不同的网络上,所以我想设置一条新路由,因此

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)

任何想法?

答案1

它运行正常,我不明白为什么它不适用于 /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

答案2

/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

相关内容