{"id":56,"date":"2024-09-08T15:57:48","date_gmt":"2024-09-08T07:57:48","guid":{"rendered":"https:\/\/blog.62510360.xyz\/?p=56"},"modified":"2024-09-08T16:01:31","modified_gmt":"2024-09-08T08:01:31","slug":"%e9%85%8d%e7%bd%aedocker-openwrt%e4%b8%8e%e5%ae%bf%e4%b8%bb%e6%9c%ba%e7%bd%91%e7%bb%9c%e4%ba%92%e9%80%9a%e4%b8%94%e4%bd%9c%e4%b8%ba%e5%ae%bf%e4%b8%bb%e6%9c%ba%e7%bd%91%e5%85%b3","status":"publish","type":"post","link":"https:\/\/blog.62510360.xyz\/?p=56","title":{"rendered":"\u914d\u7f6eDocker OpenWrt\u4e0e\u5bbf\u4e3b\u673a\u7f51\u7edc\u4e92\u901a\u4e14\u4f5c\u4e3a\u5bbf\u4e3b\u673a\u7f51\u5173"},"content":{"rendered":"\n<p>\u80cc\u666f<br>\u6700\u8fd1\u9700\u8981\u7528Docker\u7248\u7684Openwrt\u4f5c\u4e3a\u65c1\u8def\u7531\uff08\u7f51\u5173\uff09\uff0c\u5728\u914d\u7f6e\u8fc7\u7a0b\u4e2d\u9047\u5230\u4e00\u4e9b\u95ee\u9898\uff0c\u901a\u8fc7\u67e5\u9605\u8d44\u6599\uff0c\u6700\u7ec8\u5b8c\u7f8e\u89e3\u51b3\u3002\u73b0\u5728\u5c06\u6574\u4f53\u65b9\u6848\u548c\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u8d34\u5230\u8fd9\u91cc\u5206\u4eab\u7ed9\u5927\u5bb6<\/p>\n\n\n\n<p>\u73af\u5883<br>\u8fd9\u91cc\u6211\u4f7f\u7528\u7684\u73af\u5883\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u5bbf\u4e3b\u673a\u64cd\u4f5c\u7cfb\u7edf\uff1aArmbian<br>\u5bbf\u4e3b\u673aip\uff1a192.168.5.2<br>\u5bbf\u4e3b\u673a\u65b0macvlan\u63a5\u53e3ip\uff1a192.168.5.3<br>Docker\u955c\u50cf\uff1aunifreq\/openwrt-aarch64<br>Docker ip\uff08macvlan\uff09\uff1a192.168.5.10<br>\u7f51\u6bb5\uff1a192.168.5.0\/24<br>\u4e3b\u8def\u7531ip\uff1a192.168.5.1<br>\u64cd\u4f5c\u6b65\u9aa4<br>Docker\u5b89\u88c5OpenWrt<br>\u8fd9\u91cc\u6211\u4f7f\u7528docker macvlan\u7684bridge\u7f51\u7edc\u6a21\u5f0f\u63d0\u5347\u6027\u80fd<\/p>\n\n\n\n<p class=\"has-small-font-size\">\u786e\u8ba4\u5bbf\u4e3b\u673a\u7f51\u7edc\u63a5\u53e3\u540d<br>1.ifconfig<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u5f00\u542f\u6865\u63a5\u7f51\u5361\u7684\u6df7\u6dc6\u6a21\u5f0f<\/h5>\n\n\n\n<p>\u5728\u5bbf\u4e3b\u673a\u8f93\u5165\u4e0b\u9762\u547d\u4ee4<\/p>\n\n\n\n<p class=\"has-small-font-size\">ip link set eth0 promisc on<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u518d\u4e00\u6b21ifconfig\u63a5\u53e3\u540d\u67e5\u770b\u662f\u5426\u6210\u529f\u5f00\u542f\u3002\u5982\u679c\u5bf9\u5e94\u63a5\u53e3\u6709PROMISC\u8bc1\u660e\u5df2\u6210\u529f\u5f00\u542f<\/p>\n\n\n\n<p>\u4e3adocker\u521b\u5efamacvlan\u7f51\u7edc<\/p>\n\n\n\n<p class=\"has-small-font-size\">docker network create -d macvlan &#8211;subnet=192.168.5.0\/24 &#8211;gateway=192.168.5.1 -o parent=eth0 macnet<\/p>\n\n\n\n<p>\u521b\u5efaOpenWrt\u5bb9\u5668\u5728\u5bbf\u4e3b\u673a\u6267\u884c<\/p>\n\n\n\n<p class=\"has-small-font-size\">docker run &#8211;restart always &#8211;name openwrt -d &#8211;network macnet &#8211;privileged unifreq\/openwrt-aarch64:latest \/sbin\/init<\/p>\n\n\n\n<p>\u767b\u5f55\u5bb9\u5668\u66f4\u6539ip\u7f51\u6bb5,\u5bbf\u4e3b\u673a\u6267\u884c\u4e0b\u9762\u547d\u4ee4\u8fdb\u5165\u5bb9\u5668\u7ec8\u7aef<\/p>\n\n\n\n<p>docker exec -it openwrt bash<\/p>\n\n\n\n<p>\u5728\u5bb9\u5668\u7ec8\u7aef\u4e0b\uff0c\u4fee\u6539\/etc\/config\/network\u6587\u4ef6\uff0c\u4fee\u6539ipaddr\u4e3a\u5bbf\u4e3b\u673a\u7f51\u6bb5\uff0c\u5e76\u589e\u52a0gateway\u548cdns\u914d\u7f6e\uff0c\u6307\u5411\u4e3b\u8def\u7531\u5730\u5740\uff0c\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>config interface 'lan'\n\t\toption type 'bridge'\n        option ifname 'eth0'\n        option proto 'static'\n        option ipaddr '192.168.5.10'\n        option dns '192.168.5.1'\n        option gateway '192.168.5.1'\n        option netmask '255.255.255.0'\n<\/code><\/pre>\n\n\n\n<p>\u91cd\u542fnetwork\u751f\u6548\u914d\u7f6e,\u5bb9\u5668\u4e0b\u6267\u884c\uff0c<\/p>\n\n\n\n<p>\/etc\/init.d\/network restart<\/p>\n\n\n\n<p>\u4e0e\u5bbf\u4e3b\u673a\u7f51\u7edc\u4e92\u901a<br>\u5728\u7528\u4e0a\u8ff0\u914d\u7f6e\u521b\u5efa\u5b8cOpenWrt docker\u540e\uff0c\u867d\u7136\u5bbf\u4e3b\u673a\u548c\u5bb9\u5668\u5728\u540c\u4e00\u7f51\u6bb5\uff0c\u4f46\u662f\u56e0\u4e3amacvlan\u6a21\u5f0f\u7684\u9650\u5236\uff0c\u5bbf\u4e3b\u673a\u4e0e\u5bb9\u5668\u662f\u65e0\u6cd5\u4e92\u76f8\u901a\u4fe1\u7684\uff08\u4f46\u4e0e\u540c\u7f51\u6bb5\u4e0b\u7684\u5176\u4ed6\u673a\u5668\u662f\u53ef\u4ee5\u76f8\u4e92\u901a\u4fe1\u7684\uff09\uff0c\u6240\u4ee5\u9700\u8981\u5728\u5bbf\u4e3b\u673a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684macvlan\u63a5\u53e3\uff0c\u7136\u540e\u589e\u52a0\u4e00\u6761\u5bbf\u4e3b\u673amacvlan\u8bbf\u95ee\u5bb9\u5668macvlan\u7684\u9759\u6001\u8def\u7531\u3002<\/p>\n\n\n\n<p>\u5728\u5bbf\u4e3b\u673a\u7ec8\u7aef\u6267\u884c\u4e0b\u9762\u4ee3\u7801\uff0c<br>\u6ce8\uff1amacvlan-proxy\u8fd9\u4e2a\u63a5\u53e3\u540d\u79f0\u53ef\u4ee5\u968f\u4fbf\u8d77\uff0c\u53ea\u9700\u8981\u6bcf\u6761\u547d\u4ee4\u7684\u540d\u5b57\u4fdd\u6301\u4e00\u81f4\u5373\u53ef<\/p>\n\n\n\n<p>\u5bbf\u4e3b\u673a\u521b\u5efa\u65b0\u7684macvlan\u63a5\u53e3<\/p>\n\n\n\n<p>ip link add macvlan-proxy link eth0 type macvlan mode bridge<br><\/p>\n\n\n\n<p>\u4e3a\u65b0\u63a5\u53e3\u5206\u914dip\u5e76\u542f\u7528<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ip addr add 192.168.5.3 dev macvlan-proxy\nip link set macvlan-proxy up<\/code><\/pre>\n\n\n\n<p>\u6dfb\u52a0\u9759\u6001\u8def\u7531\u4f7f\u5bbf\u4e3b\u673a\u4e0e\u5bb9\u5668\u4f7f\u7528\u65b0\u63a5\u53e3\u901a\u4fe1<\/p>\n\n\n\n<p>ip route add 192.168.5.10 dev macvlan-proxy<\/p>\n\n\n\n<p>\u914d\u7f6e\u65b0\u63a5\u53e3\u7684\u9ed8\u8ba4\u7f51\u5173\u4e3a\u5bb9\u5668\u5730\u5740<\/p>\n\n\n\n<p>route add default gw 192.168.5.10 macvlan-proxy<\/p>\n\n\n\n<p>\u5982\u679c\u53ef\u4ee5\u76f8\u4e92ping\u901a\uff0c\u5219\u8bc1\u660e\u8bbe\u7f6e\u6ca1\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u52a0\u5165\u542f\u52a8\u9879\u81ea\u542f\u52a8<br>\u4e0a\u8ff0\u547d\u4ee4\u4f1a\u5728\u5bbf\u4e3b\u673a\u91cd\u542f\u540e\u5931\u6548\uff0c\u4e3a\u4e86\u6bcf\u6b21\u91cd\u542f\u5bbf\u4e3b\u673a\u5747\u53ef\u81ea\u52a8\u8fd0\u884c\u4e0a\u8ff0\u547d\u4ee4\uff0c\u9700\u8981\u7f16\u8f91\/etc\/rc.local\u6587\u4ef6\uff0c\u5c06\u4e0a\u9762\u7684\u547d\u4ee4\u7c98\u8d34\u5230exit 0\u4e4b\u524d<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>ip link set eth0 promisc on > \/dev\/null 2>&amp;1\nip link add macvlan-proxy link eth0 type macvlan mode bridge\nip addr add 192.168.5.3 dev macvlan-proxy\nip link set macvlan-proxy up\nip route add 192.168.5.10 dev macvlan-proxy\nroute add default gw 192.168.5.10 macvlan-proxy<\/code><\/pre>\n\n\n\n<p>\u6700\u540e\uff0c\u786e\u4fdd\u4e3a\/etc\/rc.local\u6587\u4ef6\u589e\u52a0\u4e86\u53ef\u6267\u884c\u6743\u9650\u4e14rc-local.service\u662f\u81ea\u542f\u52a8\u7684\u72b6\u6001<\/p>\n\n\n\n<p>chmod a+x \/etc\/rc.local<br>systemctl enable rc-local<\/p>\n\n\n\n<p>\u81f3\u6b64\uff0cDocker OpenWrt\u4e0e\u5bbf\u4e3b\u673a\u7f51\u7edc\u4e92\u901a\u914d\u7f6e\u5df2\u5b8c\u6210\uff0c\u53ef\u91cd\u542f\u540e\u9a8c\u8bc1\u662f\u5426\u751f\u6548\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f\u6700\u8fd1\u9700\u8981\u7528Docker\u7248\u7684Openwrt\u4f5c\u4e3a\u65c1\u8def\u7531\uff08\u7f51\u5173\uff09\uff0c\u5728\u914d\u7f6e\u8fc7\u7a0b\u4e2d\u9047\u5230\u4e00\u4e9b\u95ee\u9898\uff0c\u901a\u8fc7\u67e5\u9605\u8d44\u6599\uff0c\u6700\u7ec8\u5b8c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-56","post","type-post","status-publish","format-standard","hentry","category-wlzy"],"_links":{"self":[{"href":"https:\/\/blog.62510360.xyz\/index.php?rest_route=\/wp\/v2\/posts\/56","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.62510360.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.62510360.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.62510360.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.62510360.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=56"}],"version-history":[{"count":3,"href":"https:\/\/blog.62510360.xyz\/index.php?rest_route=\/wp\/v2\/posts\/56\/revisions"}],"predecessor-version":[{"id":59,"href":"https:\/\/blog.62510360.xyz\/index.php?rest_route=\/wp\/v2\/posts\/56\/revisions\/59"}],"wp:attachment":[{"href":"https:\/\/blog.62510360.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.62510360.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.62510360.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}