How to configure a Raspberry Pi or Linux system as a WiFi router

Initial steps

The very first thing we should do is set up the working system on our Raspberry Pi. In our case we now have used the newest model of Raspbian, though another system can be utilized (though the instructions could fluctuate).

Once the working system is put in on our micro SD, we run it for the primary time to full its set up and configuration (for instance, within the case of Raspbian, full the «sudo raspi-config«).

Once configured and with the gadget working and related to the Internet via RJ-45, we replace the software program sources, functions and the system by typing:

sudo apt-get replace
sudo apt-get improve
sudo apt-get dist-upgrade

Once with our up to date system we will proceed with the tutorial to configure our Raspberry Pi to perform as a router.

Check that our USB Wi-Fi card is detected and works in AP mode

The very first thing we’ll do is verify that the gadget detects the cardboard. To do that we kind:


And it ought to seem there listed. Once it seems, we’ll execute one other command to confirm that the Wi-Fi card can work in AP mode:

iw checklist

If within the consequence that seems on the display we will see the road: Mode: AP, the cardboard is suitable to perform this configuration, in any other case, we should search for one other card whose chipset permits it to be configured as an entry level, or AP.

Install required software program and dependencies

Most of the required software program is put in by default in Raspbian, though the one ones that would give us issues are the DHCP server and the entry level creation service, which we will set up manually (if it isn’t accessible) by typing:

sudo apt-get set up isc-dhcp-server hostapd

Once at this level we will restart our Raspberry to begin with the configuration.


All configurations are comprised of the terminal, in textual content mode. We are going to use the nano editor and at all times earlier than modifying a file we’ll create a copy of it in order that if an error happens we will restore it.

Configure DHCP server

The very first thing we’ll configure would be the DHCP server. For this we’ll edit the next file:

sudo cp /and so forth/dhcp/dhcpd.conf /and so forth/dhcp/dhcpd.conf.orig
sudo nano /and so forth/dhcp/dhcpd.conf

In this file we should search for a sequence of strains. The following are by default with out commenting, we remark them with a # in entrance of them in order that they’re now not enabled and are as follows:

#choice domain-name "";
#choice domain-name-servers,;

We will search for the #authoritative ingredient; which by default can be commented and we uncomment it to activate it, leaving:


To end we’ll configure the community by which the DHCP server will work (in our instance within the community For this we go to the top of the doc and add:

subnet 192.168.2.Zero netmask {
choice broadcast-address;
choice routers;
default-lease-time 600;
max-lease-time 7200;
choice domain-name "native";
choice domain-name-servers,;

We save the adjustments and shut the file.

We will open a new server configuration file, typing:

sudo cp /and so forth/default/isc-dhcp-server /and so forth/default/isc-dhcp-server.orig
sudo nano /and so forth/default/isc-dhcp-server

In this doc we’ll look (on the finish) for the INTERFACES = »» line and alter it to:


The DHCP server is already configured. We proceed with the tutorial.

Configure the WLAN and Ethernet connection

The very first thing we’ll do is disconnect the Wi-Fi card. To do that we kind:

sudo ifdown wlan0

Next we’ll open the file «interfaces»:

sudo cp /and so forth/community/interfaces /and so forth/community/interfaces.orig
sudo nano /and so forth/community/interfaces

And we’ll configure it as follows:

auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static
deal with

We remark or delete the opposite strains. We save the adjustments and shut the doc. To apply the adjustments for the time being we should kind:

sudo ifconfig wlan0

Configure the entry level

Once once more, we’ll edit one other file by typing:

sudo cp /and so forth/hostapd/hostapd.conf /and so forth/hostapd/hostapd.conf.orig
sudo nano /and so forth/hostapd/hostapd.conf

And on this file we delete what there’s (if there’s something) and paste:


We can change each the SSID by the identify we would like to give our community and the channel in channel and the wpa_passphrase with the password, in plain textual content, that we would like to use to join.

To end with the configuration we open a new configuration file by typing:

sudo cp /and so forth/default/hostapd /and so forth/default/hostapd.orig
sudo nano /and so forth/default/hostapd

We uncomment and alter the road # DAEMON_CONF = »» by:

DAEMON_CONF="/and so forth/hostapd/hostapd.conf"

We save and shut the file to end. We are virtually accomplished, solely a few minor settings stay and configure Raspbian so that each one this runs at system startup robotically.

Final settings

Although our router-access level is already configured and practical, we can not join to the Internet via it, nor are the configurations executed robotically at startup. For this to work, we should observe the final steps that we checklist under.

Configure packet forwarding

For Raspberry Pi to ahead the packets from itself to the router to have the opportunity to go to the Internet we should configure the next parts:

We open and edit the sysctl file:

sudo cp /and so forth/sysctl.conf /and so forth/sysctl.conf.orig
sudo nano /and so forth/sysctl.conf

In this doc we’ll search for the road “# internet.ipv4.ip_forward = 1” and we’ll uncomment it, leaving:


We save and shut the doc. For the adjustments to take impact instantly, we’ll kind:

sudo sysctl -p /and so forth/sysctl.conf

We allow NAT by typing:

sudo iptables -t nat -A POSTROUTING -j MASQUERADE

And we save the iptables guidelines in order that the adjustments persist (we set up the next package deal: sudo apt-get set up iptables-persistent and we observe the wizard).

Configure autostart

In order for the entry level and the DHCP server to begin robotically with our gadget, we should particularly point out this and allow the companies to be activated along with Raspbian. To do that from the terminal we kind:

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

Last setting

Before ending, there’s a WPAsupplicant file that may trigger issues on some events, so to ensure that this doesn’t occur we transfer it to a protected path by typing:

sudo mv /usr/share/dbus-1/system-services/fi.epitest.hostap.WPASupplicant.service /residence/pi

Our Raspberry Pi already works as a Wi-Fi router

Once we now have reached this level we will restart our Raspberry Pi. When it reboots it’ll robotically create the entry level, assign IP addresses to the hosts that join to it, and route all site visitors from the Wi-Fi card via the community card to the router, as lengthy as we’re related to one.