Significance of priority in "ip rule" command

2

What is the significance of the prio option in ip rule add/del command? Does a higher priority for a rule give it preference over other rules in the table?

I saw this piece of code online, without any comments to it. I'm curious to know what it does:

ip rule del prio 32766 from "" dev "" fwmark 0 table main

ip rule del prio 32767 from "" dev "" fwmark 0 table default

ip rule add prio 4294967293UL from "" dev "" fwmark 0 table 1

ip rule add prio 4294967294UL from "" dev "" fwmark 0 table main

ip rule add prio 4294967295UL from "" dev "" fwmark 0 table default

user983356

Posted 2011-11-21T14:01:49.117

Reputation:

Answers

1

The priority determines the order in which the rules are checked (from lowest number to highest). The first rule which matches the packet is used.

The maximum priority is 32767 though, so those big priority numbers don't make sense.

mgorven

Posted 2011-11-21T14:01:49.117

Reputation: 2 539

5"The first rule which matches the packet is used." this is not completely correct. The rules are in fact checked in the order specified by priority, but a rule which has its conditions satisfied may in fact not provide a result, and more rules are checked. The prime example of this is when a rule specifies a "lookup" (or "table"), but there is no route in that routing table matching the destination. – Ambroz Bizjak – 2012-04-27T21:05:53.807