I decided to setup Hostapd and DNSMasq on my Raspberry Pi 1 as part of a bigger project. This makes an awesome project to setup a router. See below.
This will install the applications.
1 2 3 4 |
sudo su - apt-get update apt-get upgrade apt-get install dnsmasq hostapd vim -y |
Lets block DHCPd by editing
1 |
vim /etc/dhcpcd.conf |
Add this line to the bottom.
1 |
denyinterfaces wlan0 |
Lets setup Hostapd
1 |
vim /etc/hostapd/hostapd.conf |
Enable the hostapd.conf config.
1 |
vim /etc/default/hostapd |
Ensure the following live is present.
1 |
DAEMON_CONF="/etc/hostapd/hostapd.conf" |
Paste the following into the configuration file, ensure you change the sections which relate to you. Pay attention to ssid and wpa password.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
interface=wlan0 ssid=raspberryap hw_mode=g channel=6 ieee80211n=1 wmm_enabled=1 ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_key_mgmt=WPA-PSK wpa_passphrase=r@spberry@p rsn_pairwise=CCMP |
Lets setup DNSMasq.
1 |
vim /etc/dnsmasq.conf |
Put the following into the config file.
1 2 3 4 5 6 7 |
interface=wlan0 listen-address=192.168.100.1 bind-interfaces server=8.8.8.8 domain-needed bogus-priv dhcp-range=192.168.100.100,192.168.100.200,12h |
Now we enable IP forwarding on a system level
1 |
vim /etc/sysctl.conf |
Uncomment the following line
1 |
#net.ipv4.ip_forward=1 |
Setup the IPtables NAT rules
1 2 3 |
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 |
Lets save the IPTables rules permanently.
1 |
sh -c "iptables-save > /etc/iptables.ipv4.nat" |
Lets ensure they run on reboot
1 |
vim /etc/rc.local |
and ensure the following is present before the “exit 0”.
1 |
iptables-restore < /etc/iptables.ipv4.nat |
Reboot and your done!
2 thoughts on “How to setup hostapd and dnsmasq on a Raspberry Pi 1 | setup wifi access point on a raspberry pi 1 with hostapd and dnsmasq”