{"id":3067,"date":"2022-12-20T16:43:25","date_gmt":"2022-12-20T19:43:25","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/iprule-man8\/"},"modified":"2022-12-20T16:43:25","modified_gmt":"2022-12-20T19:43:25","slug":"iprule-man8","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/iprule-man8\/","title":{"rendered":"IP&minus;RULE (man8)"},"content":{"rendered":"<h1 align=\"center\">IP\u2212RULE<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">ip-rule \u2212 routing policy database management<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:23%; margin-top: 1em\"><b>ip<\/b> [ <i>OPTIONS<\/i> ] <b>rule<\/b> { <i>COMMAND<\/i> | <b>help<\/b> }<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><b>ip rule<\/b> [ <b>list<\/b> [ <i>SELECTOR<\/i> ]]<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><b>ip rule<\/b> { <b>add<\/b> | <b>del<\/b> } <i>SELECTOR ACTION<\/i><\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><b>ip rule<\/b> { <b>flush<\/b> | <b>save<\/b> | <b>restore<\/b> }<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>SELECTOR<\/i> := [ <b>not<\/b> ] [ <b>from<\/b> <i>PREFIX<\/i> ] [ <b>to<\/b> <i>PREFIX<\/i> ] [ <b>tos<\/b> <i>TOS<\/i> ] [ <b>fwmark<\/b> <i>FWMARK<\/i>[<b>\/<\/b><i>MASK<\/i>] ] [ <b>iif<\/b> <i>STRING<\/i> ] [ <b>oif<\/b> <i>STRING<\/i> ] [ <b>pref<\/b> <i>NUMBER<\/i> ] [ <i>l3mdev<\/i> ] [ <b>uidrange<\/b> <i>NUMBER<\/i>&#8211;<i>NUMBER<\/i> ] [ <b>ipproto<\/b> <i>PROTOCOL<\/i> ] [ <b>sport<\/b> [ <i>NUMBER<\/i> | <i>NUMBER<\/i>&#8211;<i>NUMBER<\/i> ] ] [ <b>dport<\/b> [ <i>NUMBER<\/i> | <i>NUMBER<\/i>&#8211;<i>NUMBER<\/i> ] ] [ <b>tun_id<\/b> <i>TUN_ID<\/i> ]<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>ACTION<\/i> := [ <b>table<\/b> <i>TABLE_ID<\/i> ] [ <b>protocol<\/b> <i>PROTO<\/i> ] [ <b>nat<\/b> <i>ADDRESS<\/i> ] [ <b>realms<\/b> [<i>SRCREALM<\/i><b>\/<\/b>]<i>DSTREALM<\/i> ] [ <b>goto<\/b> <i>NUMBER<\/i> ] <i>SUPPRESSOR<\/i><\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>SUPPRESSOR<\/i> := [ <b>suppress_prefixlength<\/b> <i>NUMBER<\/i> ] [ <b>suppress_ifgroup<\/b> <i>GROUP<\/i> ]<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>TABLE_ID<\/i> := [ <b>local<\/b> | <b>main<\/b> | <b>default<\/b> | <i>NUMBER<\/i> ]<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>ip rule<\/i> manipulates rules in the routing policy database control the route selection algorithm.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Classic routing algorithms used in the Internet make routing decisions based only on the destination address of packets (and in theory, but not in practice, on the TOS field).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In some circumstances we want to route packets differently depending not only on destination addresses, but also on other packet fields: source address, IP protocol, transport protocol ports or even packet payload. This task is called \u2019policy routing\u2019.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">To solve this task, the conventional destination based routing table, ordered according to the longest match rule, is replaced with a \u2019routing policy database\u2019 (or RPDB), which selects routes by executing some set of rules.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Each policy routing rule consists of a <b>selector<\/b> and an <b>action predicate.<\/b> The RPDB is scanned in order of decreasing priority (note that lower number means higher priority, see the description of <i>PREFERENCE<\/i> below). The selector of each rule is applied to {source address, destination address, incoming interface, tos, fwmark} and, if the selector matches the packet, the action is performed. The action predicate may return with success. In this case, it will either give a route or failure indication and the RPDB lookup is terminated. Otherwise, the RPDB program continues with the next rule.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Semantically, the natural action is to select the nexthop and the output device.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">At startup time the kernel configures the default RPDB consisting of three rules:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p>1.<\/p>\n<\/td>\n<td width=\"8%\"><\/td>\n<td width=\"78%\">\n<p>Priority: 0, Selector: match anything, Action: lookup routing table <b>local<\/b> (ID 255). The <b>local<\/b> table is a special routing table containing high priority control routes for local and broadcast addresses.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p>2.<\/p>\n<\/td>\n<td width=\"8%\"><\/td>\n<td width=\"78%\">\n<p>Priority: 32766, Selector: match anything, Action: lookup routing table <b>main<\/b> (ID 254). The <b>main<\/b> 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.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p>3.<\/p>\n<\/td>\n<td width=\"8%\"><\/td>\n<td width=\"78%\">\n<p>Priority: 32767, Selector: match anything, Action: lookup routing table <b>default<\/b> (ID 253). The <b>default<\/b> table is empty. It is reserved for some post-processing if no previous default rules selected the packet. This rule may also be deleted.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">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 <b>realms<\/b>. These values do not override those contained in the routing tables. They are only used if the route did not select any attributes.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The RPDB may contain rules of the following types:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>unicast<\/b> &#8211; the rule prescribes to return the route found in the routing table referenced by the rule.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>blackhole<\/b> &#8211; the rule prescribes to silently drop the packet.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>unreachable<\/b> &#8211; the rule prescribes to generate a \u2019Network is unreachable\u2019 error.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>prohibit<\/b> &#8211; the rule prescribes to generate \u2019Communication is administratively prohibited\u2019 error.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>nat<\/b> &#8211; the rule prescribes to translate the source address of the IP packet into some other value.<\/p>\n<p style=\"margin-left:11%;\"><b>ip rule add &#8211; insert a new rule <br \/> ip rule delete &#8211; delete a rule<\/b><\/p>\n<p style=\"margin-left:22%;\"><b>type<\/b> <i>TYPE<\/i> <b>(default)<\/b><\/p>\n<p style=\"margin-left:32%;\">the type of this rule. The list of valid types was given in the previous subsection.<\/p>\n<p style=\"margin-left:22%;\"><b>from<\/b> <i>PREFIX<\/i><\/p>\n<p style=\"margin-left:32%;\">select the source prefix to match.<\/p>\n<p style=\"margin-left:22%;\"><b>to<\/b> <i>PREFIX<\/i><\/p>\n<p style=\"margin-left:32%;\">select the destination prefix to match.<\/p>\n<p style=\"margin-left:22%;\"><b>iif<\/b> <i>NAME<\/i><\/p>\n<p style=\"margin-left:32%;\">select the incoming device to match. If the interface is loopback, the rule only matches packets originating from this host. This means that you may create separate routing tables for forwarded and local packets and, hence, completely segregate them.<\/p>\n<p style=\"margin-left:22%;\"><b>oif<\/b> <i>NAME<\/i><\/p>\n<p style=\"margin-left:32%;\">select the outgoing device to match. The outgoing interface is only available for packets originating from local sockets that are bound to a device.<\/p>\n<p style=\"margin-left:22%;\"><b>tos<\/b> <i>TOS<\/i> <b><br \/> dsfield<\/b> <i>TOS<\/i><\/p>\n<p style=\"margin-left:32%;\">select the TOS value to match.<\/p>\n<p style=\"margin-left:22%;\"><b>fwmark<\/b> <i>MARK<\/i><\/p>\n<p style=\"margin-left:32%;\">select the <b>fwmark<\/b> value to match.<\/p>\n<p style=\"margin-left:22%;\"><b>uidrange<\/b> <i>NUMBER-NUMBER<\/i><\/p>\n<p style=\"margin-left:32%;\">select the <b>uid<\/b> value to match.<\/p>\n<p style=\"margin-left:22%;\"><b>ipproto<\/b> <i>PROTOCOL<\/i><\/p>\n<p style=\"margin-left:32%;\">select the ip protocol value to match.<\/p>\n<p style=\"margin-left:22%;\"><b>sport<\/b> <i>NUMBER | NUMBER-NUMBER<\/i><\/p>\n<p style=\"margin-left:32%;\">select the source port value to match. supports port range.<\/p>\n<p style=\"margin-left:22%;\"><b>dport<\/b> <i>NUMBER | NUMBER-NUMBER<\/i><\/p>\n<p style=\"margin-left:32%;\">select the destination port value to match. supports port range.<\/p>\n<p style=\"margin-left:22%;\"><b>priority<\/b> <i>PREFERENCE<\/i><\/p>\n<p style=\"margin-left:32%;\">the priority of this rule. <i>PREFERENCE<\/i> is an unsigned integer value, higher number means lower priority, and rules get processed in order of increasing number. Each rule should have an explicitly set <i>unique<\/i> priority value. The options preference and order are synonyms with priority.<\/p>\n<p style=\"margin-left:22%;\"><b>table<\/b> <i>TABLEID<\/i><\/p>\n<p style=\"margin-left:32%;\">the routing table identifier to lookup if the rule selector matches. It is also possible to use lookup instead of table.<\/p>\n<p style=\"margin-left:22%;\"><b>protocol<\/b> <i>PROTO<\/i><\/p>\n<p style=\"margin-left:32%;\">the routing protocol who installed the rule in question. As an example when zebra installs a rule it would get RTPROT_ZEBRA as the installing protocol.<\/p>\n<p style=\"margin-left:22%;\"><b>suppress_prefixlength<\/b> <i>NUMBER<\/i><\/p>\n<p style=\"margin-left:32%;\">reject routing decisions that have a prefix length of NUMBER or less.<\/p>\n<p style=\"margin-left:22%;\"><b>suppress_ifgroup<\/b> <i>GROUP<\/i><\/p>\n<p style=\"margin-left:32%;\">reject routing decisions that use a device belonging to the interface group GROUP.<\/p>\n<p style=\"margin-left:22%;\"><b>realms<\/b> <i>FROM\/TO<\/i><\/p>\n<p style=\"margin-left:32%;\">Realms to select if the rule matched and the routing table lookup succeeded. Realm <i>TO<\/i> is only used if the route did not select any realm.<\/p>\n<p style=\"margin-left:22%;\"><b>nat<\/b> <i>ADDRESS<\/i><\/p>\n<p style=\"margin-left:32%;\">The base of the IP address block to translate (for source addresses). The <i>ADDRESS<\/i> may be either the start of the block of NAT addresses (selected by NAT routes) or a local host address (or even zero). In the last case the router does not translate the packets, but masquerades them to this address. Using map-to instead of nat means the same thing.<\/p>\n<p style=\"margin-left:32%; margin-top: 1em\"><b>Warning:<\/b> Changes to the RPDB made with these commands do not become active immediately. It is assumed that after a script finishes a batch of updates, it flushes the routing cache with <b>ip route flush cache<\/b>.<\/p>\n<p style=\"margin-left:11%;\"><b>ip rule flush &#8211; also dumps all the deleted rules.<\/b><\/p>\n<p style=\"margin-left:22%;\"><b>protocol<\/b> <i>PROTO<\/i><\/p>\n<p style=\"margin-left:32%;\">Select the originating protocol.<\/p>\n<p style=\"margin-left:11%;\"><b>ip rule show &#8211; list rules<\/b><\/p>\n<p style=\"margin-left:22%;\">This command has no arguments. The options list or lst are synonyms with show.<\/p>\n<p style=\"margin-left:11%;\"><b>ip rule save<\/b><\/p>\n<p style=\"margin-left:22%;\"><b>protocol<\/b> <i>PROTO<\/i><\/p>\n<p style=\"margin-left:32%;\">Select the originating protocol.<\/p>\n<p style=\"margin-left:11%;\">save rules table information to stdout<\/p>\n<p style=\"margin-left:22%;\">This command behaves like <b>ip rule show<\/b> except that the output is raw data suitable for passing to <b>ip rule restore<\/b>.<\/p>\n<p style=\"margin-left:11%;\"><b>ip rule restore<\/b><\/p>\n<p style=\"margin-left:22%;\">restore rules table information from stdin <br \/> This command expects to read a data stream as returned from <b>ip rule save<\/b>. It will attempt to restore the rules table information exactly as it was at the time of the save. Any rules already in the table are left unchanged, and duplicates are not ignored.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>ip<\/b>(8)<\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Original Manpage by Michail Litvak <mci@owl.openwall.com><\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  ip-rule \u2212 routing policy database management <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[5,52,217,4],"class_list":["post-3067","post","type-post","status-publish","format-standard","hentry","category-8-administracion-del-sistema","tag-5","tag-administracion","tag-ip-rule","tag-man8"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3067","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=3067"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3067\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=3067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=3067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=3067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}