Hostapd
hostapd is a user space daemon for access point and authentication server.
Please follow the guide of Official documentation
Installation and configuration
Tested on raspbian with raspberry pi 3
Install hostapd and configure it
sudo apt-get install hostapd -y --force-yes,
also sudo apt-get install haveged
- Edit
hostapd.conf:
/etc/hostapd/hostapd.conf
interface=wlan0
ssid=RPi
wpa_passphrase=raspberrypi
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
channel=10
hw_mode=g
There should not be any whitespace at the end of each line
then modify file /etc/default/hostapd to let the configuration work
automatically.
You may turn of the wifi and test it with : hostapd -d /etc/hostapd/hostapd.conf
you will see the ssid RPi in wireless network list, but you cannot connect to
it yet.
Tips: if you have trouble with testing, try ifdown wlan0 (in raspbian) to bring down wifi
device ( rfkill with network-manager)
dhcp ip address
- setting static ip address
sudo vim /etc/network/interfaces
supposed the interface name is wlan0:
allow-hotplug wlan0
iface wlan0 inet static
address 10.0.0.1
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
also make dhcpcd not manage wlan0 interface
echo "denyinterfaces wlan0" >> /etc/dhcpcd.conf
- dnsmasq
sudo apt-get install dnsmasq
configuration
interface=wlan0
dhcp-range=10.0.0.100,10.0.0.150,255.255.255.0,12h
# dns
domain-needed
listen-address=127.0.0.1,10.0.0.1
listen-address=::1
#resolv-file=/etc/resolv.dnsmasq.conf
#local=/pi.lan/
#domain=pi.lan
#expand-hosts
# address=/#/10.0.0.1
#address=/pi.lan/10.0.0.1
dhcp-option=option:router,10.0.0.1
# raspberry pi 2
#dhcp-host=raspberrypi2,10.0.0.102,36h
cache-size=600 # default is 150
log-async=20
you may test it with dnsmasq --test
Port forwarding and NAT traffic
Find and uncomment these lines in file /etc/sysctl.conf:
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
add following lines before line exit 0 to have NAT traffic forwarded:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED
-j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
- Or to make the rules to be applied every time on boot, run:
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
```
to save the rules to the file `/etc/iptables.ipv4.nat`
Make it restore on boot by add
```
iptables-restore < /etc/iptables.ipv4.nat
```
in /etc/rc.local above the `exit 0` line.
## Now you may reboot the os to make it work well and have a try.
## Reference:
1. (http://www.ibm.com/developerworks/cn/linux/l-wifiencrypthostapd/)
2. (https://wireless.wiki.kernel.org/en/users/documentation/hostapd)
3. (https://help.ubuntu.com/community/NetworkConfigurationCommandLine/Automatic)
4. https://help.ubuntu.com/community/WifiDocs/WirelessAccessPoint
Other: [scripts](https://github.com/oblique/create_ap)