Raspberry ap mode

Install

upgrade system && update apt-get resources

1
2
3
4
5
6
7
8
9
10
/etc/apt/sources.list

deb http://mirrors.zju.edu.cn/raspbian/raspbian/ jessie main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'

#deb-src http://mirrors.zju.edu.cn/raspbian/raspbian/ jessie main contrib non-free rpi
#deb http://mirror.nus.edu.sg/raspbian/raspbian wheezy main contrib non-free rpi
#deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi

software

1
git clone https://github.com/oblique/create_ap.git

dependencies

1
sudo apt-get install util-linux procps iproute2 iw haveged hostapd dnsmasq

hostapd is the daemon thread of Host Access Point
used to provide WPA2 token check and authentication

dnsmasq used to config DNS provide DHCP service

Config

Config Git Page

Wlan config

dispatch wlan0 a static ip address

1
2
3
4
sudo vim /etc/dhcpcd.conf

interface wlan0
static ip_address=192.168.0.1/24

comments the wlan0 wpa-conf to prevent distribute host mode

1
2
3
4
5
sudo nano /etc/network/interfaces

allow-hotplug wlan0
iface wlan0 inet manual
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

restart raspberry

1
2
3
sudo service dhcpcd restart
sudo reboot
sudo init 0


Host config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sudo vim /etc/hostapd/hostapd.conf

interface=wlan0
driver=nl80211
ssid=pi3ap
hw_mode=g
channel=6
wmm_enabled=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
# WPA2 mode
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP

Web config

1
2
3
4
sudo nano /etc/sysctl.conf

# remove comment
net.ipv4.ip_forward=1

if not want to reboot raspberry

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

For config NAT, config firewall first

1
2
3
sudo iptables -t nat -APOSTROUTING -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

set rule autostart

1
sudo sh -c "iptables-save> /etc/iptables.ipv4.nat"

run NAT by DHCPCD need a new config

1
2
sudo nano /lib/dhcpcd/dhcpcd-hooks/70-ipv4-nat
iptables-restore </etc/iptables.ipv4.nat

restart

1
2
3
sudo service hostapdstart
sudo service dnsmasq start
sudo reboot