Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Raspberry Pi 3 access-point-setup
# This version uses September 2017 august stretch image, please use this image
if [ "$EUID" -ne 0 ]
then echo "Must be root"
if [[ $# -lt 1 ]];
then echo "You need to pass a password!"
echo "Usage:"
echo "sudo $0 yourChosenPassword [apName]"
if [[ $# -eq 2 ]]; then
apt-get remove --purge hostapd -yqq
apt-get update -yqq
apt-get upgrade -yqq
apt-get install hostapd dnsmasq -yqq
cat > /etc/dnsmasq.conf <<EOF
cat > /etc/hostapd/hostapd.conf <<EOF
sed -i -- 's/allow-hotplug wlan0//g' /etc/network/interfaces
sed -i -- 's/iface wlan0 inet manual//g' /etc/network/interfaces
sed -i -- 's/ wpa-conf \/etc\/wpa_supplicant\/wpa_supplicant.conf//g' /etc/network/interfaces
sed -i -- 's/#DAEMON_CONF=""/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/g' /etc/default/hostapd
cat >> /etc/network/interfaces <<EOF
# Added by rPi Access Point Setup
allow-hotplug wlan0
iface wlan0 inet static
echo "denyinterfaces wlan0" >> /etc/dhcpcd.conf
systemctl enable hostapd
systemctl enable dnsmasq
sudo service hostapd start
sudo service dnsmasq start
echo "All done! Please reboot"

Lewiscowles1986 commented Mar 6, 2016

This is specifically for the raspberry pi 3. The script should work with any wireless card setup as wlan0 that does not require a driver, please provide feedback, let me know any issues.

The use-case is setting up a private network, maybe for some rPi zero's to connect to, but the sky is the limit; you could bolt on a dns-server and provide a walled-garden internet experience like facebook (please don't), or host your personal project to showcase at interview.

Now allows you to specify the Access point (AP) name, so it does not have to be whatever it was before.

I suggest to share the eth0 connection that you add
in /etc/sysctl.conf
and execute the following iptables command:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

This will allow the traffic to pass through the wifi AP and out via the ethernet connection.


Lewiscowles1986 commented Mar 15, 2016

Hi @vhgarandil,

Thanks for the suggestions, this is not a script to setup a wireless->ethernet bridge, however it is a good idea for an additional script to allow using a device (doesn't matter really if it's ethernet or another wifi dongle).

The main purpose of this script is to provide an access point with guest network (for now). But I may consider adding this, as many have asked for it

I am a very very new user having just received my rPi3 running Raspbian. In at the deep end I know but I thought this function would be useful. I have been able to compile the script and even run it, but am at a loss at getting past "you need a password!"
How do I respond to the usage advice line? I have tried to input a password but cannot get beyond causing the error 'command not found'. What am I missing?

Can you give me a prod in the right directions? Thanks if you can take the time to no doubt tell me the obvious!

I find this very useful. Could you add some options to help the user to share the eth0 connection through wifi.


Lewiscowles1986 commented Mar 25, 2016

Hi @ipplepen

So once you run the script, you can run
sudo password wifiapname
and it will setup with the password "password", and the SSID "wifiapname"


Lewiscowles1986 commented Mar 25, 2016


Thanks, I'm looking right now at releasing something separate for that, so that you can share eth0, or any other networking device; I believe @vhgarandil suggestion (see above) will work for bridging eth0 as the primary connection, but to make a script do this; I think they should be separate scripts for people like me that don't want a bridge or repeater station.

elck commented Mar 27, 2016

I have some problems with this script.
Mind you, I am a total beginner with linux
On line 19 there is a var $APSSID (should that be APSSID ?) whilst on line 40 I see ssid=$APNAME (shouldn't that be $APSSID ?)

The other thing is an error I get on line 50 (when I remove the redirection that is)
Failed to create interface mon.wlan0 :-95 (Operation not supported)
wlan0 could not connect to kernel driver

What am I doing wrong please?


Lewiscowles1986 commented Mar 28, 2016

@elck nice catch on APSSID vs APNAME, must have renamed a var and forgot to copy to / update all lines (managing this via git might have been a better idea)

can I ask if you are using this on a raspberry Pi 3 using raspbian?

Most of the steps are entirely applicable on any debian based Linux on the Pi3, but raspbian has the official rPi3 hardware libs; so I'd advise using that (they have a lite edition now)

Thanks for the feedback, keep me updated

crone commented Apr 3, 2016

I have tried this script. All seems to be ok on the RPI3 side. But non of my devices at home are able to connect to the AP.

Any help would be appreciated.


Lewiscowles1986 commented Apr 4, 2016

can I ask the exact commands you ran?

Most devices should be able to connect to the rPi3, although it's not an internet pass-through Access-Point; it's so you can access your Pi to help to configure it with fewer wires

Good code you have here, but it just does not work for me,even though i am using raspbian. I've been trying for a few days to get the Pi3 AP working but it's always the same thing, saying that it could not start mon.wlan0 but the AP is enabled(i've attached a screenshot). Even so i can not connect with any device to the ap. Perhaps is there something i haven't installed?


i copy the code. and type chmod-R 755
if i start it. i get the following error:

root@HaRuVerhuur-Matrix:/home# ./ testing aptest
You need to pass a password!
sudo ./ yourChosenPassword [apName]

Grees Ruben Dijk

marcelerkel commented Apr 21, 2016

Try changing line 8 to:

if [[ $# -lt 1 ]];

The current code checks if the number of command line parameters is not equal to one (-ne 1). Since you specify the optional apName parameter, you have two parameters which causes the test to fail and hence the 'You need to pass a password!' error message.
Even better would be to test for less than one or greater than two, but I leave that as an exercise for @Lewiscowles1986 :)

_Author FYI_
I won't be taking part in "exercises" or assignments 😉

csatt commented Jun 4, 2016

This works for me, but only if I add the following line to rc.local:

service hostapd start

I put it right before the "service dnsmasq restart".

imac8t commented Jun 11, 2016

Syntax error: "fi" unexpected (expecting "then")

How can switch wifi from "access point" mode to "standard" mode ?
Is it enough if i just remove lines from rc.local file and reboot?
Is there any other service like "dnsmasq" that needs to be swicthed off in "standard" mode?

I have this problem.
pi@raspberrypi:~ $ sudo python
File "", line 3
if [ "$EUID" -ne 0 ]
SyntaxError: invalid syntax
pi@raspberrypi:~ $


ghost commented Jun 28, 2016

@lvhailong This is a shell script as denoted by the shebang at the top and .sh extension.


Lewiscowles1986 commented Jun 29, 2016

Thanks @usertaken

@navaneetharaopy you would have to edit the /etc/rc.local, but also disable hostapd and dnsmasq services

sed -i -- 's/wlan0/wlan999/g' /etc/rc.local should do for rc.local, then sed -i -- 's/wlan999/wlan0/g' /etc/rc.local if you want to restore on wlan0


Lewiscowles1986 commented Jun 29, 2016


This works for me, but only if I add the following line to rc.local:

service hostapd start

I put it right before the "service dnsmasq restart".

that should not be required as dnsmasq is started on the next line. Hostapd is started within the script too!

csatt commented Jun 30, 2016

I see where dnsmasq is started. Where is hostapd started? The "hostapd - B ..." command on the last line fails (for me) unless the service is started first. Do you have to run "sudo update-rc.d hostapd enable" or something like that for it to work without explicitly starting the service in rc.local?


I'm having a really similar problem, getting the errors

Failed to create interface mon.wlan0: 95 (Operation not supported)
wlan0: could not connect to kernel driver

but not the other stuff.

Anyone have a solution?

I tried sudo hostapd /etc/hostapd/hostapd.conf
Then i got

ioctl[SIOCSIWMODE]: Invalid argument
Could not set interface to mode(3)!
Could not set interface to master mode!
rtl871xdrv driver initialization failed.

No one can help with @adiroman, @SammoMate AND my problem?


Lewiscowles1986 commented Aug 27, 2016

@marianomarini @adiroman @SammoMate I just used the script on a fresh jessie-lite image from the raspberry pi website. The only issue I encountered was one line for the access-point name which should now be fixed. This works with fresh jessie-lite image, not sure what could be interfering

Everything works perfectly, but I can not access the internet on my phone when connected to my pi. What should I change in order to be able to connect to the internet?

9H5G commented Sep 6, 2016

Many thanks @lewiscoles1986 - worked out of the box! Thank you :)

(If the bridge script were to come along that would be fantastic :))


Lewiscowles1986 commented Sep 8, 2016

I'll add the bridge script soon and link here

mehranexpert commented Sep 8, 2016

Not work for me .

root@kali:~/git/ap# ./  testtest mehran
./ line 19: rPi3=mehran: command not found
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  freeglut3 libgnutls-deb0-28 libpng12-0 libpoppler57
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
0 upgraded, 0 newly installed, 1 to remove and 446 not upgraded.
After this operation, 981 kB disk space will be freed.
(Reading database ... 233701 files and directories currently installed.)
Removing hostapd (1:2.5-2+v2.4-2) ...
Purging configuration files for hostapd (1:2.5-2+v2.4-2) ...
dpkg: warning: while removing hostapd, directory '/etc/hostapd' not empty so not removed
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (230-7) ...
Reading package lists... Done
Building dependency tree       
Reading state information... Done
dnsmasq is already the newest version (2.76-4).
The following packages were automatically installed and are no longer required:
  freeglut3 libgnutls-deb0-28 libpng12-0 libpoppler57
Use 'apt autoremove' to remove them.
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 446 not upgraded.
Need to get 0 B/491 kB of archives.
After this operation, 981 kB of additional disk space will be used.
Selecting previously unselected package hostapd.
(Reading database ... 233677 files and directories currently installed.)
Preparing to unpack .../hostapd_1%3a2.5-2+v2.4-2_armhf.deb ...
Unpacking hostapd (1:2.5-2+v2.4-2) ...
Processing triggers for systemd (230-7) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up hostapd (1:2.5-2+v2.4-2) ...
update-rc.d: We have no instructions for the hostapd init script.
update-rc.d: It looks like a network service, we disable it.
insserv: warning: current start runlevel(s) (empty) of script `hostapd' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `hostapd' overrides LSB defaults (0 1 6).
Processing triggers for systemd (230-7) ...
All done!


Lewiscowles1986 commented Sep 12, 2016

root@kali yeah, looks like raspbian @mehranexpert... this is for specific hardware and software _RASPBERRY PI 3 & OFFICIAL RASPBIAN_

You might want to checkout

doktor500 commented Sep 26, 2016

I have the same issue than @adiroman

I install the latest version of RASPBIAN JESSIE LITE on my Raspberry Pi Model 3
I ssh into it and run:

chmod +x
sudo apt-get update
sudo ./ password apname

All seems to be good, but when I run sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf

This is the output:

Configuration file: /etc/hostapd/hostapd.conf
Failed to create interface mon.wlan0: -95 (Operation not supported)
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr b8:27:eb:fc:f9:b4 and ssid "dmcom-mad"
wlan0: interface state UNINITIALIZED->ENABLED

Lewiscowles1986 commented Oct 3, 2016

why are you running anything, just reboot the pi, it should automatically start... I'm going to make a slightly modified one using systemd service instead of hacky approach to /etc/rc.local, but I've just run this successfully on the pixel release and the latest jessie lite release.


Lewiscowles1986 commented Oct 3, 2016


cd /boot
sudo reboot
sudo cp /boot/wpa_supplicant.conf /etc/wpa_supplicant/
sudo reboot
chmod +x  2cOGZuL
sudo apt update
sudo 2cOGZuL password apname

I did see some error messages on boot, but I still have the apname show up in my list (which is new for me, as I generally pick one)



Lewiscowles1986 commented Oct 4, 2016

Also there is now a newer version using systemd, and this companion script for anyone wanting to pass through an adapter.

simar88 commented Oct 6, 2016

Hello everyone, i'll always receive "errors were encountered while processing:hoastapd" during the setup.
Do you have any idea?
Thanks in advance,

Dear All,

I want to use Rpi 3's wifi in both Access Point and Station mode simultaneously or at a time one but without reconfigure(reboot the pi).And now, i did to both mode individual configure and work its fine but problem is every time configure change for individual mode.
Please guide me.

H1ggX commented Oct 10, 2016

How to setting up a kind of bridge between eth0 and wlan0 like @vhgarandil told. I don't get it it's not working for me. Please you upload a kind of other script just for doing a bridge? (I'd like to access to internet by the AP) I'm still waiting for it. Keep updating i like what you do @Lewiscowles1986!


Lewiscowles1986 commented Oct 13, 2016

@nenoork, there is another script linked above... Please go to this url


Lewiscowles1986 commented Oct 13, 2016

@PratikGajera I'm really sorry I don't understand what you are asking

I am asking about that which way to configure wifi that run it both mode station and Access Point.

dreetie commented Oct 22, 2016

Script runs great, but how do you revert back to station mode?


Lewiscowles1986 commented Oct 28, 2016

systemctl disable hostapd
systemctl disable dnsmasq

and adding

wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf to /etc/interfaces should do it. Really at the point you are doing that this quick and dirty version won't work too well for you

Just ran this on my raspberry pi 3 and now I no longer have a wifi interface in raspbian. Does this require having another usb wifi adapter plugged in?

Also, How do I completely remove this?


Lewiscowles1986 commented Oct 31, 2016

@goodpunk6 this does not require a second wifi adapter unless using as a range extender...

@goodpunk6 to remove this try the following

sudo apt-get remove --purge hostapd dnsmasq

then add wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf to /etc/interfaces inside the /dev/wlan0 section

alternatively backup your home folder and re-flash the jessie-pixel or jessie-lite image

It would be really nice to have a way to automacally revert the chages made by this script, so that one could get back to normal use of your RPi as easily.

dreetie commented Nov 3, 2016

@goodpunk6 I've got the same problem as you: no wireless interfaces found

how i connect rspi3 to a network?


Lewiscowles1986 commented Nov 8, 2016

@heniotierra. More than happy to see a fork that does. I don't think shell is a good place to do this, it's more of a DSC deal where existing tools could take this and make for example an ansible playbook that stacks little scripts like this to specify a desired state of a raspberry pi

I'm having the same issue as @adiroman and @doktor500.
Apologies if I missed it but did either of you get a resolution to your problem?

Clint67 commented Jan 11, 2017

GREAT JOB my firend!!
I was struggling among a lot of sligtly different directions to get my Rpi3 working as an AP.
Some of them didn't work at all, some just get the Rpi3 working as AP ignoring the other commands to route traffic to share the eth0 internet connection.
Your script worked at first shot and combined with your other script at
I got it working also as a AP with traffic forwarding,...

...but my question is:

Can the Rpi3 work like any other 'out of the box' AP on the market?

I mean, 'transparent' like any AP I can buy on store shelfs? So, the wifi devices connected to the AP 'share' the same IP class as the primary router. Or, even better, get the IP address from the DHCP working on the primary router?

I am quite out of the IP configurations world, and I am just wondering if I can set the static IP class of the wlan0 to join my home lan configuration and have wireless devices on the same subnet of the primary router.

This because I need to send/receive some UDP packets to devices 'wifi connected' to the lan through the Rpi (on other ports than the 80)
Any idea is welcome...

And, once again, thank you very very much for sharing your code!


Lewiscowles1986 commented Jan 14, 2017

@Clint67 thanks 👍

You can alter the dnsmasq config file to allocate to the same subnet if that is what you'd like. You could also adjust the mask or change the rules from the other script but I've never attempted nor have the inclination to make it compete with AP makers. Fork it and share your changes with the world!


Hi Lewis,

First off thank you for creating such an easy to use script and helping troubleshoot. I'm trying to set up a new Pi3 to create a local network for several other Pi3s and I stumbled upon your script (among several sketchy or out-of-date tutorials). I ran the script on a brand new installation of Rasbian using NOOBS but I'm having a couple issues. If I don't reboot after the script runs then I can see the newly created AP on my phone and laptop, but they are not being assigned an IP address. If I reboot the Pi3 then the AP doesn't even show up.

I'm a bit of a Linux noob so I'm unsure of how to go about troubleshooting; it appears as though hostapd and dnsmasq are both running after the reboot but they aren't functioning properly. Do these programs create a log file or anything I can look at? Is there any monitoring feature so I can see error/other messages in real-time?

Thanks again!

tverboon commented Jan 21, 2017

Great script! Only thing I had to configure was the following:

sudo nano /etc/default/hostapd

Otherwise the systemd service would exit right away. Not sure why, because the config is passed as a parameter.


Lewiscowles1986 commented Jan 25, 2017

@tverboon that is strange, as you say we specify hostapd inside the service we completely generate from scratch

@dfarley1 this wasn't written for NOOBS and hasn't been tested on NOOBS, it's written for jessie pixel and jessie lite

On logging I haven't set it up, but try sudo ls -lhaR /var/log it should recursively list all log files. If there are not specific logs it may end up in syslog (I Have to admit I pretty much record what I do to get working, I'm by no means an expert with either. Much like yourself I became fed-up of tutorials asking people to attend the installation and have more than minimal input)

SamGG commented Feb 22, 2017

Thanks for the script!
I ran it step by step on a minibian after having installed the wifi
Nevertheless, I didn't use the line 67, because it does not make sense to me.
@adiroman, @doktor500, @botzen67 I encountered the same error, but it disappeared after a couple of reboot
NB: the length of the password must be at least 8 characters
I added a command to prevent energy saver from stopping the wifi interface:

ikester commented Mar 5, 2017

Thank you for this script. I was having trouble getting this to work after boot using 'hypriot'. If I manually restarted the service I could see the SSID but after a fresh reboot it just wouldn't show up. There were no errors in the logs and the output look exactly the same as when it worked manually. I figured it was a timing issue with the startup sequence. I finally got it to work by changing line 3 of the Systemd unit file to this instead:
It now shows up just fine after a reboot.

How to disable the AP script after use?

This is great! I ran into a problem however because the password length must be at least 8 character. It'd be great to add a check like:

if [ $APPASS -lt 8 ]
  echo "Password must be greater than 8 characters"

Otherwise one must manually run /usr/sbin/hostapd -B /etc/hostapd/hostapd.conf -P /var/run/ to see the error (and the AP will silently fail to start).

reinhart1010, I copied the dhcpcd.conf and interfaces files to dhcpcd.conf.station and interfaces.station before I ran the script
and then copied them to dhcpcd.conf.access_point and interfaces.access_point after I ran the script. Then I have two little scripts in the same directory I can run to switch back and forth:


cp dhcpcd.conf.station /etc/dhcpcd.conf
cp interfaces.station /etc/network/interfaces
systemctl disable hostapd
shutdown -r now


cp dhcpcd.conf.access_point /etc/dhcpcd.conf
cp interfaces.access_point /etc/network/interfaces
systemctl enable hostapd
shutdown -r now

kaz325 commented Mar 30, 2017

Did you succeed with this setup? if so, could you share what you did?

xsteacy commented May 5, 2017

when running:
sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf
I got:

Configuration file: /etc/hostapd/hostapd.conf
Failed to create interface mon.wlan0: -95 (Operation not supported)
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr b8:27:eb:69:ae:44 and ssid "testing"
wlan0: interface state UNINITIALIZED->ENABLED

The AP is working, I can connect to it but there is no internet access.

I use an RPI3 with the build-in wireless and the latest Raspbian with Pixel

Help will be very much appreciated, Thnk you

Thank you! This worked for me. Also, thank you for not adding the wireless->ethernet bridge. A lot of people want this but in my case, I'm only providing an interface to my device.

Setting up captive portal would be helpful, so that a browser automatically opens and loads the main page from the server running on the RPi.

For captive portal, try adding in dnsmasq.conf

address=/#/<address of your ap>

MrWeax1 commented Jun 17, 2017

Hi there! I was wondering how I could make the SSID hidden, as in it isn't broadcast to all computers and you have to manually enter the SSID on the connecting devices.

w7efs commented Jun 22, 2017

ignore_broadcast_ssid=0 in /etc/hostapd/hostapd.conf should hide the SSID.

thank you very much for sharing this! :)
but i've and error : 6: [: Illegal number: 11: [[: not found 21: [[: not found Reading package lists... Done
how can I resolve this ?


Lewiscowles1986 commented Aug 21, 2017

don't know what people are running to get some of these errors. I run stock raspbian-lite, and have now got this working with the stretch distro

I copy a wpa_supplicant.conf to the pi with my wifi details, create a file named ssh both on /boot, power it on, wait a few seconds

From my PC I then run

ssh pi@raspberrypi.local  -o UserKnownHostsFile=/dev/null

Once connected to the Pi I run

curl -sSL | sudo bash $0 password rPi3AP

sudo wget -q -O /usr/lib/dhcpcd5/dhcpcd
sudo chmod +x /usr/lib/dhcpcd5/dhcpcd

Then I reboot and it works

Hi, does it have a feature that if I connect ethernet cable on RPi3 and it gives internet connection like a router?


Lewiscowles1986 commented Sep 8, 2017

@mrsimple97 it's not a bridge or wifi range extender, it's just an access point. I use it to make fake internet / network.

You can try combining with to make this a bridge, however, YMMV depending upon interface names

Hello, I have tried to run your script but eth0 disappear. I have also written a script with the same base and eth0 also disappear. Have you an idea where is the trouble?


Lewiscowles1986 commented Sep 11, 2017

@jonathandreyer do you have a .bash_history I can look at. Also what is the output of ip -a command (it's the new ifconfig). Please attach to a gist or pastebin and link that here 😉

buckster123 commented Sep 16, 2017

This script works fine with Ubuntu Mate 16.04.3 LTS on rpi3.
Edit: I wanted to use this to trick my chromecast, but it is a No Go. Ho on earth do i reverse what the script did to have wlan works as before script was applied?
Edit: Please forgive my noobieness.

Edit: Figured it out :-D


Lewiscowles1986 commented Sep 18, 2017

👍 @buckster123 glad you worked it out. Do you think this would benefit from an uninstall action?

JddAndrewLauren commented Sep 21, 2017

This works well for me, correctly setting up the wireless AP, but I also lose my ethernet connection. If I comment out the lines added in the /etc/network/interfaces file and reboot, the AP goes down as expected and I get ethernet back.

Here's a pastebin of my ifconfig -a. Running on a rpi3 on Raspbian Stretch with desktop. Thanks.

Edit: I got the ethernet working again after adding these lines to /etc/network/interfaces:
auto eth0
iface eth0 inet dhcp

schmi85 commented Sep 28, 2017

At the very top

# This version uses September 2017 august stretch image, please use this image

So which exact release date is meant with that? 2017-09-07 or 2017-08-16

Thanks for clarification!

carlpoole commented Oct 6, 2017

Spent a good couple of hours trying to do all this manually searching Google then stumbled across this script. Thanks!

I had previously setup bridging between eth0 and wlan0 with the iptables commands but after rebooting from running the script I noticed my eth0 disappeared from ifconfig so I added the following to /etc/network/interfaces underneath what your script added in there and it worked. Seems related to what @JddAndrewLauren mentioned.

auto eth0
    allow-hotplug eth0
    iface eth0 inet dhcp

Lewiscowles1986 commented Oct 12, 2017

Oh btw fixes stretch release network config (which sucks)

Thanks for the script. Getting an AP up on an rpi3 w/ stretch is a BEAR. I used most of your initial script (above) and your most recent script on the stretch network config (here) BUT had to add hostapd -dd /etc/hostapd/hostapd.conf > /dev/null to my rc.local file. Without it the pi boots up and hostapd shows up as "active" "exited" and the AP never starts. Thanks again.

stsdc commented Oct 24, 2017

Worked perfect until now. Stuck at obtaining IP address. Do You know what it might be?

@stsdc try changing this:
to this:
Seemed to work for me. I think it has to do with compatibility of different WiFi devices.

@Lewiscowles1986 This script works well! I noticed though that now it disables scanning for other APs on wlan0. I understand that this is necessary to start the AP but is there a way to disable the AP temporarily to access WiFi? I noticed that the AP starts at reboot so I'm kind of at a loss as to what to do.

vicatcu commented Oct 31, 2017

Not sure it matters, but when I ran this just now, the first output I saw after a bit was this:

E: Failed to fetch  Hash Sum mismatch
   Hashes of expected file:
    - Filesize:122952 [weak]
    - SHA256:5ec0dba10fe405527b7a5cea245c60d33f6b8d10f0042b0a0046b4b203e33d3c
    - SHA1:b219b21de30952d1b3813fc1942544a63847ddd7 [weak]
    - MD5Sum:e4f5f4b020d75bf7ab5411093d34af8e [weak]
   Hashes of received file:
    - SHA256:753dccd1ae7a297ed4d484bafbe6d9e385489346ce898880e1d951ebddbf1267
    - SHA1:90c0f040f4d4d1d81f8e60d400026a88683503b9 [weak]
    - MD5Sum:a551bc63947e667bb483b8dd528f4b3c [weak]
    - Filesize:98304 [weak]
   Last modification reported: Tue, 31 Oct 2017 12:39:08 +0000
   Release file created at: Tue, 31 Oct 2017 12:26:45 +0000
E: Some index files failed to download. They have been ignored, or old ones used instead.

To be clear this didn't seem to have any adverse effects, and I did a sudo apt-get update && sudo apt-get upgrade afterwards to be on the safe side.

This even worked on the tinkerboard right out of the box, thanks a lot!

It hosts ap, but if i try to connect to it from other devices, i cant.. it just sais connecting...

joachimpr commented Dec 26, 2017

Hi there. Fantastic script! I have tried countless tutorial on how to get the AP set up in stretch and none of them worked. This script is the first to show an ssid at all! And I can connect to it. I only have one thing to sort ou to fit my needs and Im a bit confused.

I'm also creating a captive portal on the pi. I want a client to connect to the pi and be able to access the portal. Hopefully it can open automatically using the solution I saw in the comments when a client connects to the AP.

I dont want the client that is connected to the AP (pi) to have internet access so no bridging required.

I do however need the AP (pi) to have an internet connection also via wifi so that it can connect to the internet. I have a mifi router which it has to connect to. It would be fantastic if it would also connect through ethernet. I basically need the onboard wifi to connect to a router as well as provide an access point. I saw someone in the comments asking about the same thing (simultanious station/AP mode)

I have installed this script and it works great but it remòves the internet connection via wifi. I have tried some of the solutions in the comments after installing this script such as adding the wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf file to /etc/network/interfaces file under wlan0 and all the static IP stuff but I cannot get the internet connection back.

When I add wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf, the access point disappears, iw wlan0 link shows its connected to my router but I still don't have internet access.

When I add wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf, the access point is still available but iw wlan0 link show not connected and you guessed int, no internet connection.

Any help on how to get the internet connection back with an available wifi AP would be much appreciated.

Thanks again for these awesome scripts!

aloboa commented Dec 27, 2017

Many thanks for your script that looks exactly like what I need to run a remote desktop for my RPi3 using an android device on the field, away of wifi networks.
But I'm afraid I need a bit more of help...

I have downloaded and run, then downloaded and copied it to /usr/lib/dhcpcd5/dhcpcd (as you mention in your comment of 12 Oct).
Unfortunately, I reboot but I get no AP: the 2 arrows sign has two "X" and indicates "eth0: link is down", with no mention to wlan0.
The network defined at running is not visible by any other machine.
I guess there is something I'm missing.
I'm running raspbian stretch 9.3 released 2017-11-29 kernel version 4.9
Thanks for your help

banak0 commented Jan 11, 2018

Thanks for the useful script. I wanted eth0 working with internet and wireless AP without internet access. I my case, after reboot Wireless AP created as I needed but eth0 didnot work.
Then I changed /etc/network/interfaces as below:

source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static

And sudo raspi-config > Advanced Options > Network interface names > Yes

And finally edited /lib/udev/rules.d/73-usb-net-by-mac.rules by changing NAME="$env{ID_NET_NAME_MAC}" to NAME="eth0".

After Reboot all is good as I needed.


Lewiscowles1986 commented Jan 19, 2018


To disable AP mode after install

sudo update-rc.d hostpad disable
sudo update-rc.d dnsmasq disable

To enable AP mode after install

sudo update-rc.d hostpad enable
sudo update-rc.d dnsmasq enable

You'd also have to edit /etc/network/interfaces. The easiest way to do this would be to copy the file before running this script to somewhere safe, using links to link to the config you need

sudo mkdir -p /etc/pi-ap
cp /etc/network/interfaces /etc/pi-ap/standard-config

chmod +x
sudo apt-get update
sudo ./ password apname

cp /etc/network/interfaces /etc/pi-ap/ap-mode-config

rm /etc/network/interfaces
ln -f /etc/pi-ap/ap-mode-config /etc/network/interfaces

# Probably reboot here

then as well as the above for enabling and disabling, you can exchange link targets between ap-mode and stock /etc/network/interfaces file. It's a bit advanced, but doable.

You, sir, are awesome. I've been fighting AP configuration for months, and NOTHING. WAS. WORKING.
But I ran this script on a fresh Raspbian-Stretch-Lite image and it worked in one shot. Fantastic.
I'd buy you a beer if I could.

Aimma commented Feb 23, 2018

Hi there , can you please tell how can I undo all the settings done by this code?

Aimma commented Feb 23, 2018

This file has resulted in no internet connectivity to my raspberry pi. It says Connection to dhcpcd lost. I'm totally clueless what to do now. Pleaseeeee helllpppp!!!! Plus the raspberry pi didn't become the access point

For anyone who ran into the same problem as @marianomarini @adiroman @SammoMate

I found this:

Just add this to your /etc/dhcpcd.conf file
denyinterfaces wlan0
Then restart the pi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment