Linux kernel の routing table のID番号について
Linux kernel は複数のルーティングテーブルを保持することができ、それらは内部的にID(整数)で区別される。
# デフォルトのルーティングテーブルを表示 root@sv01:/home/ubuntu# ip route list default via 172.18.0.1 dev eno1 proto dhcp src 172.18.0.94 metric 100 172.18.0.0/24 dev eno1 proto kernel scope link src 172.18.0.94 metric 100 172.18.0.1 dev eno1 proto dhcp scope link src 172.18.0.94 metric 100 # ID 100 のルーティングテーブルを表示 root@sv01:/home/ubuntu# ip route list table 100 10.121.0.0/24 proto bird metric 32 nexthop via inet6 fe80::1 dev enp23s0f0 weight 1 nexthop via inet6 fe80::2 dev enp23s0f1 weight 1 10.121.0.64/26 proto bird metric 32 nexthop via inet6 fe80::1 dev enp23s0f0 weight 1 nexthop via inet6 fe80::2 dev enp23s0f1 weight 1
では、 ip route
コマンドで「特にIDを指定しない場合に操作対象になるルーティングテーブル」のIDは一体何番なのだろうか?
答えは ip route
のmanpageに書いてある:
Route tables: Linux-2.x can pack routes into several routing tables identified by a number in the range from 1 to 2^32-1 or by name from the file /etc/iproute2/rt_tables By default all normal routes are inserted into the main table (ID 254) and the kernel only uses this table when calculating routes. Values (0, 253, 254, and 255) are reserved for built-in use.
Actually, one other table always exists, which is invisible but even more important. It is the local table (ID 255). This table consists of routes for local and broadcast addresses. The kernel maintains this table automatically and the administrator usually need not modify it or even look at it.
上記のとおり、特にIDを指定しない場合に操作対象になるルーティングテーブル (main) は ID 254
で区別される。
root@sv01:/home/ubuntu# ip route list table 254 default via 172.18.0.1 dev eno1 proto dhcp src 172.18.0.94 metric 100 172.18.0.0/24 dev eno1 proto kernel scope link src 172.18.0.94 metric 100 172.18.0.1 dev eno1 proto dhcp scope link src 172.18.0.94 metric 100
その他の予約済みのIDも紹介していこう。 ID 255
には local経路 (ルータで言うところのDirect経路)がインストールされる。
root@sv01:/home/ubuntu# ip route list table 255 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 local 172.18.0.94 dev eno1 proto kernel scope host src 172.18.0.94 broadcast 172.18.0.255 dev eno1 proto kernel scope link src 172.18.0.94
ID 0
には、IPv4/v6/Multicast経路など問わず全テーブルの経路が存在するらしい。
root@sv01:/home/ubuntu# ip route list table 0 10.121.0.0/24 proto bird metric 32 nexthop via inet6 fe80::1 dev enp23s0f0 weight 1 nexthop via inet6 fe80::2 dev enp23s0f1 weight 1 10.121.0.64/26 proto bird metric 32 nexthop via inet6 fe80::1 dev enp23s0f0 weight 1 nexthop via inet6 fe80::2 dev enp23s0f1 weight 1 default via 172.18.0.1 dev eno1 proto dhcp src 172.18.0.94 metric 100 172.18.0.0/24 dev eno1 proto kernel scope link src 172.18.0.94 metric 100 172.18.0.1 dev eno1 proto dhcp scope link src 172.18.0.94 metric 100 local 127.0.0.0/8 dev lo table local proto kernel scope host src 127.0.0.1 local 127.0.0.1 dev lo table local proto kernel scope host src 127.0.0.1 broadcast 127.255.255.255 dev lo table local proto kernel scope link src 127.0.0.1 local 172.18.0.94 dev eno1 table local proto kernel scope host src 172.18.0.94 broadcast 172.18.0.255 dev eno1 table local proto kernel scope link src 172.18.0.94 ::1 dev lo proto kernel metric 256 pref medium fe80::/64 dev eno1 proto kernel metric 256 pref medium fe80::/64 dev enp23s0f0 proto kernel metric 256 pref medium fe80::/64 dev enp23s0f1 proto kernel metric 256 pref medium local ::1 dev lo table local proto kernel metric 0 pref medium local fe80::42a6:b7ff:fea7:f0 dev enp23s0f0 table local proto kernel metric 0 pref medium local fe80::42a6:b7ff:fea7:f1 dev enp23s0f1 table local proto kernel metric 0 pref medium local fe80::4e52:62ff:fe52:94e0 dev eno1 table local proto kernel metric 0 pref medium multicast ff00::/8 dev eno1 table local proto kernel metric 256 pref medium multicast ff00::/8 dev enp23s0f0 table local proto kernel metric 256 pref medium multicast ff00::/8 dev enp23s0f1 table local proto kernel metric 256 pref medium
私の環境では、 ID 253
(default) にはテーブルが定義されていなかった。このテーブルの実態はよく分からない。
root@sv01:/home/ubuntu# ip route list table 253 Error: ipv4: FIB table does not exist. Dump terminated
なお、 /etc/iproute2/rt_tables
にこれらのテーブル名が保存されている。 ip route
コマンドはこちらの名前でもテーブルを指定できる。
root@sv01:/home/ubuntu# cat /etc/iproute2/rt_tables # # reserved values # 255 local 254 main 253 default 0 unspec # # local # #1 inr.ruhep root@sv01:/home/ubuntu# ip route list table local 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 local 172.18.0.94 dev eno1 proto kernel scope host src 172.18.0.94 broadcast 172.18.0.255 dev eno1 proto kernel scope link src 172.18.0.94