{"id":701,"date":"2020-01-19T15:17:56","date_gmt":"2020-01-19T07:17:56","guid":{"rendered":"http:\/\/www.x1985.org\/?p=701"},"modified":"2020-01-19T15:17:56","modified_gmt":"2020-01-19T07:17:56","slug":"%e2%99%9e%e6%a0%91%e8%8e%93%e6%b4%be%e4%b9%8bwifi%e7%83%ad%e7%82%b9%e5%bc%80%e5%90%af","status":"publish","type":"post","link":"http:\/\/www.x1985.org\/?p=701","title":{"rendered":"\u265e\u6811\u8393\u6d3e\u4e4bWIFI\u70ed\u70b9\u5f00\u542f"},"content":{"rendered":"<h4>\u2116 1 \u4fee\u6539\u786c\u4ef6\u914d\u7f6e<\/h4>\n<pre title=\"sudo nano \/etc\/network\/interfaces\" class=\"lang:sh decode:true\"># interfaces(5) file used by ifup(8) and ifdown(8)\r\n\r\n# Please note that this file is written to be used with dhcpcd\r\n# For static IP, consult \/etc\/dhcpcd.conf and 'man dhcpcd.conf'\r\n\r\n# Include files from \/etc\/network\/interfaces.d:\r\nsource-directory \/etc\/network\/interfaces.d\r\n\r\nauto eth0\r\n#\u8bbe\u7f6eeth0\u4e3adhcp\u81ea\u52a8\u83b7\u53d6IP\u5730\u5740\r\niface eth0 inet dhcp\r\n\r\nauto wlan0\r\n#\u8bbe\u7f6ewlan0\u4e3a\u6307\u5b9aIP\u5730\u5740\r\niface wlan0 inet static\r\n#\u8bbe\u7f6ewlan0\u7684IP\u5730\u5740(WIFI\u70ed\u70b9\u8981\u4f7f\u7528\u7684\u7f51\u6bb5)\r\naddress 192.168.66.1\r\n#\u8bbe\u7f6ewlan0\u7684\u5b50\u7f51\u63a9\u7801\r\nnetmask 255.255.255.0\r\n#\u8bbe\u7f6ewlan0\u7684\u7f51\u5173\u5730\u5740(\u4e0e\u4e0a\u9762\u7684address\u76f8\u5173\u5c31\u884c)\r\ngateway 192.168.66.1<\/pre>\n<p><strong>\u2116 2 \u5b89\u88c5\u8f6f\u4ef6<\/strong><\/p>\n<pre title=\"\u547d\u4ee4\u884c\u6267\u884c\" class=\"lang:sh decode:true \">#\u5b89\u88c5AP\u7a0b\u5e8f\r\nsudo apt install hostapd\r\n#\u5b89\u88c5DHCP\u670d\u52a1\u8f6f\u4ef6\r\nsudo apt install udhcpd\r\n<\/pre>\n<p><strong>\u2116 3 \u8f6f\u4ef6\u914d\u7f6e\u4e4bhostapd<\/strong><\/p>\n<pre title=\"sudo nano \/etc\/default\/hostapd\" class=\"lang:sh decode:true\"> Defaults for hostapd initscript\r\n#\r\n# WARNING: The DAEMON_CONF setting has been deprecated and will be removed\r\n#          in future package releases.\r\n#\r\n# See \/usr\/share\/doc\/hostapd\/README.Debian for information about alternative\r\n# methods of managing hostapd.\r\n#\r\n# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration\r\n# file and hostapd will be started during system boot. An example configuration\r\n# file can be found at \/usr\/share\/doc\/hostapd\/examples\/hostapd.conf.gz\r\n#\r\n#DAEMON_CONF=\"\"\r\n\r\n# Additional daemon options to be appended to hostapd command:-\r\n#       -d   show more debug messages (-dd for even more)\r\n#       -K   include key data in debug messages\r\n#       -t   include timestamps in some debug messages\r\n#\r\n# Note that -B (daemon mode) and -P (pidfile) options are automatically\r\n# configured by the init.d script and must not be added to DAEMON_OPTS.\r\n#\r\n#DAEMON_OPTS=\"\"\r\n#\u5c06#DAEMON_CONF=\"\"\u4fee\u6539\u4e3aDAEMON_CONF=\"\/etc\/hostapd\/hostapd.conf\"\r\nDAEMON_CONF=\"\/etc\/hostapd\/hostapd.conf\"<\/pre>\n<pre title=\"sudo nano \/etc\/hostapd\/hostapd.conf\" class=\"lang:sh decode:true\">interface=wlan0\r\nssid=\u70ed\u70b9\u540d\u79f0\r\nchannel=7\r\nmacaddr_acl=0\r\nauth_algs=1\r\nignore_broadcast_ssid=0\r\nwpa=2\r\nwpa_passphrase=\u70ed\u70b9\u5bc6\u7801\r\nwpa_key_mgmt=WPA-PSK\r\nrsn_pairwise=CCMP\r\nieee80211n=1\r\nhw_mode=g\r\nwmm_enabled=1<\/pre>\n<p><strong>\u2116 4 \u8f6f\u4ef6\u914d\u7f6e\u4e4budhcpd<\/strong><\/p>\n<pre title=\"sudo nano \/etc\/udhcpd.conf\" class=\"lang:sh decode:true \"># Sample udhcpd configuration file (\/etc\/udhcpd.conf)\r\n\r\n# The start and end of the IP lease block\r\n# \u5f00\u59cb\u5730\u5740\u4e0e\u7ed3\u675f\u5730\u5740\u8981\u6839\u636e\u4f60\u521a\u521a\u8bbe\u7f6e\u7684wlan0\u7684\u7f51\u6bb5\u8bbe\u7f6e\r\nstart           192.168.66.100  #default: 192.168.0.20\r\nend             192.168.66.200  #default: 192.168.0.254\r\n\u2026\u2026\u6b64\u5904\u7701\u7565\u82e5\u5e72\u5b57\u2026\u2026\r\n#Examles\r\nopt     dns     114.114.114.114 114.114.114.110\r\noption  subnet  255.255.255.0\r\nopt     router  192.168.66.1\r\nopt     wins    192.168.66.1\r\n#option dns     129.219.13.81   # appened to above DNS servers for a total of 3\r\noption  domain  local\r\noption  lease   7200            # 10 days of seconds\r\n\u2026\u2026\u6b64\u5904\u7701\u7565\u82e5\u5e72\u5b57\u2026\u2026<\/pre>\n<pre title=\"sudo nano \/etc\/default\/udhcpd\" class=\"lang:sh decode:true \"># Comment the following line to enable\r\n# \u5728DHCPD_ENABLED=\"no\"\u524d\u9762\u52a0\u4e0a\u6ce8\u91ca\u7b26#\r\n#DHCPD_ENABLED=\"no\"\r\n\r\n# Options to pass to busybox' udhcpd.\r\n#\r\n# -S    Log to syslog\r\n# -f    run in foreground\r\n\r\nDHCPD_OPTS=\"-S\"<\/pre>\n<p><strong>\u2116 5 \u7cfb\u7edf\u914d\u7f6e\u4e4b\u8def\u7531\u8f6c\u53d1\u89c4\u5219<\/strong><\/p>\n<pre title=\"\u547d\u4ee4\u884c\u6267\u884c\" class=\"lang:sh decode:true\">sudo nano \/etc\/sysctl.conf\r\n# \u53bb\u6389net.ipv4.ip_forward=1\u524d#\u53f7\r\n\r\n#\u4f7f\u914d\u7f6e\u6587\u4ef6\u751f\u6548\r\nsudo sysctl -p\r\n#\u65b0\u5efa\u89c4\u5219\r\nsudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE\r\nsudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT\r\nsudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT\r\n#\u4fdd\u5b58\u914d\u7f6e\u5230\u6587\u4ef6\r\nsudo sh -c \"iptables-save&gt; \/etc\/iptables.ipv4.nat\"<\/pre>\n<p><strong>\u2116 6 \u7cfb\u7edf\u8bbe\u7f6e\u4e4b\u542f\u52a8\u8bbe\u7f6e<\/strong><\/p>\n<pre title=\"sudo nano \/etc\/rc.local\" class=\"lang:sh decode:true \">#exit0\u524d\u63d2\u5165\r\nsudo iptables-restore &lt; \/etc\/iptables.ipv4.nat\r\nsudo service udhcpd restart<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u2116 1 \u4fee\u6539\u786c\u4ef6\u914d\u7f6e # interfaces(5) file used by ifup(8) and ifd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":584,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[89,44],"_links":{"self":[{"href":"http:\/\/www.x1985.org\/index.php?rest_route=\/wp\/v2\/posts\/701"}],"collection":[{"href":"http:\/\/www.x1985.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.x1985.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.x1985.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.x1985.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=701"}],"version-history":[{"count":6,"href":"http:\/\/www.x1985.org\/index.php?rest_route=\/wp\/v2\/posts\/701\/revisions"}],"predecessor-version":[{"id":707,"href":"http:\/\/www.x1985.org\/index.php?rest_route=\/wp\/v2\/posts\/701\/revisions\/707"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.x1985.org\/index.php?rest_route=\/wp\/v2\/media\/584"}],"wp:attachment":[{"href":"http:\/\/www.x1985.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.x1985.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=701"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.x1985.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}