Linux policy routing

The implementation of Linux policy routing requires multiple routing tables and a routing policy database (RPDB). You can list the policies in RPDB by typing:

The "ip rule show" command is used to display the routing policy and policy routing rules on the Linux system. In Linux systems, a routing policy is a way of defining routing behavior that selects a specific routing table based on source address, destination address, or other criteria. Policy routing rules allow you to use different routing policies according to different network traffic types or needs, so as to achieve more flexible routing management.

Specifically, the "ip rule show" command will list all policy routing rules defined in the current system, and display information such as the priority, matching conditions, and ACTIONS list of each rule. For example:

0:      from all lookup local 
32765:  from 192.168.1.0/24 lookup custom
32766:  from all lookup main 
32767:  from all lookup default 

This example lists four policy routing rules. The first rule (with a priority of 0) means to look up the local routing table; the second rule (with a priority of 32765) means to use the route named "custom" for packets whose source address is in the 192.168.1.0/24 network segment table for routing; the third rule (priority 32766) means to use the system default main routing table; the fourth rule (priority 32767) means to search the default routing table.

By using the "ip rule add" command, you can add new policy routing rules to the system for greater control over the routing of network traffic.

chunk@chunk-ThinkPad-X1-Carbon-5th  /tmp/ai  ip rule show
0:	from all lookup local
32766:	from all lookup main
32767:	from all lookup default
 chunk@chunk-ThinkPad-X1-Carbon-5th  /tmp/ai  ip route list table local
local 10.200.0.1 dev docker0 proto kernel scope host src 10.200.0.1 
broadcast 10.200.255.255 dev docker0 proto kernel scope link src 10.200.0.1 linkdown 
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1 
local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1 
broadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1 
local 172.22.0.1 dev br-e475e85b2ff7 proto kernel scope host src 172.22.0.1 
broadcast 172.22.255.255 dev br-e475e85b2ff7 proto kernel scope link src 172.22.0.1 
local 192.168.10.11 dev wlp4s0 proto kernel scope host src 192.168.10.11 
broadcast 192.168.10.255 dev wlp4s0 proto kernel scope link src 192.168.10.11 
local 192.168.122.1 dev virbr0 proto kernel scope host src 192.168.122.1 
broadcast 192.168.122.255 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown 
local 192.168.250.1 dev anbox0 proto kernel scope host src 192.168.250.1 
broadcast 192.168.250.255 dev anbox0 proto kernel scope link src 192.168.250.1 linkdown 
 chunk@chunk-ThinkPad-X1-Carbon-5th  /tmp/ai  ip route list table main
default via 192.168.10.254 dev wlp4s0 proto dhcp metric 600 
10.200.0.0/16 dev docker0 proto kernel scope link src 10.200.0.1 linkdown 
169.254.0.0/16 dev virbr0 scope link metric 1000 linkdown 
172.22.0.0/16 dev br-e475e85b2ff7 proto kernel scope link src 172.22.0.1 
192.168.10.0/24 dev wlp4s0 proto kernel scope link src 192.168.10.11 metric 600 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown 
192.168.250.0/24 dev anbox0 proto kernel scope link src 192.168.250.1 linkdown 
 chunk@chunk-ThinkPad-X1-Carbon-5th  /tmp/ai  ip route list table default
Error: ipv4: FIB table does not exist.
Dump terminated
 ✘ chunk@chunk-ThinkPad-X1-Carbon-5th  /tmp/ai  ip route list table default
Error: ipv4: FIB table does not exist.
Dump terminated

Reference:
Policy Routing

Guess you like

Origin blog.csdn.net/u010674101/article/details/131381670