出自flip the world 檢視Application - Wifi AP的原始碼 頁面討論 閱讀檢視原始碼檢視歷史 ←Application - Wifi AP 您沒有權限執行編輯此頁面,由於以下原因: 您請求的操作只有這個群組的使用者能使用:使用者 您可以檢視並複製此頁面的原始碼。 Turning a Raspberry Pi into a '''Wi-Fi access point''' with hostapd and udhcpd, including the NAT configuration for sharing its uplink. [[File:DSC 2515.JPG|thumb|350px|Wifi AP with GPS]] == USB wifi dongle == ID 148f:3572 Ralink Technology, Corp. RT3572 Wireless Adapter == Software == sudo apt-get install hostapd udhcpd === dhcp server === *Edit the file /etc/udhcpd.conf and configure it like this: <pre> start 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices. end 192.168.42.20 interface wlan0 # The device uDHCP listens on. remaining yes opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use. opt subnet 255.255.255.0 opt router 192.168.42.1 # The Pi's IP address on wlan0 which we will set up shortly. opt lease 864000 # 10 day DHCP lease time in seconds </pre> *Edit the file /etc/default/udhcpd and change the line: <pre> DHCPD_ENABLED="no" to #DHCPD_ENABLED="no" </pre> === Hostapd === *edit the file /etc/hostapd/hostapd.conf <pre> interface=wlan0 driver=nl80211 ssid=My_AP hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=My_Passphrase wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP </pre> *Edit the file /etc/default/hostapd <pre> #DAEMON_CONF="" to: DAEMON_CONF="/etc/hostapd/hostapd.conf" </pre> === Configure NAT (Network Address Translation) === * fordwarding sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" * iptables <syntaxhighlight lang="bash"> 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" up iptables-restore < /etc/iptables.ipv4.nat </syntaxhighlight> === Service enable === * makae sure your runlevel <pre> $runlevel N 5 </pre> * make symbolic link to rcS <syntaxhighlight lang="bash"> cd /etc/init.d/rc5.d # put udhcpd to the last ln -s ../init.d/udhcpd S05udhcpd ln -s ../init.d/hostapd S01hostapd </syntaxhighlight> * service <syntaxhighlight lang="bash"> sudo systemctl enable hostapd.service sudo systemctl enable udhcpd.service </syntaxhighlight> == Reference == [http://elinux.org/RPI-Wireless-Hotspot RPI-Wireless-Hotspot] [[Category:Projects]] 返回到「Application - Wifi AP」。