參考:Setting up a Raspberry Pi as a routed wireless access point

1.1:安裝hostapd:
sudo apt-get install hostapd
sudo systemctl stop hostapd
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
1.2:配置hostapd:
sudo nano /etc/hostapd/hostapd.conf
加入以下:
country_code=CN
interface=wlan0
ssid=RaspberryPi    #網絡名稱
hw_mode=g    #a = IEEE 802.11a (5 GHz);b = IEEE 802.11b (2.4 GHz);g = IEEE 802.11g (2.4 GHz);ad = IEEE 802.11ad (60 GHz) 
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678    #密碼
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
sudo nano /etc/default/hostapd
在最後添加:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
sudo systemctl start hostapd
2.1:安裝dnsmasq:
sudo apt-get install dnsmasq
sudo systemctl stop dnsmasq
2.2:配置dnsmasq:
sudo nano /etc/dnsmasq.conf
interface=wlan0
dhcp-range=192.168.4.2,192.168.4.255,255.255.255.0,24h
dhcp-host=f0:7b:cb:a2:4d:54,192.168.4.2
dhcp-host=00:0c:29:99:f7:c6,192.168.4.3
sudo systemctl start dnsmasq
3.1:安裝dhcpcd:
sudo apt-get install dhcpcd
sudo systemctl stop dhcpcd
3.2:配置dhcpcd:
sudo nano /etc/dhcpcd.conf
在最後添加:
interface wlan0
    static ip_address=192.168.4.1/24
    nohook wpa_supplicant
sudo rfkill unblock wlan
sudo systemctl start dhcpcd
4:啟用IP轉發:
sudo nano /etc/sysctl.conf
去掉
net.ipv4.ip_forward=1
前面的註釋符號#
sudo sysctl -p
5:配置防火牆規則:
sudo iptables -t nat -A  POSTROUTING -o eth0 -j MASQUERADE
sudo iptables-save > /home/pi/iptables.ipv4.nat
sudo nano /etc/rc.local
iptables-restore < /home/pi/iptables.ipv4.nat
加到最後一行
exit 0
的前面。
6:重啓樹莓派:
sudo reboot