o que significam os números no comando ip rule show

4

Se eu digitar o comando ip rule show em minha máquina, obtenho a saída como

0:  from all lookup local 
32766:  from all lookup main 
32767:  from all lookup default

O que significam os números 0 , 32766 e 32767 ?

Eu entendo que estas são algumas prioridades e 0 é uma prioridade especial e não pode ser excluída.

Além disso, se eu adicionar uma nova política, ela será criada com uma prioridade como 32765 . Meu entendimento está correto?

Além disso, vejo algumas informações sobre a prioridade de ip rule add de aqui .

Really, for historical reasons ip rule add does not require a priority value and allows them to be non-unique. If the user does not supplied a priority, it is selected by the kernel. If the user creates a rule with a priority value that already exists, the kernel does not reject the request. It adds the new rule before all old rules of the same priority. It is mistake in design, nomore. And it will be fixed one day, so do not rely on this feature. Use explicit priorities.

    
por Ramesh 08.10.2014 / 22:29

1 resposta

5

A partir da página man ip-rule :

At startup time the kernel configures the default RPDB consisting of three rules:

   1.  Priority: 0, Selector: match anything, Action: lookup routing 
       table local (ID 255).  The local table is a special routing table 
       containing high priority control routes for local and broadcast 
       addresses.

       Rule 0 is special. It cannot be deleted or overridden.

   2.  Priority: 32766, Selector: match anything, Action: lookup routing 
       table main (ID 254).  The main table is the normal routing table 
       containing all non-policy routes. This rule may be deleted and/or 
       overridden with other ones by the administrator.

   3.  Priority: 32767, Selector: match anything, Action: lookup routing 
       table default (ID 253).  The default table is empty.  It is 
       reserved for some post-processing if no previous default rules 
       selected the packet.  This rule may also be deleted.

  Each RPDB entry has additional attributes.  F.e. each rule has a pointer 
  to some routing table.  NAT and masquerading rules have an attribute to 
  select new IP address to translate/masquerade.  Besides that, rules have 
  some optional attributes, which routes have, namely realms.  These 
  values do not override those contained in the routing tables.  They are 
  only used if the route did not select any attributes.

Portanto, esses números, 0, 32766 e 32767 são a prioridade que as regras receberão.

OBSERVAÇÃO: Os outros números mencionados acima: 255, 254 e 253 correspondem às tabelas de roteamento, conforme descrito neste arquivo:

$ more /etc/iproute2/rt_tables 
#
# reserved values
#
255 local
254 main
253 default
0   unspec
#
# local
#
#1  inr.ruhep

Os nomes acima podem ser usados ao consultar as tabelas de roteamento da seguinte forma:

$ ip route show table local
broadcast 127.0.0.0 dev lo  proto kernel  scope link  src 127.0.0.1 
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 
broadcast 172.17.0.0 dev docker0  proto kernel  scope link  src 172.17.42.1 
local 172.17.42.1 dev docker0  proto kernel  scope host  src 172.17.42.1 
broadcast 172.17.255.255 dev docker0  proto kernel  scope link  src 172.17.42.1 
broadcast 192.168.1.0 dev wlp1s0  proto kernel  scope link  src 192.168.1.80 
local 192.168.1.80 dev wlp1s0  proto kernel  scope host  src 192.168.1.80 
broadcast 192.168.1.255 dev wlp1s0  proto kernel  scope link  src 192.168.1.80 

Referências

por 08.10.2014 / 22:34