无聊且忙碌的的daily Curd。 作为一个linux网络小白,遇到一个linux网络环境问题,索性强行抽空记录一下。
背景
查看环境路由表的时候,会看到一些如下的字段proto kernel scope link src
# ip r
default via 15.231.43.1 dev eth0 onlink
10.173.121.0/24 dev eth1.200 proto kernel scope link src 10.173.121.10
15.231.43.0/25 dev eth0 proto kernel scope link src 15.231.43.51
172.16.0.0/16 dev eth1.100 proto kernel scope link src 172.16.0.1
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
scope 和 protocl
一直不了解这个的含义,查询如下
scope
类型 指的是路由前缀覆盖的目标地址范围。 scope link
表示在设备的网段内允许通过该路由进行通信。 通过其他往网段的话的话,应该使用路由。
scope
type is the scope of the destinations covered by the route prefix.scope link
means that within the network segment of the device communication is allowed through this link. Towards other network segments routing should be used.
protocol
类型 是该路由的路由协议标识符。proto kernel
的意思是: 在自动配置过程中由内核安装的路由。
protocol
type is the routing protocol identifier of this route.proto kernel
means: The route was installed by the kernel during autoconfiguration.
这里可以明白scope
和 protocol
应该是是需要分开理解的。 一个代表路由范围,另一个代表路由标识符
翻译自networking - route table explanation - Ask Ubuntu
scope
scope表示作用于,通常由ip的使用程序确定。
scope还有其他值可以设定吗?
当然是有的。查看 ip 命令的帮助
ip route add help
Usage: ip route { list | flush } SELECTOR
...
ip route { add | del | change | append | replace } ROUTE
...
SCOPE := [ host | link | global | NUMBER ]
...
以下引用自Christian Benvenuti, O'Reilly的《Understanding Linux network internals》
"The scope of a route in Linux is an indicator of the distance to the destination network. The scope of an IP address is an indicator of how far from the local host the address is known, which, to some extent also tells you how far the owner of that address is from the local host (...).
“在Linux中,路由的范围是到目标网络距离的指示器。IP地址的范围是一个指示器,指示该地址距离已知的本地主机有多远,这在某种程度上也告诉您该地址的所有者距离本地主机有多远
Host: An address has a host scope when it is used only to communicate within the host itself. Outside the host this address is not known and can not be used. An Example is the loopback address, 127.0.0.1
host :当地址仅用于在主机本身内部通信时,它具有主机作用域。在主机外部,这个地址是未知的,不能使用。例如,loopback地址为127.0.0.1
Link: An address has a link scope when it is meaningful and can be used only within a LAN. An example is a subnet's broadcast address.
link: 当一个地址有意义且只能在局域网内使用时,该地址就有链接作用域。例如子网的广播地址。
Global: An address has global scope when it can be used anywhere. This is the default scope for most addresses. (...)"
Global: 当地址可以在任何地方使用时,它具有全局作用域。这是大多数地址的默认作用域
The main reason to use scopes seems to be that a host with multiple interfaces and addresses has to decide when to use which address. For communication with itself a loopback address (scope host) can be used. With communication elswhere, a different address has to be selected.
使用作用域的主要原因似乎是,具有多个接口和地址的主机必须决定何时使用哪个地址。为了与自身通信,可以使用环回地址(作用域主机)。如果在其他地方通信,则必须选择不同的地址。
protocol
protocol的可选项及含义如下
protocol RTPROTO
the routing protocol identifier of this route.
RTPROTO may be a number or a string from the
file /etc/iproute2/rt_protos. If the routing
protocol ID is not given, ip assumes protocol
boot (i.e. it assumes the route was added by
someone who doesn't understand what they are doing).
Several protocol values have a fixed interpretation.
Namely:
redirect - the route was installed due to an ICMP redirect.
kernel - the route was installed by the kernel during
autoconfiguration.
boot - the route was installed during the bootup sequence.
If a routing daemon starts, it will purge all of them.
static - the route was installed by the administrator to
override dynamic routing. Routing daemon will
respect them and, probably, even advertise them
to its peers.
ra - the route was installed by Router Discovery protocol.
The rest of the values are not reserved and the administrator is free
to assign (or not to assign) protocol tags.
参考
networking - route table explanation - Ask Ubuntu
linux - What is the interface scope (global vs. link) used for? - Unix & Linux Stack Exchange
linux - ip address scope parameter - Server Fault
What does "proto kernel" means in Unix Routing Table? - Stack Overflow