{"id":6032,"date":"2014-01-13T21:37:51","date_gmt":"2014-01-13T13:37:51","guid":{"rendered":"http:\/\/jpuyy.com\/?p=6032"},"modified":"2014-08-14T10:53:01","modified_gmt":"2014-08-14T02:53:01","slug":"ip-rule-and-ip-route","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=6032","title":{"rendered":"ip rule\u548c ip route"},"content":{"rendered":"<p>\u76f8\u5bf9ip route \uff0cip rule\u662f\u9ad8\u7ea7\u8def\u7531\uff0c\u80fd\u5b9e\u73b0\u4e0d\u540c\u6761\u4ef6\u8def\u7531\u7684\u8f6c\u53d1\u3002<\/p>\n<p>linux\u7cfb\u7edf\u7ef4\u62a4\u4e86\u8def\u7531\u8868\uff0c\u7528ip rule show\u53ef\u4ee5\u67e5\u770b\u8def\u7531\u8868\u3002<\/p>\n<pre># ip rule show\r\n0: from all lookup local \r\n32766: from all lookup main \r\n32767: from all lookup default<\/pre>\n<p>\u8def\u7531\u8868\u8bb0\u5f55\u5728\/etc\/iproute2\/rt_tables\u6587\u4ef6\u4e2d\uff0c\u9ed8\u8ba4\u91cc\u9762\u4f1a\u7528\u8fd9\u4e48\u51e0\u884c\uff0c\u5728\u8fd9\u4e2a\u6587\u4ef6\u91cc\u6dfb\u52a0\u7684\u8def\u7531\u8868\u5373\u65f6\u751f\u6548<\/p>\n<pre>255 local\r\n254 main\r\n253 default\r\n0 unspec<\/pre>\n<p>\u6240\u4ee5\u81ea\u5b9a\u4e49\u4e00\u4e2a\u8def\u7531\u8868\u7684\u65f6\u5019\uff0c\u5e8f\u53f7\u8981\u57281-252\u4e4b\u95f4\uff0c\u8def\u7531\u9009\u62e9\u7684\u4f18\u5148\u7ea7\u4e5f\u4e0e\u6570\u5b57\u7684\u5927\u5c0f\u6709\u5173\uff0c\u8d8a\u5c0f\u7684\u4f18\u5148\u7ea7\u8d8a\u9ad8\uff0c\u5148\u5339\u914d\u3002<br \/>\n\u6570\u5b57\u540e\u9762\u8981\u89c4\u5b9a\u4e00\u4e2a\u522b\u540d\uff0c\u65b9\u4fbf\u4f7f\u7528\u548c\u8fa8\u8ba4\u3002<\/p>\n<p>\u8fd9\u6837\u8def\u7531\u8868\u7684\u67e5\u770b\u53ef\u6709\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n<pre>ip route list table table_number\r\nip route list table table_name<\/pre>\n<p>\u5982\u67e5\u770b\u9ed8\u8ba4\u8def\u7531\u8868\u53ef\u7528\u5982\u4e0b\u547d\u4ee4<\/p>\n<pre>ip route list table main\r\nip route list table 254<\/pre>\n<p>\u8def\u7531\u8868\u6dfb\u52a0\u5b8c\u4e4b\u540e\uff0c\u63a5\u4e0b\u6765\u5c31\u662f\u5bf9\u8def\u7531\u8868\u7684\u64cd\u4f5c\uff0c\u5982\u679c\u6211\u6709<\/p>\n<p>eth1 \u914d\u7f6eip\u00a0192.168.1.8\/24 \u8def\u7531\u8868 101 mytable1<\/p>\n<p>eth2 \u914d\u7f6eip \u00a0192.168.2.8\/24\u00a0\u8def\u7531\u8868 102 mytable2<\/p>\n<p>\u4e0d\u540c\u6bb5\u7684\u4ece\u4e0d\u540c\u7684\u7f51\u5361\u8d70\u3002<\/p>\n<pre>ip route add 192.168.1.0 dev eth1 src 192.168.1.8 table mytable1\r\nip route add default via 192.168.1.1 table mytable1\r\nip rule add from 192.168.1.8 table mytable1\r\n\r\nip route add 192.168.2.0 dev eth2 src 192.168.2.8 table mytable2\r\nip route add default via 192.168.2.1 table mytable2\r\nip rule add from 192.168.2.8 table mytable2<\/pre>\n<p>\u73b0\u5728\u4f7f\u7528ip rule show\u67e5\u770b<\/p>\n<pre># ip rule show\r\n 0: from all lookup local\r\n 32764: from 192.168.2.8 lookup mytable2\r\n 32765: from 192.168.1.8 lookup mytable1\r\n 32766: from all lookup main\r\n 32767: from all lookup default<\/pre>\n<p>\u8fd9\u65f6\u8981\u5220\u9664rule\u53ef\u4f7f\u7528<\/p>\n<pre>ip rule del prio 32764<\/pre>\n<p>ip rule\u8fd8\u53ef\u4ee5\u5b9e\u73b0\u66f4\u9ad8\u7ea7\u7684\u529f\u80fd\uff0c\u6bd4\u5982\u6839\u636eip\u76ee\u7684\u5730\u5740\uff0c\u5305\u5927\u5c0f\u6765\u8fdb\u884c\u8f6c\u53d1\u3002<\/p>\n<p>\u67e5\u770broute -n flag<\/p>\n<p>The flags<\/p>\n<p>Following is the list of flags and their significance in the routing table :<\/p>\n<p>U : This flag signifies that the route is up<br \/>\nG : This flag signifies that the route is to a gateway. If this flag is not present then we can say that the route is to a directly connected destination<br \/>\nH : This flag signifies that the route is to a host which means that the destination is a complete host address. If this flag is not present then it can be assumed that the route is to a network and destination would be a network address.<br \/>\nD : This flag signifies that this route is created by a redirect.<br \/>\nM : This flag signifies that this route is modified by a redirect.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76f8\u5bf9ip route \uff0cip rule\u662f\u9ad8\u7ea7\u8def\u7531\uff0c\u80fd\u5b9e\u73b0\u4e0d\u540c\u6761\u4ef6\u8def\u7531\u7684\u8f6c\u53d1\u3002 linux\u7cfb\u7edf\u7ef4\u62a4\u4e86\u8def\u7531\u8868\uff0c\u7528ip rule show\u53ef\u4ee5\u67e5\u770b\u8def\u7531\u8868\u3002 # ip rule show 0: from all lookup local 32766: from all lookup main 32767: from all lookup default \u8def\u7531\u8868\u8bb0\u5f55\u5728\/etc\/iproute2\/rt_tables\u6587\u4ef6\u4e2d\uff0c\u9ed8\u8ba4\u91cc\u9762\u4f1a\u7528\u8fd9\u4e48\u51e0\u884c\uff0c\u5728\u8fd9\u4e2a\u6587\u4ef6\u91cc\u6dfb\u52a0\u7684\u8def\u7531\u8868\u5373\u65f6\u751f\u6548 255 local 254 main 253 default 0 unspec \u6240\u4ee5\u81ea\u5b9a\u4e49\u4e00\u4e2a\u8def\u7531\u8868\u7684\u65f6\u5019\uff0c\u5e8f\u53f7\u8981\u57281-252\u4e4b\u95f4\uff0c\u8def\u7531\u9009\u62e9\u7684\u4f18\u5148\u7ea7\u4e5f\u4e0e\u6570\u5b57\u7684\u5927\u5c0f\u6709\u5173\uff0c\u8d8a\u5c0f\u7684\u4f18\u5148\u7ea7\u8d8a\u9ad8\uff0c\u5148\u5339\u914d\u3002 \u6570\u5b57\u540e\u9762\u8981\u89c4\u5b9a\u4e00\u4e2a\u522b\u540d\uff0c\u65b9\u4fbf\u4f7f\u7528\u548c\u8fa8\u8ba4\u3002 \u8fd9\u6837\u8def\u7531\u8868\u7684\u67e5\u770b\u53ef\u6709\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\uff1a ip route list table table_number ip route list table table_name \u5982\u67e5\u770b\u9ed8\u8ba4\u8def\u7531\u8868\u53ef\u7528\u5982\u4e0b\u547d\u4ee4 ip route list table main ip [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-6032","post","type-post","status-publish","format-standard","hentry","category-life"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6032","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6032"}],"version-history":[{"count":15,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6032\/revisions"}],"predecessor-version":[{"id":6621,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6032\/revisions\/6621"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}