Create your Access Point with your Raspberry Pi

[Last updated: 03/28/19]

In this tutorial, we will transform our Raspberry Pi in a Wifi access point, this in order to connect to it and access to the internet using its wired Ethernet connection or to use the applications installed on the Raspberry Pi such as our Plex Media Server 🙂

To do this, we must first have installed, configured and updated Raspbian.

As I write this tutorial, the version of Raspbian is the 2018-11-13 Raspbian Stretch Lite Kernel version 4.14.

Connect with SSH to your Raspberry Pi, then:

1. Installing packages :

Execute the following command : sudo apt-get install dnsmasq hostapd -y

Once dnsmasq is installed, run the following commands to stop unconfigured services:

sudo systemctl stop dnsmasq
sudo systemctl stop hostapd

And restart it with the command: sudo reboot now

2. Wireless interface configuration (wlan) :

Edit the file “dhcpcd.conf” with the command : sudo nano /etc/dhcpcd.conf

At the end of this file add :

interface wlan0
static ip_address=192.168.4.1/24
static routers=192.168.4.1
static domain_name_servers=8.8.8.8

Type ctrl+O then ENTER to save the changes, type ctrl+X to exit the editor.

3. Configuration of HOSTAPD :

Edit the file “hostapd.conf” with the command : sudo nano /etc/hostapd/hostapd.conf

In this file add :

interface=wlan0
driver=nl80211
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=RPiAP
wpa_passphrase=mypassword

You can change the value of the last two lines to put the ssid and password of your choice.

Type ctrl+O then ENTER to save the changes, type ctrl+X to exit the editor.

Then enter the following command : sudo nano /etc/default/hostapd

Find the line  #DAEMON_CONF=""  and change it to DAEMON_CONF="/etc/hostapd/hostapd.conf"

Type ctrl+O then ENTER to save the changes, type ctrl+X to exit the editor.

4. Configuration of DNSMASQ :

Edit the file “dnsmasq.conf” with the command : sudo nano /etc/dnsmasq.conf

At the end of this very long file add the code below.

Tip: Scroll down the file with the “Page Down” key.

interface=wlan0
domain-needed
bogus-priv
dhcp-range=192.168.4.8,192.168.4.250,12h

Type ctrl+O then ENTER to save the changes, type ctrl+X to exit the editor.

5. Configuring the IP Table (Optional – Personally not test) :

This operation is optional, only if you want that the connected devices to your Access Point may access to the internet.

Enter the following command : sudo nano /etc/sysctl.conf

Delete the # at the beginning of the line net.ipv4.ip_forward=1

Now configure the NAT (Network Address Translation). You can do this using the following commands :

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 be apply this configuration on every time the Raspberry Pi is started, run the following commands :

To save these this rules in the file “iptables.ipv4.nat” enter the following command : sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Edit the file “rc.local” with the command sudo nano /etc/rc.local and just before exit 0 add :

iptables-restore < /etc/iptables.ipv4.nat

Type ctrl+O then ENTER to save the changes, type ctrl+X to exit the editor.

6. Finally :

That’s it, everything is ready, all you have to do is start the services with the following command :

sudo systemctl start hostapd

If you have the following message: “Failed to start hostapd.service: Unit hostapd.service is masked.“, Run the following two commands:

sudo systemctl unmask hostapd
sudo systemctl enable hostapd

Then again :sudo systemctl start hostapd

Followed by : sudo systemctl start dnsmasq

And finally, we will restart the Raspberry Pi with the command : sudo reboot now

Once started, connect to your new Wifi with a client device.

4 Replies to “Create your Access Point with your Raspberry Pi”

    1. With Linux, when it doesn’t work, it is better to redo everything from the beginning 🙂

    1. Hi,
      You don’t need to add the # to execute the commands.
      The # are only used to comment lines in configuration files.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.