List-all-ip-route-tables列出所有路由表

来自三线的随记

技巧-- list all ip route tables in linux kernel

Related knowledge points

可以在 /etc/iproute2/rt_tables 文件定义路由表(ip routing table)id以及它的别名

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.


Command to list all ip route tables in linux kernel

ip route show table all
ip route show table all | grep "table" | sed 's/.*\(table.*\)/\1/g' | awk '{print $2}' | sort | uniq
ip route show table all | grep -Po 'table \K[^\s]+' | sort -u