linux策略路由的添加

添加记录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
stack@pdf-compute:~$ ip rule show
0: from all lookup local
32765: from 169.254.169.254 lookup 2
32766: from all lookup main
32767: from all lookup default
stack@pdf-compute:~$
stack@pdf-compute:~$ sudo ip rule add from 192.168.56.0/24 table 10
stack@pdf-compute:~$ sudo ip route add default via 192.168.56.10 table 10
RTNETLINK answers: File exists
stack@pdf-compute:~$ ip route show table 10
default via 192.168.56.10 dev br-ex
stack@pdf-compute:~$
stack@pdf-compute:~$ sudo ip route delete default via 192.168.56.10 table 10
stack@pdf-compute:~$ ip route show table 10
stack@pdf-compute:~$
stack@pdf-compute:~$ sudo ip route add default via 192.168.56.10 table 10
stack@pdf-compute:~$
stack@pdf-compute:~$ ip route show table 10
default via 192.168.56.10 dev br-ex
stack@pdf-compute:~$ sudo ip route add 114.114.114.114 via 192.168.56.10 table 10
stack@pdf-compute:~$ ip route show table 10
default via 192.168.56.10 dev br-ex
114.114.114.114 via 192.168.56.10 dev br-ex

步骤总结

添加

  • ip rule add from 192.168.56.0/24 table 10
  • ip route add default via 192.168.56.10 table 10
  • ip route add 114.114.114.114 via 192.168.56.10 table 10

删除

  • ip route delete 114.114.114.114 via 192.168.56.10 table 10
  • sudo ip route delete default via 192.168.56.10 table 10
  • sudo ip rule delete from 192.168.56.0/24