﻿{"id":1487,"date":"2023-09-05T19:52:13","date_gmt":"2023-09-05T11:52:13","guid":{"rendered":"http:\/\/blog.sway.com.cn\/?p=1487"},"modified":"2023-09-05T20:01:23","modified_gmt":"2023-09-05T12:01:23","slug":"%e6%a0%91%e8%8e%93%e6%b4%be4b%e4%bd%bf%e5%bc%80%e6%94%be%e7%83%ad%e7%82%b9%e5%85%b1%e4%ba%ab%e7%89%a9%e8%81%94%e7%bd%914g%e6%a8%a1%e5%9d%97%e7%9a%84%e7%bd%91%e7%bb%9c","status":"publish","type":"post","link":"http:\/\/blog.sway.com.cn\/?p=1487","title":{"rendered":"\u6811\u8393\u6d3e4B\u4f7f\u5f00\u653e\u70ed\u70b9\u5171\u4eab\u7269\u8054\u7f514G\u6a21\u5757\u7684\u7f51\u7edc"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u7b2c\u4e00\u6b65\uff1ahostapd<\/h2>\n\n\n\n<p>\u5b89\u88c5hostapd<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install hostapd\nsudo systemctl stop hostapd<\/pre>\n\n\n\n<p>\u7f16\u8f91\u201c\/etc\/hostapd\/hostapd.conf\u201d\u6587\u4ef6\uff08\u82e5\u65e0\uff0c\u5219\u521b\u5efa\uff09\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">interface=wlan0\ndriver=nl80211\nssid=raspberry_hotspot\nhw_mode=g\nchannel=7\nwmm_enabled=0\nmacaddr_acl=0\nauth_algs=1\nignore_broadcast_ssid=0\nwpa=2\nwpa_passphrase=12345678\nwpa_key_mgmt=WPA-PSK\nwpa_pairwise=TKIP\nrsn_pairwise=CCMP<\/pre>\n\n\n\n<p>\u542f\u52a8\u670d\u52a1\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl unmask hostapd\nsudo systemctl enable hostapd\nsudo systemctl start hostapd<\/pre>\n\n\n\n<p>\u8fc7\u4e00\u4f1a\uff0c\u5c31\u80fd\u5728\u5176\u4ed6\u79fb\u52a8\u8bbe\u5907\u4e2d\u641c\u7d22\u5230\u8be5\u70ed\u70b9\u4e86\uff0c\u53ea\u662f\u6b64\u65f6\u80fd\u8fde\u63a5\u8be5\u70ed\u70b9\uff0c\u4f46\u662f\u8fd8\u4e0d\u80fd\u4e0a\u7f51\uff0c\u56e0\u4e3a\u76f8\u5173\u7684dns\u8bbe\u7f6e\u6ca1\u6709\u914d\u597d\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u5982\u679c\u670d\u52a1\u542f\u52a8\u5931\u8d25\uff0c\u6bd4\u5982\u62a5\u9519 \"systemctl status hostapd.service\" and \"journalctl -xe\" for details \u7b49\uff0c\u53ef\u4ee5\u6309\u5982\u4e0b\u6b65\u9aa4\u9010\u4e00\u6392\u67e5\uff1a 1. \u91cd\u542f\u6811\u8393\u6d3e\uff0c\u518d\u5c1d\u8bd5\u542f\u52a8 hostapd 2. \u547d\u4ee4\u884c\u6267\u884c sudo \/usr\/sbin\/hostapd \/etc\/hostapd\/hostapd.conf\uff0c\u76f4\u63a5\u8fd0\u884c hostapd\uff0c\u89c2\u5bdf\u8f93\u51fa\u65e5\u5fd7\uff0c\u4e00\u822c\u90fd\u80fd\u53d1\u73b0\u95ee\u9898\u3002\u6bd4\u5982\u5e38\u89c1\u7684\uff1a 1. hostapd.conf \u914d\u7f6e\u9519\u8bef\u5bfc\u81f4\u542f\u52a8\u5931\u8d25\u3002\u68c0\u67e5\u914d\u7f6e\u6587\u4ef6\uff0c\u4fee\u6539\u540e\uff0c\u65b0\u542f\u52a8 hostapd \u5373\u53ef\u3002 2. wlan0 \u7aef\u53e3\u672a\u5f00\u542f\u5bfc\u81f4\u542f\u52a8\u5931\u8d25\u3002\u6267\u884c sudo ifconfig wlan0 up \u5f00\u542f\u7aef\u53e3\u540e\uff0c\u91cd\u65b0\u542f\u52a8 hostapd \u5373\u53ef\u3002<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u4e8c\u6b65\uff1a\u914d\u7f6edhcp<\/h2>\n\n\n\n<p>\u7f16\u8f91\u201c\/etc\/dhcpcd.conf\u201d\uff0c\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">interface wlan0\n    static ip_address=192.168.4.1\/24\n    nohook wpa_supplicant<\/pre>\n\n\n\n<p>\u610f\u601d\u662f\u5c06\u6811\u8393\u6d3e\u7684\u5730\u5740\u8bbe\u7f6e\u4e3a192.168.4.1\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"469\" height=\"186\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image.png\" alt=\"\" class=\"wp-image-1488\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image.png 469w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-300x119.png 300w\" sizes=\"auto, (max-width: 469px) 100vw, 469px\" \/><\/a><\/figure>\n\n\n\n<p>\u63a5\u7740\u91cd\u542fdhcpcd\u670d\u52a1\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl restart dhcpcd<\/pre>\n\n\n\n<p>\u7136\u540e\u6267\u884c\u201cifconfig\u201d\u547d\u4ee4\uff0c\u4fbf\u53ef\u4ee5\u770b\u5230wlan0\u7684\u5730\u5740\u4e3a192.168.4.1\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"199\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-1.png\" alt=\"\" class=\"wp-image-1489\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-1.png 786w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-1-300x76.png 300w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-1-768x194.png 768w\" sizes=\"auto, (max-width: 786px) 100vw, 786px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u4e09\u6b65\uff1adnsmasq<\/h2>\n\n\n\n<p>dnsmasq \u662f\u4e00\u4e2a\u5c0f\u578b\u7684\u7528\u4e8e\u914d\u7f6e DNS \u548c DHCP \u7684\u5de5\u5177\uff0c\u9002\u7528\u4e8e\u5c0f\u578b\u7f51\u7edc\uff0c\u5b83\u63d0\u4f9b\u4e86 DNS \u548c DHCP \u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u5b89\u88c5dnsmasq\u670d\u52a1\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install dnsmasq\nsudo systemctl stop dnsmasq<\/pre>\n\n\n\n<p>\u7f16\u8f91\u201c\/etc\/dnsmasq.conf\u201d\u6587\u4ef6\uff08\u82e5\u65e0\u6b64\u6587\u4ef6\u5219\u65b0\u5efa\u5373\u53ef\uff09\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">interface=wlan0\ndhcp-range=192.168.4.20,192.168.4.50,255.255.255.0,24h\nserver=8.8.8.8\nserver=8.8.4.4<\/pre>\n\n\n\n<p>dhcp-range \u914d\u7f6e\u9879\u7684\u610f\u601d\u662f\uff0cdhcp \u670d\u52a1\u4f1a\u7ed9\u5ba2\u6237\u7aef\u5206\u914d 192.168.4.20 \u5230 192.168.4.50 \u7684 IP \u7a7a\u95f4\uff0c24 \u5c0f\u65f6\u79df\u671f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"565\" height=\"86\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-2.png\" alt=\"\" class=\"wp-image-1490\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-2.png 565w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-2-300x46.png 300w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/a><\/figure>\n\n\n\n<p>\u7136\u540e\u91cd\u542f dnsmasq \u670d\u52a1\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl reload dnsmasq<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u56db\u6b65\uff1a\u914d\u7f6eiptables\u8f6c\u53d1<\/h2>\n\n\n\n<p>\u5f00\u542f Linux \u5185\u6838\u7684 ip \u8f6c\u53d1\u529f\u80fd\uff0c\u7f16\u8f91\u201c\/etc\/sysctl.conf\u201d\u7cfb\u7edf\u914d\u7f6e\u6587\u4ef6\uff0c\u53bb\u6389 net.ipv4.ip_forward=1 \u8fd9\u4e2a\u914d\u7f6e\u9879\u7684\u6ce8\u91ca\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-5.png\"><img loading=\"lazy\" decoding=\"async\" width=\"845\" height=\"649\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-5.png\" alt=\"\" class=\"wp-image-1494\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-5.png 845w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-5-300x230.png 300w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-5-768x590.png 768w\" sizes=\"auto, (max-width: 845px) 100vw, 845px\" \/><\/a><\/figure>\n\n\n\n<p>\u6dfb\u52a0\u8def\u7531\u8f6c\u53d1\u89c4\u5219\uff08\u6ce8\u610f\uff1aeth0\u4e3a\u7f51\u7ebf\u53e3\uff0c\u9700\u8981\u89c6\u60c5\u51b5\u66f4\u6362\u6210\u8bbf\u95ee\u7f51\u7edc\u7684\u7aef\u53e3\uff0c\u5982\u201cusb0\u201d\uff09\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo iptables -t nat -A  POSTROUTING -o eth0 -j MASQUERADE\nsudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT\nsudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT<\/pre>\n\n\n\n<p>\u8bbe\u7f6e\u5f00\u673a\u65f6\u81ea\u52a8\u5bfc\u5165\u9632\u706b\u5899\u89c4\u5219\uff08\u5c06\u521a\u521a\u8bbe\u7f6e\u7684\u8fd9\u4e9b\u89c4\u5219\u5e94\u7528\u4e8e\u6211\u4eec\u7684\u6bcf\u4e00\u6b21\u542f\u52a8\uff09\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo sh -c \"iptables-save > \/etc\/iptables.ipv4.nat\"<\/pre>\n\n\n\n<p>\u7f16\u8f91\u201c\/etc\/rc.local\u201d\uff0c\u628a\u201ciptables-restore &lt; \/etc\/iptables.ipv4.nat\u201d\u52a0\u5230\u6700\u540e\u4e00\u884c\u201cexit 0\u201d\u7684\u524d\u9762\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"753\" height=\"515\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-3.png\" alt=\"\" class=\"wp-image-1491\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-3.png 753w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-3-300x205.png 300w\" sizes=\"auto, (max-width: 753px) 100vw, 753px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u4e94\u6b65\uff1a\u91cd\u542f\u6811\u8393\u6d3e<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo reboot<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"828\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-4-1024x828.png\" alt=\"\" class=\"wp-image-1492\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-4-1024x828.png 1024w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-4-300x243.png 300w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-4-768x621.png 768w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/09\/image-4.png 1081w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u5176\u4ed6<\/h2>\n\n\n\n<p>\u82e5dnsmasq\u7ecf\u5e38\u4f1a\u51fa\u73b0\u95ee\u9898\uff0c\u539f\u56e0\u53ef\u80fd\u662fwlan0\u8fd8\u6ca1\u70ed\u542f\u52a8\u5b8c\u6210\uff0c\u800cdnsmasq\u5c31\u5148\u542f\u52a8\u4e86\uff0c\u6240\u4ee5\u51fa\u73b0\u4e86\u542f\u52a8\u5931\u8d25\u7684\u73b0\u8c61\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u64cd\u4f5c\uff08\u672a\u9a8c\u8bc1\uff09\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u6253\u5f00\u7ba1\u7406\u542f\u52a8\nsudo vim \/etc\/rc.local\n\/\/ \u6dfb\u52a0\u5982\u4e0b\u884c\uff0c\u5728 exit 0 \u4e4b\u524d\nsudo bash \/etc\/dnsmasq_delayinit.sh\n\/\/ \u7136\u540e\u7f16\u8f91dnsmasq_delayinit.sh\nsudo vim \/etc\/dnsmasq_delayinit.sh\n#!\/bin\/sh\nsleep 10\nsudo service dnsmasq restart\n\/\/ \u518d\u8bbe\u7f6e\u6210\u53ef\u6267\u884c\nsudo chmod +x \/etc\/dnsmasq_delayinit.sh<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u4e00\u6b65\uff1ahostapd \u5b89\u88c5hostapd \u7f16\u8f91\u201c\/etc\/hostapd\/hostapd.conf\u201d\u6587\u4ef6\uff08\u82e5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1487","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1487"}],"version-history":[{"count":4,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1487\/revisions"}],"predecessor-version":[{"id":1497,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1487\/revisions\/1497"}],"wp:attachment":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1487"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}