![更改主表的默认 ip 规则优先级](https://linux22.com/image/127778/%E6%9B%B4%E6%94%B9%E4%B8%BB%E8%A1%A8%E7%9A%84%E9%BB%98%E8%AE%A4%20ip%20%E8%A7%84%E5%88%99%E4%BC%98%E5%85%88%E7%BA%A7.png)
请建议如何在主规则之后添加 ip 规则。
我有以下配置,需要在启动时恢复。
32766: from all lookup main
32766: from all lookup upstream01
32766: from all lookup upstream02
32767: from all lookup default
挑战是在 main 之后以正确的顺序为上游表 01 和 02 添加规则。 main 和 default 的优先级在它们之间注入规则没有任何间隙。我只能使用与主表相同的规则优先级来添加它,如上面所示。
所以,我看到了多种选择:
A。更改主表的默认优先级规则,以在规则之间留出间隙,以便能够按所需顺序定义优先级。但我不知道该怎么做。
b.找到了一种在“main”和“upstream01”之间注入规则的方法。
答案1
关键字pref
允许覆盖优先级。
ip rule add pref 32000 from all lookup main
ip rule del pref 32766 from all lookup main
ip rule add pref 32010 from all lookup upstream01
ip rule add pref 32020 from all lookup upstream02
答案2
您可以删除现有的“默认”规则并将其替换为适合您情况的规则:
# delete the existing default rule
ip rule del from all lookup default priority 32767
# add your custom rules
ip rule add from all lookup upstream01 priority 32767
ip rule add from all lookup upstream02 priority 32768
# replace the "default" rule
ip rule add from all lookup default priority 32769
结果应该是这样的:
0: from all lookup local
32766: from all lookup main
32767: from all lookup upstream01
32768: from all lookup upstream02
32769: from all lookup default