策略路由 policy routing rt_tables

参考链接: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/configuring-policy-based-routing-to-define-alternative-routes_configuring-and-managing-networking
其他资源: ip-rule , ip-route man手册页.

Linux-2.x 版本可以将路由打包到多个路由表中, 这些路由表由1到2^32-1范围的数字或者文件 /etc/iproute2/rt_tables 中的名称标识. 默认情况下, 所有正常路由都插入到 main(ID 254)路由表, 并且内核在计算路由时仅使用此表. 0, 253, 254, 255 保留内置使用.

相比main表, 一个更重要的表是local表(ID 255), 包含local和广播地址的路由, 此表由内核维护, 管理员不需要修改.

一些命令

# 展示此路由表的内容
ip route show table [TABLEID]

# 给此路由表添加路由项
ip route add ... table [TABLEID]

# 
ip rule add from xxx table [TABLEID]s