Application - Wifi AP

出自 flip the world
於 2018年8月23日 (四) 10:36 由 Tommy (對話 | 貢獻) 所做的修訂 (已建立頁面,內容為 "thumb|350px|Wifi AP with GPS == USB wifi dongle == ID 148f:3572 Ralink Technology, Corp. RT3572 Wireless Adapter == Software == sudo apt-get i…")
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
前往: 導覽搜尋
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:
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
  • Edit the file /etc/default/udhcpd and change the line:
DHCPD_ENABLED="no"
to
#DHCPD_ENABLED="no"

Hostapd

  • edit the file /etc/hostapd/hostapd.conf
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
  • Edit the file /etc/default/hostapd
#DAEMON_CONF=""
to:
DAEMON_CONF="/etc/hostapd/hostapd.conf"

Configure NAT (Network Address Translation)

  • fordwarding

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

  • iptables
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

Service enable

  • makae sure your runlevel
$runlevel
N 5
  • make symbolic link to rcS
cd /etc/init.d/rc5.d
# put udhcpd to the last
ln -s ../init.d/udhcpd S05udhcpd
ln -s ../init.d/hostapd S01hostapd
  • service
sudo systemctl enable hostapd.service
sudo systemctl enable udhcpd.service


Reference

RPI-Wireless-Hotspot