1. Services to be installed: hostapd
DHCP (ISC-DHCP-server)
DNS (neither dnsmasq nor bind9 is installed)
2. Create the hostapd. conf file, sudo Vim/etc/hostapd. conf (random location)
Interface = wlan0
Driver = nl80211
SSID = xxxxxx
Hw_mode = G
Channel = 10
Macaddr_acl = 0
Auth_algs = 3
WPA = 2 # Remove the following three lines and there will be no password
Wpa_passphrase = xxxxxx # XXXX is the password
Wpa_key_mgmt = WPA-PSK
3. Configure DHCP
subnet 192.168.0.0 netmask 255.255.255.0
{
range 192.168.0.2 192.168.0.10; #设置范围 可以更大192.168.0.0-192.168.10.0
option routers 192.168.0.1;
option domain-name-servers 192.168.0.1#(如果设置成8.8.8.8等 就不需要配置dns服务器(dnsmasq、bind9) 用wlan0 ip需要配置dns服务器);
}
四、设置开机启动脚本内容 ap.sh
sudo ifconfig wlan0 172.16.0.1 netmask 255.255.252.0 # wlan0ip 也可以手动设置static
sudo service bind9 restart #安装bind9时 wlan0需要设置在bin9启动前 所以这里重启一下bin9,如果是安装dmsmasq就不需要这一步 或者
sudo dhcpd wlan0 -pf /var/run/dhcp-server/dhcpd.pid #开启dhcp
sudo bash -c "echo 1 >/proc/sys/net/ipv4/ip_forward" #打开IP转发 同样可以设置永久为1
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE #设置NAT
Sudo hostapd-B/etc/hostapd. conf # open a hotspot
5. Set AP. Sh to start
Reference
Hostapd hotspot settings