
내 컴퓨터에 명령을 입력하면 ip rule show
다음과 같이 출력됩니다.
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
숫자는 무엇을 하는가0,32766그리고32767평균?
나는 이것이 몇 가지 우선순위임을 이해하고 있으며0특별 우선순위이므로 삭제할 수 없습니다.
또한 새 정책을 추가하면 다음과 같은 우선순위로 생성됩니다.32765. 내 이해가 맞나요?
또한 우선순위에 관한 몇 가지 정보가 표시됩니다 ip rule add
.여기.
실제로 역사적인 이유로 인해 IP 규칙 추가에는 우선 순위 값이 필요하지 않으며 고유하지 않은 값을 허용합니다. 사용자가 우선순위를 제공하지 않으면 커널이 우선순위를 선택합니다. 사용자가 이미 존재하는 우선순위 값을 사용하여 규칙을 생성하는 경우 커널은 요청을 거부하지 않습니다. 동일한 우선순위를 가진 모든 이전 규칙 앞에 새 규칙을 추가합니다. 더 이상 디자인 실수가 아닙니다. 그리고 언젠가는 수정될 것이므로 이 기능에 의존하지 마십시오. 명시적인 우선순위를 사용하세요.
답변1
매뉴얼 페이지에서ip-rule
:
시작 시 커널은 세 가지 규칙으로 구성된 기본 RPDB를 구성합니다.
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.
따라서 해당 숫자 0, 32766 및 32767은 규칙이 적용될 우선순위입니다.
메모:위에 언급된 다른 번호인 255, 254, 253은 이 파일에 설명된 라우팅 테이블에 해당합니다.
$ more /etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
위의 이름은 다음과 같이 라우팅 테이블을 쿼리할 때 사용할 수 있습니다.
$ 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