# ip route get 1.2.3.4 anycast 1.2.3.4 dev eth0 src 5.6.7.8
问题是如何知道地址是一个任播? (这显然是真的)。
更新:
作为选播路线呈现:
root@hv2 ~ # ip route get 1.2.3.4 anycast 1.2.3.4 dev eth0 src 5.6.7.8 cache
但在列表中不可见:
root@hv2 ~ # ip route list|grep 1.2.3.4|wc -l 0
但可以将其删除,而不是恢复正常(不再有任何选anycast
):
root@hv2 ~ # ip route del anycast 1.2.3.4 dev eth0 root@hv2 ~ # ip route get 1.2.3.4 1.2.3.4 via 5.6.7.8 dev eth0 src 9.10.11.12 cache
如果你看看iproute2的gitweb ,你会发现它显示了在内核路由结构上设置的RTN_ANYCAST
位的状态。 如果与内核源代码(rtnetlink.h)交叉引用,则会看到以下注释:
RTN_ANYCAST, /* Accept locally as broadcast, but send as unicast */
如果您查看手册页,则会看到地址的任播状态由configuration决定(特别是在指定要添加的地址时添加anycast
关键字)。 据man 8 ip
:
IFADDR := PREFIX | ADDR peer PREFIX [ broadcast ADDR ] [ anycast ADDR ] [ label STRING ] [ scope SCOPE-ID ] ... anycast - _not implemented_ the destinations are anycast addresses assigned to this host. They are mainly equivalent to local with one difference: such addresses are invalid when used as the source address of any packet.
从手册的第一部分,它指出,当你指定地址时,你可以指示栈是一个任播地址。 在不检查内核源代码的情况下,我想象当添加一个任播地址时,任播位会被传播到一个相应的路由表项中,这个路由表项将在添加地址时创build。
我不确定“未执行”部分是否完全正确,因为它看起来像iproute2确实将anycast标志传递给系统调用。 所以看起来如果anycast被内核支持,它应该可以工作。 但是我没有testing过,所以我不知道。
在ip-route
的手册页中,在“ip route get”部分下:
请注意,此操作不等同于ip route show。 显示现有路线。 得到解决他们,并在必要时创build新的克隆。 基本上,get就相当于沿着这条path发送一个数据包
您可以使用命令ip route show type anycast
显示任意路由。