Turn your Raspberry Pi into a WiFi router

This is a bit special because it is a “checklist” or “actionlist” in order to turn my Raspberry Pi 2 model B into a WiFi router. I bought a starter kit with a WiFi dongle as this one to achieve this goal without having to worry about component compatibility and to have a Rasbian version already installed.

Once you have received your Raspberry Pi, and connected all your devices (hdmi, keyboard, mouse, Wifi dongle, SD card and the power supply), branch it to your internet router with an ethernet cable. Open a terminal and enter these commands:

$ apt-get update
$ apt-get upgrade

Now we are ready to start our configuration.

Before to start

If like me you don’t have a QWERTY keyboard and you don’t live in the UTC+0 timezone you will need to change that to make your experience more confortable.

To update the keyboard layout follow these instructions:

$ sudo nano /etc/default/keyboard

Find the key/value: XKBLAYOUT="gb" and replace the gb value with your country code (e.g. fr for France). Once the file is modified, if you use nano, enter the CTRL+O to save the modification and then CTRL+X to quit.

To update your timezone enter the following command and follow the instructions:

$ sudo tzselect

Let’s install the router software.


In order to turn the Raspberry Pi as a WiFi router and access point you need to install some utilities:

  • hostapd: a user space daemon for wireless access point and authentication servers. In simple words, hostapd turns your Raspberry Pi into a WiFi access points allowing decent amount of configuration options (for security for example).
  • isc-dhcp-server: an implementation of the Internet Systems Consortium’s DHCP server. A DHCP server is responsible for assigning addresses automatically to computers and devices that connect to the access point.

To start we are going to install the hostapd deamon. Like most of the WiFi dongle sold with the Raspberry Pi are based on the RTL8188CUS chipset, we need to install a custom version of hostapd:

$ cd /tmp
$ sudo wget https://github.com/jenssegers/RTL8188-hostapd/archive/v1.1.tar.gz
$ sudo tar -zxvf v1.1.tar.gz
$ cd RTL8188-hostapd-1.1/wpa_supplicant
$ sudo make
$ sudo make install
$ cd ../hostapd
$ sudo make
$ sudo make install

The build can take some time, so just be patient. 🙂

Then, to install the isc-dhcp-server utility run the following command:

$ sudo apt-get install isc-dhcp-server

Once finished we can go to the next: the configuration.


The DHCP server

To configure the DHCP server open the file dhcpd.conf:

$ sudo nano /etc/dhcp/dhcpd.conf

Next I want the DCHP server to attribute ip from to with a netmask. To do so you can simply replace the content of the file with the following one:

ddns-update-style none;

default-lease-time 600;
max-lease-time 7200;


log-facility local7;

subnet netmask {
 option broadcast-address;
 option routers;
 default-lease-time 600;
 max-lease-time 7200;
 option domain-name "local-network";
 option domain-name-servers,;

Press CTRL+O then CTRL+X to save the file.

Next file to edit is isc-dhcp-server:

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

Find the line with the key INTERFACES and add the wlan0 value:


This will make the DHCP server hand out network addresses on the wireless interface. Save the file and exit nano.

In order to make the DHCP server effective we need to configure a static ip address for the wireless network adapter. Start by putting down the WLAN interface:

$ sudo ifdown wlan0

Then open the file /etc/network/interfaces:

$ sudo nano /etc/network/interfaces

Replace its content by the following one:

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet static

This configuration will make the wireless adapter take the address in our new local network.

Now let’s configure the access point thanks to the hostapd daemon.

The access point

To configure the hostapd daemon, open the file called hostapd.conf:

$ sudo nano /etc/hostapd/hostapd.conf

Update the ssid and wpa_passphrase values to define the SSID Wifi name and WPA password of your WiFi:

ssid=My Wifi Hotspot Name

That’s all for the access point configuration. Just think to test the configuration and reboot your Raspberry Pi:

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

Starting your WiFi router

You are now ready to start the DHCP server and the access point application. To test everything is ok just run these commands:

$ sudo /etc/init.d/isc-dhcp-server start
$ sudo /etc/init.d/hostapd start

If everything is ok you should be able to find your wireless network in the list of your smart phone or laptop!

So this is the time to start these services when the Raspberry Pi boot. It’s very simple, just enter the following commands:

$ sudo update-rc.d hostapd defaults 
$ sudo update-rc.d isc-dhcp-server defaults


I tried to make it as simple as possible in order to make your (and my next) installations as simple as possible.

In the next chapter I’ll do the same this in order to install mongodb and nodejs on a Raspberry Pi 2.

If you have any question, let a comment below!


1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditPin on Pinterest


Time limit is exhausted. Please reload CAPTCHA.

  1. Nameless · March 14

    J’ai suivi pas à pas le tuto. Je vois bien mon SSID, lorsque je veux me connecter il accepte bien mon password mais ensuite me rejete. J’ai essayer depuis un PC android et un PC windows. Mon rapsberry est connecté en ETH0 sur la freebos (192.168) et mon WLAN0 est en (10.0). Une piste pour résoudre mon souci ?

  2. Andrea · March 14

    Hello, many thanks for this tutorial!
    I set up everything, the hotspot is found by my devices but I can’t connect them to it.
    How can I move?