I was in a need for a Raspberry Pi (RPi) acting as an access controller for one of our sawing machine in our private club workshop. As we do not have any network in our workshop, but wanted to easily be able to connect with the RPi anyways, I figured it would be nice to set the RPi, which is a Model B+ with WiFi included, up as an autonomous access point that we can connect to with a laptop if need be.
I found a ton of information on how to set up the RPi as an access point, but that was either with internet access, bridging the ethernet port to wifi, or it seemed to be pretty outdated and not working entirely.
After some messing over the weekend I finally found a setup that works.
These instructions have been proven working with an fresh installation and the following setup:
After ssh
-ing into the RPi (to be able to do so, make sure to put an empty file named ssh
onto the boot
-partition of the SD card),
ssh pi@raspberrypi
we first want to make sure that the system is up-to-date:
sudo apt-get update
sudo apt-get upgrade
After that, we install the following required packages, stop them right afterwards, as we need to make some additional configurations on them first and do a restart:
sudo apt-get install dnsmasq hostapd
sudo systemctl stop dnsmasq
sudo systemctl stop hostapd
sudo reboot
Our goal is to connect to the RPi that works as an access point in the end, so first things first the wireless adapter of the RPi needs to have a fixed IP. Most instructions, including (1) and (2) will do so by editing /etc/dhcpcd.conf
. But I found out that doing so will end up in a configuration with the dhcp
server of the RPi not working, because it keeps failing to start the dhcpcd
service at boot time with the following message:
dnsmasq: failed to create listening socket for 172.16.0.1: Cannot assign requested address
It seems as though that is because at the time the system tries to start the dnsmasq
service, the wifi adapter isn't up already, so the fixed IP configured in that manner isn't available. I found an entry on stackexchange.com proposing to fix the IP with /etc/network/interfaces
instead (3) -- which has proven to be working for me.
So, my /etc/network/interfaces
now actually looks like this:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto wlan0
iface wlan0 inet static
address 172.16.0.1
netmask 255.255.255.0
dhcp
server with dnsmasq
As /etc/dnsmasq.conf
contains tons of boilerplate code that we won't need, we are making a backup of the original file and create a new one as our productive configuration
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo vi /etc/dnsmasq.conf
with the following content of /etc/dnsmasq.conf
:
interface=wlan0 # Use the required wireless interface - usually wlan0
dhcp-range=172.16.0.10,172.16.0.20,255.255.255.0,24h
hostapd
The access point functionality is set up in /etc/hostapd/hostapd.conf
, which has to be created first
sudo vi /etc/hostapd/hostapd.conf
with the follwing content:
interface=wlan0
driver=nl80211
ssid=MyNet
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=MyPassword
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
That will make an access point of the RPi using its wlan0
interface to broadcast a new wireless network with the ssid
of MyNet
, the password MyPassword
with a WPA2 PSK
encryption on channel 7.
Note that if you want to hide / not broadcast the ssid of our new wireless, you have to set ignore_broadcast_ssid=1
-- something we choose to do in our case as the network really only is supposed to be used to configure our RPi.
Next, we need to open /etc/default/hostapd
and find the line that says DAEMON_CONF=""
to change it to DAEMON_CONF="/etc/hostapd/hostapd.conf"
. This tells hostapd
where its configuration file is located.
As I said in the beginning, most instructions found online assume that we want to bridge an existing internet connection on the ethernet port eth0
of the RPi to our new wifi access point. In this specific use case, we do not want that, so we are leaving out those steps.
We stopped hostapd
and dnsmasq
right after installing the packages because we needed to do some configuration on them, so now that we have finished that, we need to start those services permanentely again:
sudo systemctl start hostapd
sudo systemctl start dnsmasq
Last but not least we can now restart the RPi and connect with the new wireless network. If everything works as expected, we should now get an IP address of the dhcp
pool we configured above and can ssh
into our RPi with
ssh pi@172.16.0.1