Raspberry Pi as a fancy Wi-Fi hotspot

Nov 03, 2016

There are plenty of tutorials on how to make your Raspberry Pi a Wi-Fi hotspot with VPN, bells, and whistles. Unfortunately, I occasionally have to start from scratch after making some silly mistake that breaks everything. That’s why I decided to write this tutorial for myself. Maybe you’ll find it useful too. Let me know if you do!

I am using Raspberry Pi 2 Model B (1,2 GHz Quad-core ARM Cortex-A53, 1GB RAM, USB 2.0) with Raspbian Jessie Lite image from https://www.raspberrypi.org/downloads/raspbian/. See installation guide for Linux (guides for other operating systems should also be available on the website).

General configuration

Check https://www.linode.com/docs/security/securing-your-server for some information about securing your server.

Making a Wi-Fi hotspot

I was using Edimax EW-7811UN Wi-Fi adapter, which seems to work reasonably well with Raspberry Pi 2.


We need a custom version for this dongle. It’s available at https://github.com/jenssegers/RTL8188-hostapd.

First, delete the old version if it’s installed:

# apt-get autoremove hostapd

Now clone the repo and install it:

# git clone https://github.com/jenssegers/RTL8188-hostapd.git
# cd hostapd
# make
# make install

Now modify the configuration file that has just been created at /etc/hostapd/hostapd.conf. The only two values that need changing are ssid and wpa_passphrase.


# apt-get install dnsmasq

Create configuration file /etc/dnsmasq.conf (replace old one, if exists) and update it with the following values:


Network interfaces

Add the following two lines at the end of /etc/dhcpcd.conf:

interface wlan0
    static ip_address=

In /etc/network/interfaces comment out this line in wlan0 section:

wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf


In /etc/sysctl.conf uncomment this line:


This should enable forwarding on the next reboot.


To share internet connection on eth0 to Wi-Fi add the following lines to /etc/rc.local file:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

To start up all the services add:

sudo service hostapd start
sudo service dnsmasq start

Last steps

Next, you need to reboot the Pi:

# reboot

After it’s up again Wi-Fi hotspot should be available. Success!