$ sudo apt-get install isc-dhcp-server
$ sudo apt-get install hostapd
2. 備份阿
$ cd ~
$ mkdir bak
$ cp /etc/network/interfaces ~/bak
$ cp /etc/dhcp/dhcpd.conf ~/bak
$ cp /etc/hostapd/hostapd.conf ~/bak
3. 修改網路介面設定
$ sud vim /etc/network/interfaces
source-directory /etc/network/interfaces.d auto lo iface lo inet loopback allow-hotplug wlan0 iface wlan0 inet manual
4. 修改 dhcp server 設定
$ sudo vim /etc/dhcp/dhcpd.conf
ddns-update-style none; option domain-name "my.raspberry.pi"; option domain-name-servers 8.8.8.8, 8.8.4.4; default-lease-time 600; max-lease-time 7200; authoritative; log-facility local7; subnet 192.168.55.0 netmask 255.255.255.0 { range 192.168.55.101 192.168.55.200; option routers 192.168.55.1; }
5. 修改 hostapd 設定
$ sudo vim /etc/hostapd/hostapd.conf
# This is the name of the WiFi interface we configured above interface=wlan0 # Use the nl80211 driver with the brcmfmac driver driver=nl80211 # This is the name of the network ssid=Pi3-AP # Use the 2.4GHz band hw_mode=g # Use channel 6 channel=6 # Enable 802.11n ieee80211n=1 # Enable WMM wmm_enabled=1 # Enable 40MHz channels with 20ns guard interval ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] # Accept all MAC addresses macaddr_acl=0 # Use WPA authentication auth_algs=1 # Require clients to know the network name ignore_broadcast_ssid=0 # Use WPA2 wpa=2 # Use a pre-shared key wpa_key_mgmt=WPA-PSK # The network passphrase wpa_passphrase=1234567890 # Use AES, instead of TKIP rsn_pairwise=CCMP
6. 建立啟動腳本
$ vim ~/ap_mode.sh
#!/bin/bash ifconfig wlan0 192.168.55.1 netmask 255.255.255.0 iptables -A INPUT -i wlan0 -j ACCEPT iptables -t nat -A POSTROUTING -s 192.168.55.0/24 -o eth0 -j MASQUERADE sysctl net.ipv4.ip_forward=1 hostapd /etc/hostapd/hostapd.conf -B dhcpd wlan0
7. 修改權限 & 設定開機就啟動
$ chmod 755 ~/ap_mode.sh
$ sudo vim /etc/rc.local新增這行
sudo ~/ap_mode.sh
Reference:
* Using your new Raspberry Pi 3 as a WiFi access point with hostapd
沒有留言:
張貼留言