{"id":2358,"date":"2025-09-25T15:34:35","date_gmt":"2025-09-25T07:34:35","guid":{"rendered":"https:\/\/www.madbull.site\/?p=2358"},"modified":"2025-09-25T15:35:14","modified_gmt":"2025-09-25T07:35:14","slug":"linux-%e5%a4%9a%e7%bd%91%e5%8d%a1%e5%90%8c%e7%bd%91%e6%ae%b5%e9%85%8d%e7%bd%ae%e5%86%b2%e7%aa%81%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.madbull.site\/?p=2358","title":{"rendered":"Linux \u591a\u7f51\u5361\u540c\u7f51\u6bb5\u914d\u7f6e\u51b2\u7a81\u95ee\u9898"},"content":{"rendered":"\n<p>\u5728\u67d0\u4e9b\u7f51\u7edc\u573a\u666f\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5728\u4e00\u53f0 Linux \u670d\u52a1\u5668\u4e0a\u914d\u7f6e\u591a\u4e2a\u7269\u7406\u7f51\u5361\uff0c\u5e76\u4e3a\u5b83\u4eec\u5206\u914d<strong>\u540c\u4e00\u5b50\u7f51\u5185\u7684\u4e0d\u540c IP \u5730\u5740<\/strong>\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e3a\u9ad8\u53ef\u7528\u670d\u52a1\u63d0\u4f9b\u591a\u4e2a\u63a5\u5165\u70b9\uff1b<\/li>\n\n\n\n<li>\u5b9e\u73b0\u7f51\u7edc\u9694\u79bb\u4f46\u5171\u4eab\u540c\u4e00\u5e7f\u64ad\u57df\uff1b<\/li>\n\n\n\n<li>\u6d4b\u8bd5\u591a\u8def\u5f84\u901a\u4fe1\u884c\u4e3a\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u7136\u800c\uff0c\u8fd9\u79cd\u770b\u4f3c\u7b80\u5355\u7684\u914d\u7f6e\u5728\u5b9e\u9645\u64cd\u4f5c\u4e2d\u5e38\u5e38\u5bfc\u81f4<strong>\u7f51\u7edc\u4e0d\u901a\u6216\u884c\u4e3a\u5f02\u5e38<\/strong>\u3002\u672c\u6587\u5206\u6790\u5176\u539f\u56e0\uff0c\u5e76\u63d0\u4f9b\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u5178\u578b\u914d\u7f6e\u4e0e\u95ee\u9898\u73b0\u8c61<\/h2>\n\n\n\n<p>\u5047\u8bbe\u670d\u52a1\u5668\u6709\u4e24\u4e2a\u7f51\u5361 <code>eth0<\/code> \u548c <code>eth1<\/code>\uff0c\u8fde\u63a5\u5230\u540c\u4e00\u4e2a\u4e8c\u5c42\u4ea4\u6362\u673a\uff08\u5373\u5904\u4e8e\u540c\u4e00\u5e7f\u64ad\u57df\uff09\uff0c\u6267\u884c\u5982\u4e0b\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ip addr add 192.168.1.56\/24 dev eth0<br>ip addr add 192.168.1.57\/24 dev eth1<\/code><\/pre>\n\n\n\n<p>\u6b64\u65f6\u53ef\u80fd\u51fa\u73b0\u4ee5\u4e0b\u73b0\u8c61\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4ece\u5916\u90e8\u4e3b\u673a ping <code>192.168.1.56<\/code> \u548c <code>192.168.1.57<\/code>\uff0c<strong>\u53ea\u6709\u5176\u4e2d\u4e00\u4e2a\u80fd\u901a<\/strong>\uff1b<\/li>\n\n\n\n<li>\u6216\u8005\u4e24\u4e2a\u90fd\u80fd ping \u901a\uff0c\u4f46 TCP \u8fde\u63a5\u4e0d\u7a33\u5b9a\uff1b<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>arping<\/code> \u53d1\u73b0\uff0c\u4e24\u4e2a IP \u5730\u5740\u8fd4\u56de\u7684\u662f<strong>\u540c\u4e00\u4e2a MAC \u5730\u5740<\/strong>\uff08\u901a\u5e38\u662f\u5148\u6fc0\u6d3b\u7684\u7f51\u5361\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u95ee\u9898\u6839\u6e90\uff1aLinux \u7684\u9ed8\u8ba4 ARP \u884c\u4e3a<\/h2>\n\n\n\n<p>Linux \u5185\u6838\u5728\u5904\u7406 ARP\uff08\u5730\u5740\u89e3\u6790\u534f\u8bae\uff09\u65f6\uff0c\u9ed8\u8ba4\u91c7\u7528\u8f83\u4e3a\u5bbd\u677e\u7684\u7b56\u7565\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"has-large-font-size\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-3-color\">\u53ea\u8981\u672c\u673a\u62e5\u6709\u67d0\u4e2a IP \u5730\u5740\uff0c\u65e0\u8bba\u8be5 IP \u914d\u7f6e\u5728\u54ea\u4e2a\u63a5\u53e3\u4e0a\uff0c\u6240\u6709\u63a5\u53e3\u90fd\u4f1a\u54cd\u5e94\u5bf9\u8be5 IP \u7684 ARP \u8bf7<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-3-color\">\u6c42<\/mark><\/strong>\u3002<\/mark><\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u610f\u5473\u7740\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f53\u5916\u90e8\u4e3b\u673a\u901a\u8fc7arp\u534f\u8bae\u8be2\u95ee \u201c\u8c01\u6709 192.168.1.57\uff1f\u201d \u65f6\uff0c<\/li>\n\n\n\n<li><code>eth0<\/code>\uff08\u5373\u4f7f\u53ea\u914d\u7f6e\u4e86 .56\uff09\u4e5f\u4f1a\u54cd\u5e94\uff0c\u56e0\u4e3a\u5b83\u77e5\u9053\u672c\u673a\u62e5\u6709 .57\uff08\u5728 <code>eth1<\/code> \u4e0a\uff09\uff1b<\/li>\n\n\n\n<li>\u5916\u90e8\u4e3b\u673a\u4e8e\u662f\u5c06 .57 \u7684 MAC \u5730\u5740\u8bb0\u5f55\u4e3a <code>eth0<\/code> \u7684 MAC\uff1b<\/li>\n\n\n\n<li>\u540e\u7eed\u53d1\u5f80 .57 \u7684\u6570\u636e\u5305\u88ab\u4ea4\u6362\u673a\u9001\u5230 <code>eth0<\/code>\uff0c\u4f46 <code>eth0<\/code> \u5e76\u672a\u7ed1\u5b9a\u8be5 IP\uff0c\u5bfc\u81f4\u6570\u636e\u5305\u88ab\u4e22\u5f03\u6216\u65e0\u6cd5\u6b63\u786e\u5904\u7406\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u79cd\u884c\u4e3a\u7531\u5185\u6838\u53c2\u6570 <code>arp_ignore<\/code> \u548c <code>arp_announce<\/code> \u63a7\u5236\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u89e3\u51b3\u65b9\u6848<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6848 1\uff1a\u8c03\u6574 ARP \u76f8\u5173\u5185\u6838\u53c2\u6570<\/h3>\n\n\n\n<p>\u901a\u8fc7\u4fee\u6539\u4ee5\u4e0b\u4e24\u4e2a\u53c2\u6570\uff0c\u53ef\u4f7f\u6bcf\u4e2a\u63a5\u53e3<strong>\u4ec5\u54cd\u5e94\u81ea\u8eab\u914d\u7f6e\u7684 IP \u5730\u5740\u7684 ARP \u8bf7\u6c42<\/strong>\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u4e34\u65f6\u751f\u6548\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u5bf9\u6240\u6709\u63a5\u53e3\u751f\u6548<br>echo 2 > \/proc\/sys\/net\/ipv4\/conf\/all\/arp_ignore<br>echo 2 > \/proc\/sys\/net\/ipv4\/conf\/all\/arp_announce<br><br># \u6216\u9488\u5bf9\u5177\u4f53\u63a5\u53e3\uff08\u66f4\u7cbe\u786e\uff09<br>echo 2 > \/proc\/sys\/net\/ipv4\/conf\/eth0\/arp_ignore<br>echo 2 > \/proc\/sys\/net\/ipv4\/conf\/eth0\/arp_announce<br>echo 2 > \/proc\/sys\/net\/ipv4\/conf\/eth1\/arp_ignore<br>echo 2 > \/proc\/sys\/net\/ipv4\/conf\/eth1\/arp_announce<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u6c38\u4e45\u751f\u6548\uff1a<\/h4>\n\n\n\n<p>\u5728 <code>\/etc\/sysctl.conf<\/code> \u6216 <code>\/etc\/sysctl.d\/99-arp-fix.conf<\/code> \u4e2d\u6dfb\u52a0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">conf\u7f16\u8f91<code>net.ipv4.conf.all.arp_ignore = 2\nnet.ipv4.conf.all.arp_announce = 2<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u6267\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sysctl -p<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u53c2\u6570\u8bf4\u660e\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>arp_ignore = 2<\/code>\uff1a\u4ec5\u5f53\u76ee\u6807 IP \u914d\u7f6e\u5728<strong>\u63a5\u6536 ARP \u8bf7\u6c42\u7684\u63a5\u53e3\u4e0a<\/strong>\u65f6\uff0c\u624d\u54cd\u5e94\u3002<\/li>\n\n\n\n<li><code>arp_announce = 2<\/code>\uff1a\u5728\u53d1\u9001 ARP \u54cd\u5e94\u65f6\uff0c\u4f18\u5148\u4f7f\u7528<strong>\u76ee\u6807 IP \u6240\u5728\u63a5\u53e3\u7684 MAC \u5730\u5740<\/strong>\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6b64\u65b9\u6848\u9002\u7528\u4e8e\u5927\u591a\u6570\u4ec5\u9700\u201c\u4e24\u4e2a IP \u5747\u53ef\u88ab\u8bbf\u95ee\u201d\u7684\u573a\u666f\uff0c\u65e0\u9700\u590d\u6742\u8def\u7531\u914d\u7f6e\u3002<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6848 2\uff1a\u914d\u5408\u7b56\u7565\u8def\u7531\uff08Policy Routing\uff09<\/h3>\n\n\n\n<p>\u5982\u679c\u9664\u4e86 ARP \u6b63\u786e\u5916\uff0c\u8fd8\u9700\u786e\u4fdd<strong>\u51fa\u7ad9\u6d41\u91cf\u4ece\u5bf9\u5e94\u63a5\u53e3\u53d1\u51fa<\/strong>\uff08\u4f8b\u5982 .56 \u7684\u6d41\u91cf\u5fc5\u987b\u4ece eth0 \u51fa\uff0c.57 \u4ece eth1 \u51fa\uff09\uff0c\u5219\u9700\u7ed3\u5408\u7b56\u7565\u8def\u7531\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6b65\u9aa4\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># 1. \u521b\u5efa\u81ea\u5b9a\u4e49\u8def\u7531\u8868\uff08\u5982 100 \u548c 101\uff09<br>echo \"100 table_eth0\" >> \/etc\/iproute2\/rt_tables<br>echo \"101 table_eth1\" >> \/etc\/iproute2\/rt_tables<br><br># 2. \u4e3a\u6bcf\u4e2a\u8868\u6dfb\u52a0\u8def\u7531\uff08\u5047\u8bbe\u7f51\u5173\u4e3a 192.168.1.1\uff09<br>ip route add default via 192.168.1.1 dev eth0 table 100<br>ip route add default via 192.168.1.1 dev eth1 table 101<br><br># 3. \u6dfb\u52a0\u7b56\u7565\u89c4\u5219<br>ip rule add from 192.168.1.56 table 100<br>ip rule add from 192.168.1.57 table 101<br><br># 4. \uff08\u53ef\u9009\uff09\u63a7\u5236\u56de\u5305\u8def\u5f84<br>ip rule add iif eth0 table 100<br>ip rule add iif eth1 table 101<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6ce8\u610f\uff1a\u6b64\u65b9\u6848<strong>\u4ecd\u9700\u914d\u5408 <code>arp_ignore=2<\/code> \u548c <code>arp_announce=2<\/code><\/strong>\uff0c\u5426\u5219 ARP \u95ee\u9898\u4f9d\u7136\u5b58\u5728\u3002<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u9a8c\u8bc1\u65b9\u6cd5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u68c0\u67e5 ARP \u54cd\u5e94\u662f\u5426\u6b63\u786e<\/h3>\n\n\n\n<p>\u4ece\u53e6\u4e00\u53f0\u4e3b\u673a\u6267\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>arping -I ethX 192.168.1.56<br>arping -I ethX 192.168.1.57<\/code><\/pre>\n\n\n\n<p>\u5e94\u5206\u522b\u770b\u5230 <code>eth0<\/code> \u548c <code>eth1<\/code> \u7684 MAC \u5730\u5740\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u67e5\u770b\u5b9e\u9645\u8def\u7531\u8def\u5f84<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ip route get 8.8.8.8 from 192.168.1.56<br>ip route get 8.8.8.8 from 192.168.1.57<\/code><\/pre>\n\n\n\n<p>\u786e\u8ba4\u4f7f\u7528\u4e86\u9884\u671f\u7684\u8def\u7531\u8868\u548c\u51fa\u53e3\u63a5\u53e3\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u68c0\u67e5\u5185\u6838\u53c2\u6570<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sysctl net.ipv4.conf.eth0.arp_ignore<br>sysctl net.ipv4.conf.eth0.arp_announce<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u6ce8\u610f\u4e8b\u9879<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e0d\u5efa\u8bae\u5173\u95ed\u63a5\u53e3\u7684 ARP \u529f\u80fd<\/strong>\uff08\u5982 <code>ip link set eth1 arp off<\/code>\uff09\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u8be5\u63a5\u53e3\u65e0\u6cd5\u901a\u4fe1\u3002<\/li>\n\n\n\n<li>\u82e5\u4e24\u4e2a\u7f51\u5361\u8fde\u63a5\u5230<strong>\u4e0d\u540c\u4ea4\u6362\u673a\u4f46\u540c\u7f51\u6bb5<\/strong>\uff0c\u4ecd\u5c5e\u4e8e\u540c\u4e00\u5e7f\u64ad\u57df\uff0c\u540c\u6837\u4f1a\u89e6\u53d1 ARP \u51b2\u7a81\u3002<\/li>\n\n\n\n<li>\u5728\u5bb9\u5668\u6216\u865a\u62df\u5316\u73af\u5883\u4e2d\uff0c\u8fd8\u9700\u8003\u8651\u5e95\u5c42\u7f51\u7edc\u6a21\u578b\u7684\u5f71\u54cd\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u603b\u7ed3<\/h2>\n\n\n\n<p>Linux \u591a\u7f51\u5361\u540c\u7f51\u6bb5\u914d\u7f6e\u7684\u6838\u5fc3\u95ee\u9898\u5728\u4e8e<strong>\u9ed8\u8ba4 ARP \u884c\u4e3a\u8fc7\u4e8e\u5bbd\u677e<\/strong>\u3002\u901a\u8fc7\u5408\u7406\u8bbe\u7f6e <code>arp_ignore<\/code> \u548c <code>arp_announce<\/code> \u53c2\u6570\uff0c\u5373\u53ef\u89e3\u51b3\u7edd\u5927\u591a\u6570\u901a\u4fe1\u5f02\u5e38\u3002\u82e5\u9700\u66f4\u7cbe\u7ec6\u7684\u6d41\u91cf\u63a7\u5236\uff0c\u53ef\u8f85\u4ee5\u7b56\u7565\u8def\u7531\u3002<\/p>\n\n\n\n<p>\u8be5\u914d\u7f6e\u867d\u4e0d\u5e38\u89c1\uff0c\u4f46\u5728\u7279\u5b9a\u7f51\u7edc\u67b6\u6784\u4e2d\u5177\u6709\u5b9e\u7528\u4ef7\u503c\u3002\u7406\u89e3\u5176\u539f\u7406\uff0c\u6709\u52a9\u4e8e\u907f\u514d\u201c\u770b\u4f3c\u914d\u7f6e\u6b63\u786e\u5374\u65e0\u6cd5\u901a\u4fe1\u201d\u7684\u56f0\u60d1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u67d0\u4e9b\u7f51\u7edc\u573a\u666f\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5728\u4e00\u53f0 Linux \u670d\u52a1\u5668\u4e0a\u914d\u7f6e\u591a\u4e2a\u7269\u7406\u7f51\u5361\uff0c\u5e76\u4e3a\u5b83\u4eec\u5206\u914d\u540c\u4e00\u5b50\u7f51\u5185\u7684\u4e0d\u540c IP [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":450,"comment_status":"open","ping_status":"open","sticky":false,"template":"wp-custom-template-my","format":"standard","meta":{"footnotes":""},"categories":[135,131],"tags":[237,19,698,696,347],"class_list":["post-2358","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-131","tag-linux","tag-19","tag-698","tag-696","tag-347"],"_links":{"self":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/2358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2358"}],"version-history":[{"count":2,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/2358\/revisions"}],"predecessor-version":[{"id":2360,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/2358\/revisions\/2360"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/media\/450"}],"wp:attachment":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}