{"id":3040,"date":"2024-12-02T00:26:30","date_gmt":"2024-12-01T16:26:30","guid":{"rendered":"http:\/\/www.51cos.com\/?p=3040"},"modified":"2025-05-23T18:21:40","modified_gmt":"2025-05-23T10:21:40","slug":"%e4%b8%a4%e5%8f%b0%e8%bf%90%e8%a1%8copenwrt%e8%b7%af%e7%94%b1%e5%99%a8%ef%bc%8c%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%aeadhoc%e6%a8%a1%e5%bc%8f%ef%bc%8c%e5%ae%9e%e7%8e%b0%e4%ba%92%e8%81%94%e4%ba%92","status":"publish","type":"post","link":"http:\/\/www.51cos.com\/?p=3040","title":{"rendered":"\u4e24\u53f0\u8fd0\u884copenwrt\u8def\u7531\u5668\uff0c\u5982\u4f55\u8bbe\u7f6eadhoc\u6a21\u5f0f\uff0c\u5b9e\u73b0\u4e92\u8054\u4e92\u901a"},"content":{"rendered":"<hr \/>\n<p>\u8981\u8ba9\u4e24\u53f0\u8fd0\u884c OpenWrt \u7684\u8def\u7531\u5668\u901a\u8fc7 Ad-Hoc \u6a21\u5f0f\u5b9e\u73b0\u4e92\u8054\u4e92\u901a\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u786e\u4fdd\u65e0\u7ebf\u7f51\u5361\u652f\u6301 Ad-Hoc \u6a21\u5f0f<\/li>\n<\/ol>\n<p>\u5728 OpenWrt \u4e0a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u68c0\u67e5\u65e0\u7ebf\u7f51\u5361\u662f\u5426\u652f\u6301 Ad-Hoc \u6a21\u5f0f\uff1a<\/p>\n<p>iw list<\/p>\n<p>\u5728\u8f93\u51fa\u7684 Supported interface modes \u4e2d\u5bfb\u627e IBSS\uff0c\u5982\u679c\u5b58\u5728\uff0c\u5219\u652f\u6301 Ad-Hoc \u6a21\u5f0f\u3002<\/p>\n<hr \/>\n<ol start=\"2\">\n<li>\u914d\u7f6e\u65e0\u7ebf\u7f51\u7edc\u4e3a Ad-Hoc \u6a21\u5f0f<\/li>\n<\/ol>\n<p>\u5206\u522b\u5728\u4e24\u53f0\u8def\u7531\u5668\u4e0a\u4fee\u6539\u65e0\u7ebf\u914d\u7f6e\u6587\u4ef6 \/etc\/config\/wireless\u3002<\/p>\n<p>\u793a\u4f8b\u914d\u7f6e\uff1a<\/p>\n<p>\u5047\u8bbe\u4e24\u53f0\u8def\u7531\u5668\u9700\u8981\u901a\u8fc7 adhoc \u7f51\u7edc\u4e92\u8054\uff0c\u7f51\u7edc\u540d\u79f0\u4e3a adhoc-network\uff0c\u9891\u7387\u4e3a 2412 MHz (\u4fe1\u9053 1)\uff0c\u52a0\u5bc6\u65b9\u5f0f\u4e3a WPA2\u3002<\/p>\n<p>\u7f16\u8f91 \/etc\/config\/wireless\uff0c\u6dfb\u52a0\u6216\u4fee\u6539\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<p>config wifi-device &#8216;radio0&#8217;<br \/>\n    option type &#8216;mac80211&#8242;<br \/>\n    option hwmode &#8217;11g&#8217;      # \u6216 &#8217;11a&#8217;\uff0c\u6839\u636e\u4f60\u7684\u8bbe\u5907\u652f\u6301\u7684\u9891\u6bb5<br \/>\n    option channel &#8216;1&#8217;       # \u4fe1\u9053\u9700\u4e24\u53f0\u4fdd\u6301\u4e00\u81f4<br \/>\n    option htmode &#8216;HT20&#8217;     # \u6216\u5176\u4ed6\u652f\u6301\u7684\u6a21\u5f0f\uff0c\u5982 VHT80<br \/>\n    option country &#8216;US&#8217;<\/p>\n<p>config wifi-iface<br \/>\n    option device &#8216;radio0&#8217;<br \/>\n    option network &#8216;adhoc&#8217;   # \u7f51\u7edc\u63a5\u53e3\u540d\u79f0<br \/>\n    option mode &#8216;adhoc&#8217;<br \/>\n    option ssid &#8216;adhoc-network&#8217;<br \/>\n    option encryption &#8216;psk2&#8217; # \u8bbe\u7f6e\u52a0\u5bc6\u7c7b\u578b<br \/>\n    option key &#8216;password123&#8217; # \u5bc6\u94a5<\/p>\n<hr \/>\n<ol start=\"3\">\n<li>\u914d\u7f6e\u7f51\u7edc\u63a5\u53e3<\/li>\n<\/ol>\n<p>\u7f16\u8f91 \/etc\/config\/network\uff0c\u4e3a adhoc \u63a5\u53e3\u5206\u914d\u9759\u6001 IP \u5730\u5740\u3002<\/p>\n<p>\u793a\u4f8b\u914d\u7f6e\uff1a<\/p>\n<p>\u5728\u6bcf\u53f0\u8def\u7531\u5668\u4e2d\uff0c\u4e3a Ad-Hoc \u7f51\u7edc\u8bbe\u7f6e\u4e0d\u540c\u7684\u9759\u6001 IP \u5730\u5740\uff0c\u5e76\u786e\u4fdd\u5b83\u4eec\u5728\u540c\u4e00\u7f51\u6bb5\u4e2d\u3002<\/p>\n<p>\u8def\u7531\u5668 1:<\/p>\n<p>config interface &#8216;adhoc&#8217;<br \/>\n    option proto &#8216;static&#8217;<br \/>\n    option ipaddr &#8216;192.168.100.1&#8217;<br \/>\n    option netmask &#8216;255.255.255.0&#8217;<\/p>\n<p>\u8def\u7531\u5668 2:<\/p>\n<p>config interface &#8216;adhoc&#8217;<br \/>\n    option proto &#8216;static&#8217;<br \/>\n    option ipaddr &#8216;192.168.100.2&#8217;<br \/>\n    option netmask &#8216;255.255.255.0&#8217;<\/p>\n<hr \/>\n<ol start=\"4\">\n<li>\u91cd\u542f\u7f51\u7edc\u670d\u52a1<\/li>\n<\/ol>\n<p>\u5728\u4e24\u53f0\u8def\u7531\u5668\u4e0a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>\/etc\/init.d\/network restart<\/p>\n<hr \/>\n<ol start=\"5\">\n<li>\u6d4b\u8bd5\u8fde\u63a5<\/li>\n<\/ol>\n<p>\u5728\u4efb\u610f\u4e00\u53f0\u8def\u7531\u5668\u4e0a\u5c1d\u8bd5 ping \u53e6\u4e00\u53f0\u7684\u9759\u6001 IP \u5730\u5740\uff1a<\/p>\n<p>ping 192.168.100.2  # \u4ece\u8def\u7531\u5668 1 \u6d4b\u8bd5\u5230\u8def\u7531\u5668 2<br \/>\nping 192.168.100.1  # \u4ece\u8def\u7531\u5668 2 \u6d4b\u8bd5\u5230\u8def\u7531\u5668 1<\/p>\n<p>\u5982\u679c\u80fd\u6210\u529f ping \u901a\uff0c\u8bf4\u660e Ad-Hoc \u7f51\u7edc\u5df2\u7ecf\u5efa\u7acb\uff0c\u8def\u7531\u5668\u4e92\u8054\u4e92\u901a\u3002<\/p>\n<hr \/>\n<ol start=\"6\">\n<li>\uff08\u53ef\u9009\uff09\u914d\u7f6e\u8def\u7531<\/li>\n<\/ol>\n<p>\u5982\u679c\u9700\u8981\u8ba9\u5176\u4ed6\u8bbe\u5907\u901a\u8fc7\u8def\u7531\u5668\u8bbf\u95ee Ad-Hoc \u7f51\u7edc\uff0c\u53ef\u4ee5\u914d\u7f6e\u9759\u6001\u8def\u7531\u6216\u542f\u7528 NAT \u8f6c\u53d1\uff0c\u5177\u4f53\u6b65\u9aa4\u6839\u636e\u7f51\u7edc\u9700\u6c42\u8c03\u6574\u3002<\/p>\n<hr \/>\n<p>\u4e3a\u4e86\u8ba9\u4e24\u53f0\u8def\u7531\u5668\u7684 \u7f51\u53e3\uff08LAN\/WAN \u53e3\uff09\u901a\u8fc7 Ad-Hoc \u6a21\u5f0f\u5b9e\u73b0\u4e92\u8054\u4e92\u901a\uff0c\u9700\u8981\u6b63\u786e\u8bbe\u7f6e\u8def\u7531\u548c\u9632\u706b\u5899\u89c4\u5219\uff0c\u4f7f\u4e24\u8fb9\u7684\u7f51\u53e3\u7f51\u7edc\u80fd\u591f\u76f8\u4e92\u8bbf\u95ee\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n<hr \/>\n<p>\u5047\u8bbe\u7f51\u7edc\u62d3\u6251<\/p>\n<p>\u8def\u7531\u5668 A:<\/p>\n<p>LAN \u7f51\u6bb5\uff1a192.168.1.0\/24\uff08IP\uff1a192.168.1.1\uff09<\/p>\n<p>Ad-Hoc IP\uff1a192.168.100.1<\/p>\n<p>\u8def\u7531\u5668 B:<\/p>\n<p>LAN \u7f51\u6bb5\uff1a192.168.2.0\/24\uff08IP\uff1a192.168.2.1\uff09<\/p>\n<p>Ad-Hoc IP\uff1a192.168.100.2<\/p>\n<hr \/>\n<ol>\n<li>\u914d\u7f6e Ad-Hoc \u7f51\u7edc\u7684\u9759\u6001\u8def\u7531<\/li>\n<\/ol>\n<p>\u4e3a\u4e86\u8ba9\u4e24\u53f0\u8def\u7531\u5668\u7684 LAN \u7f51\u6bb5\u53ef\u4ee5\u901a\u8fc7 Ad-Hoc \u7f51\u7edc\u8bbf\u95ee\u5bf9\u65b9\uff0c\u5fc5\u987b\u5728\u4e24\u8fb9\u5206\u522b\u6dfb\u52a0\u9759\u6001\u8def\u7531\u3002<\/p>\n<p>\u5728\u8def\u7531\u5668 A \u4e0a\uff1a<\/p>\n<p>\u544a\u8bc9\u8def\u7531\u5668 A\uff0c\u5982\u4f55\u901a\u8fc7 Ad-Hoc \u7f51\u7edc\u8bbf\u95ee\u8def\u7531\u5668 B \u7684 LAN \u7f51\u6bb5\uff1a<\/p>\n<p>uci add network route<br \/>\nuci set network.@route[-1].interface=&#8217;adhoc&#8217;<br \/>\nuci set network.@route[-1].target=&#8217;192.168.2.0&#8242;<br \/>\nuci set network.@route[-1].netmask=&#8217;255.255.255.0&#8242;<br \/>\nuci set network.@route[-1].gateway=&#8217;192.168.100.2&#8242;<br \/>\nuci commit network<br \/>\n\/etc\/init.d\/network restart<\/p>\n<p>\u5728\u8def\u7531\u5668 B \u4e0a\uff1a<\/p>\n<p>\u544a\u8bc9\u8def\u7531\u5668 B\uff0c\u5982\u4f55\u901a\u8fc7 Ad-Hoc \u7f51\u7edc\u8bbf\u95ee\u8def\u7531\u5668 A \u7684 LAN \u7f51\u6bb5\uff1a<\/p>\n<p>uci add network route<br \/>\nuci set network.@route[-1].interface=&#8217;adhoc&#8217;<br \/>\nuci set network.@route[-1].target=&#8217;192.168.1.0&#8242;<br \/>\nuci set network.@route[-1].netmask=&#8217;255.255.255.0&#8242;<br \/>\nuci set network.@route[-1].gateway=&#8217;192.168.100.1&#8242;<br \/>\nuci commit network<br \/>\n\/etc\/init.d\/network restart<\/p>\n<hr \/>\n<ol start=\"2\">\n<li>\u4fee\u6539\u9632\u706b\u5899\u89c4\u5219<\/li>\n<\/ol>\n<p>\u786e\u4fdd Ad-Hoc \u7f51\u7edc\u548c LAN \u7f51\u7edc\u4e4b\u95f4\u5141\u8bb8\u76f8\u4e92\u8bbf\u95ee\u3002<\/p>\n<p>\u5728\u8def\u7531\u5668 A \u4e0a\uff1a<\/p>\n<p>\u7f16\u8f91 \/etc\/config\/firewall\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u89c4\u5219\uff1a<\/p>\n<p>config rule<br \/>\n    option name &#8216;Allow-LAN-to-Adhoc&#8217;<br \/>\n    option src &#8216;lan&#8217;<br \/>\n    option dest &#8216;adhoc&#8217;<br \/>\n    option target &#8216;ACCEPT&#8217;<\/p>\n<p>config rule<br \/>\n    option name &#8216;Allow-Adhoc-to-LAN&#8217;<br \/>\n    option src &#8216;adhoc&#8217;<br \/>\n    option dest &#8216;lan&#8217;<br \/>\n    option target &#8216;ACCEPT&#8217;<\/p>\n<p>\u5728\u8def\u7531\u5668 B \u4e0a\uff1a<\/p>\n<p>\u7c7b\u4f3c\u5730\uff0c\u7f16\u8f91 \/etc\/config\/firewall\uff0c\u6dfb\u52a0\uff1a<\/p>\n<p>config rule<br \/>\n    option name &#8216;Allow-LAN-to-Adhoc&#8217;<br \/>\n    option src &#8216;lan&#8217;<br \/>\n    option dest &#8216;adhoc&#8217;<br \/>\n    option target &#8216;ACCEPT&#8217;<\/p>\n<p>config rule<br \/>\n    option name &#8216;Allow-Adhoc-to-LAN&#8217;<br \/>\n    option src &#8216;adhoc&#8217;<br \/>\n    option dest &#8216;lan&#8217;<br \/>\n    option target &#8216;ACCEPT&#8217;<\/p>\n<p>\u5e94\u7528\u9632\u706b\u5899\u914d\u7f6e\uff1a<\/p>\n<p>\u5728\u4e24\u53f0\u8def\u7531\u5668\u4e0a\u8fd0\u884c\uff1a<\/p>\n<p>\/etc\/init.d\/firewall restart<\/p>\n<hr \/>\n<ol start=\"3\">\n<li>\u6d4b\u8bd5\u4e92\u8054<\/li>\n<\/ol>\n<p>\u6d4b\u8bd5 LAN \u5230 LAN \u901a\u4fe1\uff1a \u4ece\u8def\u7531\u5668 A \u7684 LAN \u7f51\u6bb5\u4e2d\u7684\u8bbe\u5907\u5c1d\u8bd5\u8bbf\u95ee\u8def\u7531\u5668 B \u7684 LAN \u7f51\u6bb5\u4e2d\u7684\u8bbe\u5907\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>ping 192.168.2.100  # \u6d4b\u8bd5 B \u7684\u8bbe\u5907<\/p>\n<p>\u6d4b\u8bd5\u8def\u7531\u5668\u4e4b\u95f4\u4e92\u901a\uff1a \u6d4b\u8bd5\u4ece\u8def\u7531\u5668 A \u5230\u8def\u7531\u5668 B \u7684 LAN IP \u5730\u5740\uff1a<\/p>\n<p>ping 192.168.2.1<\/p>\n<hr \/>\n<ol start=\"4\">\n<li>\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/li>\n<li>\n<p>IP \u5730\u5740\u89c4\u5212\uff1a\u786e\u4fdd\u4e24\u53f0\u8def\u7531\u5668\u7684 LAN \u7f51\u6bb5\u4e0d\u51b2\u7a81\u3002<\/p>\n<\/li>\n<li>\n<p>\u5e7f\u64ad\u548c\u670d\u52a1\uff1a\u5982\u679c\u9700\u8981\u8de8\u7f51\u6bb5\u8bbf\u95ee\u5e7f\u64ad\u670d\u52a1\uff08\u5982\u5171\u4eab\u6253\u5370\u673a\u3001DLNA\uff09\uff0c\u53ef\u80fd\u9700\u8981\u914d\u7f6e IGMP Proxy \u6216 mDNS \u4e2d\u7ee7\u3002<\/p>\n<\/li>\n<li>\n<p>\u6027\u80fd\u8c03\u4f18\uff1aAd-Hoc \u7f51\u7edc\u6027\u80fd\u8f83\u4f4e\uff0c\u5efa\u8bae\u6839\u636e\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u4fe1\u9053\u548c\u9891\u5bbd\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u914d\u7f6e\uff0c\u4e24\u53f0\u8def\u7531\u5668\u7684 LAN \u7f51\u6bb5\u53ef\u4ee5\u901a\u8fc7 Ad-Hoc \u7f51\u7edc\u5b9e\u73b0\u4e92\u8054\u4e92\u901a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u8ba9\u4e24\u53f0\u8fd0\u884c OpenWrt \u7684\u8def\u7531\u5668\u901a\u8fc7 Ad-Hoc \u6a21\u5f0f\u5b9e\u73b0\u4e92\u8054\u4e92\u901a\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a \u786e\u4fdd\u65e0\u7ebf\u7f51 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-3040","post","type-post","status-publish","format-standard","hentry","category-plana"],"_links":{"self":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/3040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3040"}],"version-history":[{"count":2,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/3040\/revisions"}],"predecessor-version":[{"id":3044,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/3040\/revisions\/3044"}],"wp:attachment":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3040"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}