For setting up the Raspberry Pi as an access point we will be using most of the steps from the Setting up a Raspberry Pi as a WiFI access point guide but with some changes for our project.

First we install the software onto the Raspberry Pi that will act as the 'hostap' (host access point) 

sudo apt-get install hostapd isc-dhcp-server

Set up DHCP server


Next we will edit /etc/dhcp/dhcpd.conf, a file that sets up our DHCP server - this allows wifi connections to automatically get IP addresses, DNS, etc.

Run this command to edit the file

sudo nano /etc/dhcp/dhcpd.conf

Find the lines that say

option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

and change them to add a # in the beginning so they say

#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;

Find the lines that say

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

and remove the # so it says

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

Then scroll down to the bottom and add the following lines

subnet 192.168.42.0 netmask 255.255.255.0 {
	range 192.168.42.10 192.168.42.50;
	option broadcast-address 192.168.42.255;
	option routers 192.168.42.1;
	default-lease-time 600;
	max-lease-time 7200;
	option domain-name "local";
	option domain-name-servers 8.8.8.8, 8.8.4.4;
}

Save the file by typing in Control-X then Y then return

Run

sudo nano /etc/default/isc-dhcp-server

and scroll down to INTERFACES="" and update it to say INTERFACES="wlan0"

Or whatever the name of your wifi adapter is!

close and save the file

Set up wlan0 for static IP


If you happen to have wlan0 active because you set it up, run sudo ifdown wlan0
There's no harm in running it if you're not sure.

Next we will set up the wlan0 connection to be static and incoming. Run sudo nano /etc/network/interfaces to edit the file

Find the line auto wlan0 and add a # in front of the line, and in front of every line afterwards. If you don't have that line, just make sure it looks like the screenshot below in the end! Basically just remove any old wlan0 configuration settings, we'll be changing them up

Depending on your existing setup/distribution there might be more or less text and it may vary a little bit

Add the lines

iface wlan0 inet static
  address 192.168.42.1
  netmask 255.255.255.0

After allow-hotplug wlan0 - see below for an example of what it should look like.  Any other lines afterwards should have a # in front to disable them

Save the file (Control-X Y )

Assign a static IP address to the wifi adapter by running
sudo ifconfig wlan0 192.168.42.1

We will get an error message since we do not have a device connected to wlan0 at the moment.

Configure Access Point

Now we can configure the access point details. 

Create a new file by running sudo nano /etc/hostapd/hostapd.conf

Paste the following in, you can change the text after ssid= to another name, that will be the network broadcast name.

The password can be changed with the text after wpa_passphrase= 

To enable a password remove the # in front of the 5 lines that have wpa in them

interface=wlan0
#driver=rtl871xdrv
ssid=Pi_AP
country_code=US
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
#wpa=2
#wpa_passphrase=Raspberry
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=CCMP
#wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1

I have found that it will load the correct drivers if you comment out the line driver=rtl871xdrv

Save as usual. Make sure each line has no extra spaces or tabs at the end or beginning - this file is pretty picky!

Now we will tell the Pi where to find this configuration file. Run sudo nano /etc/default/hostapd

Find the line #DAEMON_CONF="" and edit it so it says DAEMON_CONF="/etc/hostapd/hostapd.conf"
Don't forget to remove the # in front to activate it!

Then save the file

Likewise, run sudo nano /etc/init.d/hostapd and find the line

DAEMON_CONF=

and change it to

DAEMON_CONF=/etc/hostapd/hostapd.conf

Update hostapd

 I have added this step as required since I could not get it to work with the usb wifi module until I did this.

Before we can run the access point software, we have to update it to a version that supports the WiFi adapter.
First get the new version by typing in

wget http://adafruit-download.s3.amazonaws.com/adafruit_hostapd_14128.zip

to download the new version (check the next section for how to compile your own updated hostapd) then

unzip adafruit_hostapd_14128.zip

to uncompress it. Move the old version out of the way with

sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG

And move the new version back with

sudo mv hostapd /usr/sbin

set it up so its valid to run with

sudo chown root:root /usr/sbin/hostapd

sudo chmod 755 /usr/sbin/hostapd

Finishing up!

Now it is time to set it up as a 'daemon' - a program that will start when the Pi boots.

To set the daemon services to run every time on boot enter these commands.

sudo update-rc.d hostapd enable
sudo update-rc.d isc-dhcp-server enable

This guide was first published on Dec 09, 2016. It was last updated on Nov 26, 2016.

This page (Configure Access Point) was last updated on Nov 23, 2016.

Text editor powered by tinymce.