← 返回命令列表

Linux command

ip-rule 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Example

ip rule

Add

sudo ip rule add from all lookup [100]

Example

sudo ip rule add from [192.168.1.0/24]

Example

sudo ip rule add to [10.0.0.0/8]

Delete

sudo ip rule delete from [192.168.1.0/24]

Flush

sudo ip rule flush

Save

ip rule save > [path/to/rules.dat]

Restore

sudo ip rule restore < [path/to/rules.dat]

说明

ip rule manages the routing policy database (RPDB), which controls how routing table lookups are performed. Rules define selectors (conditions) and actions (which table to consult) enabling policy-based routing. Multiple routing tables can exist, each with different routes. Rules determine which table is consulted based on source address, destination, interface, firewall mark, and other criteria. This enables complex routing scenarios like multi-homing.

参数

add _selector_ _action_
Add a new rule
delete _selector_
Remove a rule
flush
Delete all rules
save
Output rules to stdout (for backup)
restore
Restore rules from stdin
from _PREFIX_
Match source address
to _PREFIX_
Match destination address
lookup _TABLE_
Route table to use (number or name)
priority _NUM_
Rule priority (lower = higher priority)

FAQ

What is the ip-rule command used for?

ip rule manages the routing policy database (RPDB), which controls how routing table lookups are performed. Rules define selectors (conditions) and actions (which table to consult) enabling policy-based routing. Multiple routing tables can exist, each with different routes. Rules determine which table is consulted based on source address, destination, interface, firewall mark, and other criteria. This enables complex routing scenarios like multi-homing.

How do I run a basic ip-rule example?

Run `ip rule` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does add _selector_ _action_ do in ip-rule?

Add a new rule