在 IPv4 与 IPv6 情况下从本地主机地址路由数据包时的行为有所不同

在 IPv4 与 IPv6 情况下从本地主机地址路由数据包时的行为有所不同

为什么本地地址的 IPv4 路由与 IPv6 不同?

下面是一个ip route演示它的例子:

# IPv4 case
$ ip route get 1.2.3.4 from 127.0.0.1
RTNETLINK answers: Invalid argument

# For comparison, IPv4 when source addr is not specified
$ ip route get 1.2.3.4
1.2.3.4 via 192.168.178.1 dev wlp3s0 src 192.168.178.20 uid 1000 
    cache 

# IPv6 case
$ ip route get 1:2:3:4::5 from ::1
1:2:3:4::5 from ::1 via fe80::9a9b:cbff:fe5c:818f dev wlp3s0 proto ra src 2a01:c23:604d:ef00:5e85:b4f4:da92:59f2 metric 20600 pref medium

在这两种情况下,我们都尝试将数据包从环回 IP 地址 ( 127.0.0.1/ ::1) 路由到公共目的地(未绑定到任何本地接口)。IPv4 理所当然地立即拒绝了该路由。IPv6 决定通过默认网关将其路由出去(在测试中,通过网络接口发送一个数据包,源地址::1

检查 IPv4local路由表未显示任何黑洞路由:

$ ip route show table local
broadcast 127.0.0.0 dev lo proto kernel scope link src 127.0.0.1 
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1 
local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1 
broadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1 
broadcast 172.17.0.0 dev docker0 proto kernel scope link src 172.17.0.1 linkdown 
local 172.17.0.1 dev docker0 proto kernel scope host src 172.17.0.1 
broadcast 172.17.255.255 dev docker0 proto kernel scope link src 172.17.0.1 linkdown 
broadcast 172.18.0.0 dev br-6141a041d1de proto kernel scope link src 172.18.0.1 
local 172.18.0.1 dev br-6141a041d1de proto kernel scope host src 172.18.0.1 
broadcast 172.18.255.255 dev br-6141a041d1de proto kernel scope link src 172.18.0.1 
broadcast 192.168.178.0 dev wlp3s0 proto kernel scope link src 192.168.178.20 
local 192.168.178.20 dev wlp3s0 proto kernel scope host src 192.168.178.20 
broadcast 192.168.178.255 dev wlp3s0 proto kernel scope link src 192.168.178.20 

那么,当 src 是本地主机地址时,IPv4 堆栈的哪部分会抛出快速失败?

相关内容