Raspberry Pi as a Standalone WiFi Access Point

This recipe is a little different from some other Pi access point setups in that the Pi is not going to be installed on a wired network after we have set it up. However, WiFi devices will be able to connect to it and access any services we have enabled on the Pi (e.g. web server, file sharing) or access other WiFi devices also connected to the Pi.

Step 1. Install an OS

If you have already installed an OS, skip to step 3 (note we are using Raspbian for this recipe, but other Debian based flavors of OS should work the same way).

  • Download Raspbian from https://www.raspberrypi.org/downloads/
  • Use PiBaker (or your favorite disk image transfer process) to install the image to a 4GB (or larger) SD card
  • Insert SD card into the Pi
  • Connect keyboard, ethernet to local network, HDMI cable to a monitor, WiFi dongle
  • Power up the Pi

After the Pi boots up it will launch the raspi-config app – select ‘Advanced Options’ and then ‘Hostname’. By default the Pi has a hostname of ‘raspberrypi’ which you can change here if desired. Select ‘Finish’ when done with raspi-config, which we quit the app and leave you in the shell.

Step 2. Update the OS

This step and the remainder of this recipe are a little easier to perform over an ssh connection from your desktop computer to the pi – in a shell window type:

ssh pi@raspberrypi

where ‘raspberrypi’ is the hostname you set for the Pi in step 1. When prompted for a login enter raspberry

Enter the following commands at the prompt to update the OS and firmware:

sudo apt-get update 
sudo apt-get upgrade 
sudo rpi-update

After that process is complete it may ask you to reboot:

sudo shutdown -r now

Step 3. Configure WiFi Interface

In this step we are assigning a static IP address to our WiFi interface. Ensure that you are connected to the Pi using wired ethernet (not WiFi!).

By default the wifi interface will have the network interface name of wlan0. If you happen to have wifi active perhaps because you already 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 wifi connection to be static and incoming, run:

sudo nano /etc/network/interfaces

which will open the text editor and allow us to edit the network configuration.

Edit the configuration file to match the following:

## Local (loopback) interface
auto lo
iface lo inet loopback

## Wired ethernet interface
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

## WiFi interface
iface wlan0 inet static
address 10.0.0.1
netmask 255.255.255.0

eth0 is the wired ethernet interface on the Pi which will use DHCP to get its IP address from your router. wlan0 is the WiFi interface which we are assigning a static IP address of 10.0.0.1

Save the file (Control-X Y <return>).

Bring the wifi adapter up using the new configuration:

sudo ifup wlan0

Step 4. Setup DNS, DHCP

This step allows the Pi to allocate IP addresses to WiFi clients so that they can be on a separate subnet from the wired network (and will receive IP addresses when the Pi is not connected to the wired network).

Install the dnsmasq package:

sudo apt-get install dnsmasq

Now we will edit the settings for dnsmasq:

sudo nano /etc/dnsmasq.conf

We will set the range of the IP addresses that will be assigned to the clients – look for the line:

#interface=

and change it to:

interface=wlan0

Look for the line:

#dhcp-range=192.168.0.50,192.168.0.150,12h

and change it to:

dhcp-range=10.0.0.2,10.0.0.250,255.255.255.0,12h

We will set the Pi to be the DNS server for the WiFi clients – look for the line:

#address=/double-click.net/127.0.0.1

and change it to:

address=/#/10.0.0.1

These changes tell dnsmasq to handout addresses in the range 10.0.0.2 to 10.0.0.250 and treat the access point (the Pi) as the primary DNS server.

Restart dnsmasq by typing:

sudo service dnsmasq restart

Step 5. Configure the WiFi Access Point

Install access point package:

sudo apt-get install hostapd

Now we can configure the access point details. We will set up a password-protected network so only people with the password can connect.

Create a new configuration file:

sudo nano /etc/hostapd/hostapd.conf

and use the following for its content:

interface=wlan0
## Ralink RT5370 powered wifi dongle
driver=nl80211
ssid=Pi_AP
#hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=1
wpa_passphrase=Raspberry
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Which will create a WiFi access point name (SSID) of ‘Pi_AP’ with a password of ‘Raspberry’ that uses WPA security protocol. You are free to change the values to something else – see http://www.ibm.com/developerworks/library/l-wifiencrypthostapd/ for an explanation of the settings. Note that the entry for ‘driver’ depends on your WiFi dongle. The one in the example an inexpensive one available from Amazon.

Save and close the file.

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"

and save the file.

Test the configuration by running:

sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf

Which the manually starts the access point and tells it to use the config file we just created.

Use another wifi enabled computer/device to check that the SSID you used in the configuration file appears as a WiFi network. If so, you have successfully set up the access point. Try connecting to the network (using the password you entered into the config file) – you will not connect to the internet but debug text will appear on the Pi’s console screen. Cancel the test by typing Control-C.

If  that worked, set up the access point as a ‘daemon’ – a program that will start when the Pi boots.

Run the following commands:

sudo service hostapd start

To start the daemon service. Verify that they both start successfully (no ‘failure’ or ‘errors’)

You can always check the status of the host AP server and the DHCP server with:

sudo service hostapd status
sudo service dnsmasq status

To ensure that the access point starts automatically when the Pi boots:

sudo update-rc.d hostapd enable

Step 6. Install Additional Services

WiFi clients can now connect to the Pi. You can install additional services to allow the Pi to share files, act as a web server, etc to the clients.