♞树莓派之WIFI热点开启
№ 1 修改硬件配置
# interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d auto eth0 #设置eth0为dhcp自动获取IP地址 iface eth0 inet dhcp auto wlan0 #设置wlan0为指定IP地址 iface wlan0 inet static #设置wlan0的IP地址(WIFI热点要使用的网段) address 192.168.66.1 #设置wlan0的子网掩码 netmask 255.255.255.0 #设置wlan0的网关地址(与上面的address相关就行) gateway 192.168.66.1
№ 2 安装软件
#安装AP程序 sudo apt install hostapd #安装DHCP服务软件 sudo apt install udhcpd
№ 3 软件配置之hostapd
Defaults for hostapd initscript # # WARNING: The DAEMON_CONF setting has been deprecated and will be removed # in future package releases. # # See /usr/share/doc/hostapd/README.Debian for information about alternative # methods of managing hostapd. # # Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration # file and hostapd will be started during system boot. An example configuration # file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz # #DAEMON_CONF="" # Additional daemon options to be appended to hostapd command:- # -d show more debug messages (-dd for even more) # -K include key data in debug messages # -t include timestamps in some debug messages # # Note that -B (daemon mode) and -P (pidfile) options are automatically # configured by the init.d script and must not be added to DAEMON_OPTS. # #DAEMON_OPTS="" #将#DAEMON_CONF=""修改为DAEMON_CONF="/etc/hostapd/hostapd.conf" DAEMON_CONF="/etc/hostapd/hostapd.conf"
interface=wlan0 ssid=热点名称 channel=7 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=热点密码 wpa_key_mgmt=WPA-PSK rsn_pairwise=CCMP ieee80211n=1 hw_mode=g wmm_enabled=1
№ 4 软件配置之udhcpd
# Sample udhcpd configuration file (/etc/udhcpd.conf) # The start and end of the IP lease block # 开始地址与结束地址要根据你刚刚设置的wlan0的网段设置 start 192.168.66.100 #default: 192.168.0.20 end 192.168.66.200 #default: 192.168.0.254 ……此处省略若干字…… #Examles opt dns 114.114.114.114 114.114.114.110 option subnet 255.255.255.0 opt router 192.168.66.1 opt wins 192.168.66.1 #option dns 129.219.13.81 # appened to above DNS servers for a total of 3 option domain local option lease 7200 # 10 days of seconds ……此处省略若干字……
# Comment the following line to enable # 在DHCPD_ENABLED="no"前面加上注释符# #DHCPD_ENABLED="no" # Options to pass to busybox' udhcpd. # # -S Log to syslog # -f run in foreground DHCPD_OPTS="-S"
№ 5 系统配置之路由转发规则
sudo nano /etc/sysctl.conf # 去掉net.ipv4.ip_forward=1前#号 #使配置文件生效 sudo sysctl -p #新建规则 sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT #保存配置到文件 sudo sh -c "iptables-save> /etc/iptables.ipv4.nat"
№ 6 系统设置之启动设置
#exit0前插入 sudo iptables-restore < /etc/iptables.ipv4.nat sudo service udhcpd restart
阅读剩余
版权声明:
作者:Mr.x
链接:http://www.x1985.org/?p=701
文章版权归作者所有,未经允许请勿转载。
THE END