Freth
Posts: 4
Joined: Sat Jun 25, 2016 2:57 pm

Success with access point on Raspbian Stretch

Fri Apr 19, 2019 4:32 pm

NOTE: This tutorial assumes you're working with a fresh image of Raspbian Stretch and have already installed it on an SD, plugged it into your device, powered it up and are ready to go.


I spent many hours struggling with the official access point tutorial (see https://www.raspberrypi.org/documentati ... s-point.md), trying to install it on Raspbian Stretch to no avail. I tried other tutorials on various websites, but none of them worked. I think I spent a total of 12 hours on it, until I found success.

The website that had the tutorial that worked: https://pimylifeup.com/raspberry-pi-wir ... ess-point/

I cannot take credit for this, but I wanted to share it here, to hopefully save others the headache. As a side note, when I couldn't access my Pi Zero W directly due to a glitch in Windows and the host name, I completed the setup with the SD in my RPI3B+, then just moved it to my Pi Zero W.

There were a couple of important things missing from the tutorial, which I'm adding here.

Prep: Enable SSH using raspi-config or add an "SSH" text file in the root folder. Enable VNC if you want to use that for remote desktop. Config the system localization, etc.

Access Point Setup

Update and upgrade first.

Code: Select all

sudo apt-get update
sudo apt-get upgrade

Install hostapd and dnsmasq.

Code: Select all

sudo apt-get install hostapd dnsmasq

Stop the packages.

Code: Select all

sudo systemctl stop hostapd
sudo systemctl stop dnsmasq

Edit the dhcpcd config and add settings.

Code: Select all

sudo nano /etc/dhcpcd.conf
  • NOTE: You can customize the IP.
Settings:

Code: Select all

interface wlan0
    static ip_address=192.168.220.1/24
    nohook wpa_supplicant
CTRL-X,Y,Enter to save.


Restart dhcpcd.

Code: Select all

sudo systemctl restart dhcpcd

Edit the hostapd config and add settings.

Code: Select all

sudo nano /etc/hostapd/hostapd.conf
  • NOTE: Leave out anything starting with "wpa" to remove the passphrase requirement for the access point.
Settings:

Code: Select all

interface=wlan0
driver=nl80211

hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=0
macaddr_acl=0
ignore_broadcast_ssid=0

auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

# This is the name of the network
ssid=Pi3-AP
# The network passphrase
wpa_passphrase=pimylifeup
CTRL-X,Y,Enter to save.


Edit hostapd file in /etc/default.

Code: Select all

sudo nano /etc/default/hostapd
Find #DAEMON_CONF=""
Uncomment it (remove the # at the beginning) and add the path.

Code: Select all

DAEMON_CONF="/etc/hostapd/hostapd.conf"
CTRL-X,Y,Enter to save.


Edit the hostapd file in /etc/init.d.

Code: Select all

sudo nano /etc/init.d/hostapd
Find DAEMON_CONF=
Add the path to the hostapd.conf here as well, but without quotes.

Code: Select all

DAEMON_CONF=/etc/hostapd/hostapd.conf
CTRL-X,Y,Enter to save.


Back up the dnsmasq.conf file.

Code: Select all

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

Create a new and blank dnsmasq.conf in place of the one we just moved.

Code: Select all

sudo nano /etc/dnsmasq.conf
  • NOTE: server=8.8.8.8 can be used for Google DNS and IP range can be customized.
Settings:

Code: Select all

interface=wlan0       # Use interface wlan0  
server=1.1.1.1       # Use Cloudflare DNS  
dhcp-range=192.168.220.50,192.168.220.150,12h # IP range and lease time  
CTRL-X,Y,Enter to save.


Edit the systctl.conf file.

Code: Select all

sudo nano /etc/sysctl.conf
Find: #net.ipv4.ip_forward=1
Remove the comment character (#) to activate this line.
CTRL-X,Y,Enter to save.


Activate the setting above immediately.

Code: Select all

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

Configure a NAT between wlan0 and eth0.

Code: Select all

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Save the new rules.

Code: Select all

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Edit rc.local.

Code: Select all

sudo nano /etc/rc.local
Find: exit 0
Add this line above it.

Code: Select all

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

If all has gone well and there are no mistakes, you should be able to start hostapd and dnsmasq without errors.

Code: Select all

sudo service hostapd start
sudo service dnsmasq start
If you have errors, you'll need to use the commands it gives you to see what it's pointing to.


This part was missing from the website tutorial:

Enable hostapd and dnsmasq, so they start at boot.

Code: Select all

sudo update-rc.d hostapd defaults
sudo update-rc.d hostapd enable
sudo update-rc.d dnsmasq defaults
sudo update-rc.d dnsmasq enable
You should see your access point on wifi now.

Next, I would reboot.

Code: Select all

sudo reboot
Your access point should (still) be available after reboot.

Connect to your access point, then SSH into it (using your IP, of course).

Code: Select all

ssh 192.168.220.1

Regards. :o)
Last edited by Freth on Sat Apr 20, 2019 3:22 am, edited 1 time in total.

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Success with access point on Raspbian Stretch

Fri Apr 19, 2019 5:04 pm

It is allowed for the "ssh" file to have a ".txt" extension. This makes it easier to create with some text editors.
Unreadable squiggle

Freth
Posts: 4
Joined: Sat Jun 25, 2016 2:57 pm

Re: Success with access point on Raspbian Stretch

Sat Apr 20, 2019 3:21 am

rpdom wrote:
Fri Apr 19, 2019 5:04 pm
It is allowed for the "ssh" file to have a ".txt" extension. This makes it easier to create with some text editors.
Thank you for letting me know. I wasn't aware.

yeyeto2788
Posts: 1
Joined: Mon May 06, 2019 6:11 pm
Location: Spain
Contact: Website

Re: Success with access point on Raspbian Stretch

Mon May 06, 2019 6:20 pm

Hey! Thanks for this guide.

I can confirm that these steps are working with latest raspbian image (2019-04-08-raspbian-stretch).

I just wanted to point out 2 things:

1. Take into consideration that after executing

Code: Select all

sudo systemctl restart dhcpcd
you may loose you ssh connection on the rpi0w (If connected through WIFI and SSH). After googling a bit I found easier to add the USB-OTG or Ethernet over USB on the rpi0w and I could follow all steps.

2. I had a error saying

Code: Select all

Failed to start hostapd.service: Unit hostapd.service is masked
when I tried

Code: Select all

vice hostapd start
(Almost at the end), so to fix that and keep with the guide I just type the following commands:

Code: Select all

sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
Regards.

Return to “Networking and servers”