Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Raspberry Pi 3 access-point-setup
#!/bin/bash
#
# This version uses September 2017 august stretch image, please use this image
#
if [ "$EUID" -ne 0 ]
then echo "Must be root"
exit
fi
if [[ $# -lt 1 ]];
then echo "You need to pass a password!"
echo "Usage:"
echo "sudo $0 yourChosenPassword [apName]"
exit
fi
APPASS="$1"
APSSID="rPi3"
if [[ $# -eq 2 ]]; then
APSSID=$2
fi
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
interface=wlan0
dhcp-range=10.0.0.2,10.0.0.5,255.255.255.0,12h
EOF
cat > /etc/hostapd/hostapd.conf <<EOF
interface=wlan0
hw_mode=g
channel=10
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
wpa_passphrase=$APPASS
ssid=$APSSID
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
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
address 10.0.0.1
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
EOF
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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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.

Owner

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.

@vhgarandil

This comment has been minimized.

Show comment
Hide comment
@vhgarandil

vhgarandil Mar 10, 2016

I suggest to share the eth0 connection that you add
net.ipv4.ip_forward=1
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.

vhgarandil commented Mar 10, 2016

I suggest to share the eth0 connection that you add
net.ipv4.ip_forward=1
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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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

Owner

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

@ipplepen

This comment has been minimized.

Show comment
Hide comment
@ipplepen

ipplepen Mar 17, 2016

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!

ipplepen commented Mar 17, 2016

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!

@bitterypaul

This comment has been minimized.

Show comment
Hide comment
@bitterypaul

bitterypaul Mar 24, 2016

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

bitterypaul commented Mar 24, 2016

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

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Mar 25, 2016

Hi @ipplepen

So once you run the script, you can run
sudo rPi3-ap-setup.sh password wifiapname
and it will setup with the password "password", and the SSID "wifiapname"

Owner

Lewiscowles1986 commented Mar 25, 2016

Hi @ipplepen

So once you run the script, you can run
sudo rPi3-ap-setup.sh password wifiapname
and it will setup with the password "password", and the SSID "wifiapname"

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Mar 25, 2016

@bitterypaul

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.

Owner

Lewiscowles1986 commented Mar 25, 2016

@bitterypaul

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

This comment has been minimized.

Show comment
Hide comment
@elck

elck 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?

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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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

Owner

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

This comment has been minimized.

Show comment
Hide comment
@crone

crone 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.

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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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

Owner

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

@adiroman

This comment has been minimized.

Show comment
Hide comment
@adiroman

adiroman Apr 11, 2016

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?
capture

adiroman commented Apr 11, 2016

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?
capture

@RubenDijk

This comment has been minimized.

Show comment
Hide comment
@RubenDijk

RubenDijk Apr 18, 2016

Hello,

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

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

Grees Ruben Dijk

RubenDijk commented Apr 18, 2016

Hello,

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

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

Grees Ruben Dijk

@marcelerkel

This comment has been minimized.

Show comment
Hide comment
@marcelerkel

marcelerkel Apr 21, 2016

@RubenDijk
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 ๐Ÿ˜‰

marcelerkel commented Apr 21, 2016

@RubenDijk
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

This comment has been minimized.

Show comment
Hide comment
@csatt

csatt 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".

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

This comment has been minimized.

Show comment
Hide comment
@imac8t

imac8t Jun 11, 2016

Syntax error: "fi" unexpected (expecting "then")
why๏ผŸ

imac8t commented Jun 11, 2016

Syntax error: "fi" unexpected (expecting "then")
why๏ผŸ

@navaneetharaopy

This comment has been minimized.

Show comment
Hide comment
@navaneetharaopy

navaneetharaopy Jun 23, 2016

Hi,
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?

navaneetharaopy commented Jun 23, 2016

Hi,
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?

@lvhailong

This comment has been minimized.

Show comment
Hide comment
@lvhailong

lvhailong Jun 27, 2016

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

lvhailong commented Jun 27, 2016

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

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 28, 2016

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

ghost commented Jun 28, 2016

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

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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

Owner

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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Jun 29, 2016

@csatt

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!

Owner

Lewiscowles1986 commented Jun 29, 2016

@csatt

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

This comment has been minimized.

Show comment
Hide comment
@csatt

csatt 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?

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?

@SammoMate

This comment has been minimized.

Show comment
Hide comment
@SammoMate

SammoMate Jul 12, 2016

@adiroman

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

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

but not the other stuff.

Anyone have a solution?

SammoMate commented Jul 12, 2016

@adiroman

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

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

but not the other stuff.

Anyone have a solution?

@gabylan12

This comment has been minimized.

Show comment
Hide comment
@gabylan12

gabylan12 Jul 30, 2016

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

drv->ifindex=3
l2_sock_recv==l2_sock_xmit=0x0xfc5648
ioctl[SIOCSIWMODE]: Invalid argument
Could not set interface to mode(3)!
Could not set interface to master mode!
rtl871xdrv driver initialization failed.

gabylan12 commented Jul 30, 2016

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

drv->ifindex=3
l2_sock_recv==l2_sock_xmit=0x0xfc5648
ioctl[SIOCSIWMODE]: Invalid argument
Could not set interface to mode(3)!
Could not set interface to master mode!
rtl871xdrv driver initialization failed.

@marianomarini

This comment has been minimized.

Show comment
Hide comment
@marianomarini

marianomarini Aug 5, 2016

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

marianomarini commented Aug 5, 2016

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

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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

Owner

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

@vemfanvet

This comment has been minimized.

Show comment
Hide comment
@vemfanvet

vemfanvet Sep 6, 2016

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?

vemfanvet commented Sep 6, 2016

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

This comment has been minimized.

Show comment
Hide comment
@9H5G

9H5G 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 :))

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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Sep 8, 2016

I'll add the bridge script soon and link here

Owner

Lewiscowles1986 commented Sep 8, 2016

I'll add the bridge script soon and link here

@mehranexpert

This comment has been minimized.

Show comment
Hide comment
@mehranexpert

mehranexpert Sep 8, 2016

Not work for me .

root@kali:~/git/ap# ./rPi3-ap-setup.sh  testtest mehran
./rPi3-ap-setup.sh: 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:
  hostapd*
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:
  hostapd
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!

mehranexpert commented Sep 8, 2016

Not work for me .

root@kali:~/git/ap# ./rPi3-ap-setup.sh  testtest mehran
./rPi3-ap-setup.sh: 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:
  hostapd*
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:
  hostapd
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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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 resin.io

Owner

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 resin.io

@doktor500

This comment has been minimized.

Show comment
Hide comment
@doktor500

doktor500 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:

wget https://gist.githubusercontent.com/Lewiscowles1986/fecd4de0b45b2029c390/raw/71a732423f7302cd7dd441e9c98f38a7ec471b4c/rPi3-ap-setup.sh
chmod +x rPi3-ap-setup.sh
sudo apt-get update
sudo ./rPi3-ap-setup.sh 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
wlan0: AP-ENABLED

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:

wget https://gist.githubusercontent.com/Lewiscowles1986/fecd4de0b45b2029c390/raw/71a732423f7302cd7dd441e9c98f38a7ec471b4c/rPi3-ap-setup.sh
chmod +x rPi3-ap-setup.sh
sudo apt-get update
sudo ./rPi3-ap-setup.sh 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
wlan0: AP-ENABLED
@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Oct 3, 2016

_.bash_history_

ping google.com
cd /boot
ls
sudo reboot
sudo cp /boot/wpa_supplicant.conf /etc/wpa_supplicant/
sudo reboot
wget http://bit.ly/2cOGZuL
chmod +x  2cOGZuL
sudo apt update
sudo 2cOGZuL password apname
reboot

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)

image

Owner

Lewiscowles1986 commented Oct 3, 2016

_.bash_history_

ping google.com
cd /boot
ls
sudo reboot
sudo cp /boot/wpa_supplicant.conf /etc/wpa_supplicant/
sudo reboot
wget http://bit.ly/2cOGZuL
chmod +x  2cOGZuL
sudo apt update
sudo 2cOGZuL password apname
reboot

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)

image

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Oct 4, 2016

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

Owner

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

This comment has been minimized.

Show comment
Hide comment
@simar88

simar88 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,
Simone

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,
Simone

@PratikGajera

This comment has been minimized.

Show comment
Hide comment
@PratikGajera

PratikGajera Oct 7, 2016

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.

PratikGajera commented Oct 7, 2016

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

This comment has been minimized.

Show comment
Hide comment
@H1ggX

H1ggX 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!

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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Oct 13, 2016

@nenoork, there is another script linked above... Please go to this url https://gist.github.com/Lewiscowles1986/f303d66676340d9aa3cf6ef1b672c0c9

Owner

Lewiscowles1986 commented Oct 13, 2016

@nenoork, there is another script linked above... Please go to this url https://gist.github.com/Lewiscowles1986/f303d66676340d9aa3cf6ef1b672c0c9

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Oct 13, 2016

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

Owner

Lewiscowles1986 commented Oct 13, 2016

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

@PratikGajera

This comment has been minimized.

Show comment
Hide comment
@PratikGajera

PratikGajera Oct 19, 2016

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

PratikGajera commented Oct 19, 2016

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

@dreetie

This comment has been minimized.

Show comment
Hide comment
@dreetie

dreetie Oct 22, 2016

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

dreetie commented Oct 22, 2016

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

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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

Owner

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

@goodpunk6

This comment has been minimized.

Show comment
Hide comment
@goodpunk6

goodpunk6 Oct 30, 2016

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?

goodpunk6 commented Oct 30, 2016

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?

@goodpunk6

This comment has been minimized.

Show comment
Hide comment
@goodpunk6

goodpunk6 Oct 30, 2016

Also, How do I completely remove this?

goodpunk6 commented Oct 30, 2016

Also, How do I completely remove this?

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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

Owner

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

@heniotierra

This comment has been minimized.

Show comment
Hide comment
@heniotierra

heniotierra Nov 2, 2016

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.

heniotierra commented Nov 2, 2016

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

This comment has been minimized.

Show comment
Hide comment
@dreetie

dreetie Nov 3, 2016

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

dreetie commented Nov 3, 2016

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

@jimRushan

This comment has been minimized.

Show comment
Hide comment
@jimRushan

jimRushan Nov 4, 2016

how i connect rspi3 to a network?

jimRushan commented Nov 4, 2016

how i connect rspi3 to a network?

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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

Owner

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

@botzen67

This comment has been minimized.

Show comment
Hide comment
@botzen67

botzen67 Nov 28, 2016

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?

botzen67 commented Nov 28, 2016

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

This comment has been minimized.

Show comment
Hide comment
@Clint67

Clint67 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
https://gist.github.com/Lewiscowles1986/f303d66676340d9aa3cf6ef1b672c0c9
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!

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
https://gist.github.com/Lewiscowles1986/f303d66676340d9aa3cf6ef1b672c0c9
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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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!

๐Ÿ˜‰

Owner

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!

๐Ÿ˜‰

@dfarley1

This comment has been minimized.

Show comment
Hide comment
@dfarley1

dfarley1 Jan 17, 2017

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!

dfarley1 commented Jan 17, 2017

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

This comment has been minimized.

Show comment
Hide comment
@tverboon

tverboon Jan 21, 2017

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

sudo nano /etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"

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

tverboon commented Jan 21, 2017

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

sudo nano /etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"

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

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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)

Owner

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

This comment has been minimized.

Show comment
Hide comment
@SamGG

SamGG Feb 22, 2017

Thanks for the script!
I ran it step by step on a minibian https://minibianpi.wordpress.com/ after having installed the wifi https://minibianpi.wordpress.com/how-to/rpi3/
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: http://raspberrypi.stackexchange.com/questions/43473

SamGG commented Feb 22, 2017

Thanks for the script!
I ran it step by step on a minibian https://minibianpi.wordpress.com/ after having installed the wifi https://minibianpi.wordpress.com/how-to/rpi3/
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: http://raspberrypi.stackexchange.com/questions/43473

@ikester

This comment has been minimized.

Show comment
Hide comment
@ikester

ikester 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:
After=network.target
It now shows up just fine after a reboot.

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:
After=network.target
It now shows up just fine after a reboot.

@reinhart1010

This comment has been minimized.

Show comment
Hide comment
@reinhart1010

reinhart1010 Mar 7, 2017

How to disable the AP script after use?

reinhart1010 commented Mar 7, 2017

How to disable the AP script after use?

@mseltzer94

This comment has been minimized.

Show comment
Hide comment
@mseltzer94

mseltzer94 Mar 27, 2017

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 ]
then
  echo "Password must be greater than 8 characters"
  exit
fi

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

mseltzer94 commented Mar 27, 2017

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 ]
then
  echo "Password must be greater than 8 characters"
  exit
fi

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

@ACI-leecooper

This comment has been minimized.

Show comment
Hide comment
@ACI-leecooper

ACI-leecooper Mar 28, 2017

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:

restart_station

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

restart_access_point

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

ACI-leecooper commented Mar 28, 2017

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:

restart_station

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

restart_access_point

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

This comment has been minimized.

Show comment
Hide comment
@kaz325

kaz325 Mar 30, 2017

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

kaz325 commented Mar 30, 2017

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

@xsteacy

This comment has been minimized.

Show comment
Hide comment
@xsteacy

xsteacy 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
wlan0: AP-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

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
wlan0: AP-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

@rm-rf-etc

This comment has been minimized.

Show comment
Hide comment
@rm-rf-etc

rm-rf-etc Jun 9, 2017

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.

rm-rf-etc commented Jun 9, 2017

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.

@japita-se

This comment has been minimized.

Show comment
Hide comment
@japita-se

japita-se Jun 14, 2017

For captive portal, try adding in dnsmasq.conf

address=/#/<address of your ap>

japita-se commented Jun 14, 2017

For captive portal, try adding in dnsmasq.conf

address=/#/<address of your ap>

@MrWeax1

This comment has been minimized.

Show comment
Hide comment
@MrWeax1

MrWeax1 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.

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

This comment has been minimized.

Show comment
Hide comment
@w7efs

w7efs Jun 22, 2017

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

w7efs commented Jun 22, 2017

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

@brahmanggi

This comment has been minimized.

Show comment
Hide comment
@brahmanggi

brahmanggi Jul 13, 2017

hi,
thank you very much for sharing this! :)
but i've and error :

rPi3-ap-setup.sh: 6: [: Illegal number: rPi3-ap-setup.sh: 11: rPi3-ap-setup.sh: [[: not found rPi3-ap-setup.sh: 21: rPi3-ap-setup.sh: [[: not found Reading package lists... Done
how can I resolve this ?

brahmanggi commented Jul 13, 2017

hi,
thank you very much for sharing this! :)
but i've and error :

rPi3-ap-setup.sh: 6: [: Illegal number: rPi3-ap-setup.sh: 11: rPi3-ap-setup.sh: [[: not found rPi3-ap-setup.sh: 21: rPi3-ap-setup.sh: [[: not found Reading package lists... Done
how can I resolve this ?

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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 https://gist.github.com/Lewiscowles1986/fecd4de0b45b2029c390/raw/0c8b3af3530a35db9ab958defe9629cb5ea99972/rPi3-ap-setup.sh | sudo bash $0 password rPi3AP

sudo wget -q https://gist.githubusercontent.com/Lewiscowles1986/390d4d423a08c4663c0ada0adfe04cdb/raw/5b41bc95d1d483b48e119db64e0603eefaec57ff/dhcpcd.sh -O /usr/lib/dhcpcd5/dhcpcd
sudo chmod +x /usr/lib/dhcpcd5/dhcpcd

Then I reboot and it works

Owner

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 https://gist.github.com/Lewiscowles1986/fecd4de0b45b2029c390/raw/0c8b3af3530a35db9ab958defe9629cb5ea99972/rPi3-ap-setup.sh | sudo bash $0 password rPi3AP

sudo wget -q https://gist.githubusercontent.com/Lewiscowles1986/390d4d423a08c4663c0ada0adfe04cdb/raw/5b41bc95d1d483b48e119db64e0603eefaec57ff/dhcpcd.sh -O /usr/lib/dhcpcd5/dhcpcd
sudo chmod +x /usr/lib/dhcpcd5/dhcpcd

Then I reboot and it works

@mrsimple97

This comment has been minimized.

Show comment
Hide comment
@mrsimple97

mrsimple97 Aug 30, 2017

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

mrsimple97 commented Aug 30, 2017

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

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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 https://gist.github.com/Lewiscowles1986/f303d66676340d9aa3cf6ef1b672c0c9 to make this a bridge, however, YMMV depending upon interface names

Owner

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 https://gist.github.com/Lewiscowles1986/f303d66676340d9aa3cf6ef1b672c0c9 to make this a bridge, however, YMMV depending upon interface names

@jonathandreyer

This comment has been minimized.

Show comment
Hide comment
@jonathandreyer

jonathandreyer Sep 10, 2017

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?

jonathandreyer commented Sep 10, 2017

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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 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 ๐Ÿ˜‰

Owner

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

This comment has been minimized.

Show comment
Hide comment
@buckster123

buckster123 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

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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Sep 18, 2017

๐Ÿ‘ @buckster123 glad you worked it out. Do you think this would benefit from an uninstall action?

Owner

Lewiscowles1986 commented Sep 18, 2017

๐Ÿ‘ @buckster123 glad you worked it out. Do you think this would benefit from an uninstall action?

@JddAndrewLauren

This comment has been minimized.

Show comment
Hide comment
@JddAndrewLauren

JddAndrewLauren 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

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

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost 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!

ghost 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

This comment has been minimized.

Show comment
Hide comment
@carlpoole

carlpoole 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

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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986
Owner

Lewiscowles1986 commented Oct 12, 2017

Oh btw https://gist.github.com/Lewiscowles1986/390d4d423a08c4663c0ada0adfe04cdb fixes stretch release network config (which sucks)

@reichley

This comment has been minimized.

Show comment
Hide comment
@reichley

reichley Oct 12, 2017

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.

reichley commented Oct 12, 2017

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

This comment has been minimized.

Show comment
Hide comment
@stsdc

stsdc Oct 24, 2017

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

stsdc commented Oct 24, 2017

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

@Lexicographical

This comment has been minimized.

Show comment
Hide comment
@Lexicographical

Lexicographical Oct 31, 2017

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

Lexicographical commented Oct 31, 2017

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

@Lexicographical

This comment has been minimized.

Show comment
Hide comment
@Lexicographical

Lexicographical Oct 31, 2017

@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.

Lexicographical commented Oct 31, 2017

@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

This comment has been minimized.

Show comment
Hide comment
@vicatcu

vicatcu 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 http://archive.raspberrypi.org/debian/dists/stretch/main/binary-armhf/Packages.gz  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.

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 http://archive.raspberrypi.org/debian/dists/stretch/main/binary-armhf/Packages.gz  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.

@robinhuse

This comment has been minimized.

Show comment
Hide comment
@robinhuse

robinhuse Nov 16, 2017

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

robinhuse commented Nov 16, 2017

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

@PatrikXop

This comment has been minimized.

Show comment
Hide comment
@PatrikXop

PatrikXop Dec 20, 2017

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

PatrikXop commented Dec 20, 2017

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

@joachimpr

This comment has been minimized.

Show comment
Hide comment
@joachimpr

joachimpr 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!

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

This comment has been minimized.

Show comment
Hide comment
@aloboa

aloboa 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 rPi3-ap-setup.sh, then downloaded dhcpcd.sh 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 rPi3-ap-setup.sh 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

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 rPi3-ap-setup.sh, then downloaded dhcpcd.sh 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 rPi3-ap-setup.sh 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

This comment has been minimized.

Show comment
Hide comment
@banak0

banak0 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
address 10.0.0.1
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255

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.

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
address 10.0.0.1
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255

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

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Jan 19, 2018

@Lexicographical

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
sudo cp /etc/network/interfaces /etc/pi-ap/standard-config

wget https://gist.github.com/Lewiscowles1986/fecd4de0b45b2029c390/raw/0c8b3af3530a35db9ab958defe9629cb5ea99972/rPi3-ap-setup.sh
chmod +x rPi3-ap-setup.sh
sudo apt-get update
sudo ./rPi3-ap-setup.sh password apname

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

sudo rm /etc/network/interfaces
sudo 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.

Owner

Lewiscowles1986 commented Jan 19, 2018

@Lexicographical

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
sudo cp /etc/network/interfaces /etc/pi-ap/standard-config

wget https://gist.github.com/Lewiscowles1986/fecd4de0b45b2029c390/raw/0c8b3af3530a35db9ab958defe9629cb5ea99972/rPi3-ap-setup.sh
chmod +x rPi3-ap-setup.sh
sudo apt-get update
sudo ./rPi3-ap-setup.sh password apname

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

sudo rm /etc/network/interfaces
sudo 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.

@dereksnyder42v2

This comment has been minimized.

Show comment
Hide comment
@dereksnyder42v2

dereksnyder42v2 Feb 17, 2018

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.

dereksnyder42v2 commented Feb 17, 2018

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

This comment has been minimized.

Show comment
Hide comment
@Aimma

Aimma 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

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

@Aimma

This comment has been minimized.

Show comment
Hide comment
@Aimma

Aimma 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

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

@lucascrandle

This comment has been minimized.

Show comment
Hide comment
@lucascrandle

lucascrandle Feb 25, 2018

Awww. spam :removed: ๐Ÿ˜‰

lucascrandle commented Feb 25, 2018

Awww. spam :removed: ๐Ÿ˜‰

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Mar 3, 2018

@Aimma did you follow the guide like 2 comments above your question?

@lucascrandle removed for spam, please don't do that again. I've just re-tested (again), the script works on raspberry pi 3's (it's designed platform) using raspbian (as designed). Start a blog elsewhere if you want to post links. I don't want people to be confused further.

@dereksnyder42v2 cheers ๐Ÿ‘

Owner

Lewiscowles1986 commented Mar 3, 2018

@Aimma did you follow the guide like 2 comments above your question?

@lucascrandle removed for spam, please don't do that again. I've just re-tested (again), the script works on raspberry pi 3's (it's designed platform) using raspbian (as designed). Start a blog elsewhere if you want to post links. I don't want people to be confused further.

@dereksnyder42v2 cheers ๐Ÿ‘

@jimbo1969

This comment has been minimized.

Show comment
Hide comment
@jimbo1969

jimbo1969 Mar 13, 2018

Thanks Lewis!
13-Mar-2018 -- Pi-day-eve.
I thought I'd contribute a tiny bit back by sharing what I had to do to employ this on the 2017-11-09 version of Raspian Lite (Stretch) on my first generation Model B Raspberry Pi.
I added an empty file named "ssh" to the root folder of my SD card in order to enable SSH to my headless Pi.
I prepended "net.ifnames=0 " to the contents of /boot/cmdline.txt in order to get old-school interface names back.
I installed the policykit-1 package after running your rPi3-ap-setup.sh script (above) and having it break my eth0 interface, thus preventing me from SSH-ing back into the Pi after reboot. So I suggest doing a "sudo apt-get install policykit-1" on this version of Raspian BEFORE running rPi3-ap-setup.sh. Policykit-1 allowed eth0 to come back online after the next reboot.
I ran rPi3-ap-setup.sh, of course.
I received the cryptic error about dhcpcd failing due to /etc/network/interfaces defining some interfaces that will use a DHCP client or static address. I spent hours trying to understand all the parts of that, and stumbled across another of your scripts (thank you again) -- dhcpcd.sh, here.
I copied dhcpcd.sh to its intended home "sudo cp dhcpcd.sh /usr/lib/dhcpcd5/dhcpcd" and rebooted. All now works as intended. Yeah!

jimbo1969 commented Mar 13, 2018

Thanks Lewis!
13-Mar-2018 -- Pi-day-eve.
I thought I'd contribute a tiny bit back by sharing what I had to do to employ this on the 2017-11-09 version of Raspian Lite (Stretch) on my first generation Model B Raspberry Pi.
I added an empty file named "ssh" to the root folder of my SD card in order to enable SSH to my headless Pi.
I prepended "net.ifnames=0 " to the contents of /boot/cmdline.txt in order to get old-school interface names back.
I installed the policykit-1 package after running your rPi3-ap-setup.sh script (above) and having it break my eth0 interface, thus preventing me from SSH-ing back into the Pi after reboot. So I suggest doing a "sudo apt-get install policykit-1" on this version of Raspian BEFORE running rPi3-ap-setup.sh. Policykit-1 allowed eth0 to come back online after the next reboot.
I ran rPi3-ap-setup.sh, of course.
I received the cryptic error about dhcpcd failing due to /etc/network/interfaces defining some interfaces that will use a DHCP client or static address. I spent hours trying to understand all the parts of that, and stumbled across another of your scripts (thank you again) -- dhcpcd.sh, here.
I copied dhcpcd.sh to its intended home "sudo cp dhcpcd.sh /usr/lib/dhcpcd5/dhcpcd" and rebooted. All now works as intended. Yeah!

@jimbo1969

This comment has been minimized.

Show comment
Hide comment
@jimbo1969

jimbo1969 Mar 13, 2018

Question: After employing this solution on the 2017-11-09 version of Raspian Lite (Stretch), it seems like I may have two competing DHCP clients running.
"pi@raspberrypi:~ $ dpkg -l | grep dhcp"
returns

  • ii dhcpcd5 1:6.11.5-1+rpt4 armhf DHCPv4, IPv6RA and DHCPv6 client with IPv4LL support
  • ii isc-dhcp-client 4.3.5-3 armhf DHCP client for automatically obtaining an IP address
  • ii isc-dhcp-common 4.3.5-3 armhf common manpages relevant to all of the isc-dhcp packages

Am I interpreting that correctly? And if so, is the answer to simply uninstall ics-dhcp-client? Aside from this question, I'm convinced it is all working as intended on this platform.

jimbo1969 commented Mar 13, 2018

Question: After employing this solution on the 2017-11-09 version of Raspian Lite (Stretch), it seems like I may have two competing DHCP clients running.
"pi@raspberrypi:~ $ dpkg -l | grep dhcp"
returns

  • ii dhcpcd5 1:6.11.5-1+rpt4 armhf DHCPv4, IPv6RA and DHCPv6 client with IPv4LL support
  • ii isc-dhcp-client 4.3.5-3 armhf DHCP client for automatically obtaining an IP address
  • ii isc-dhcp-common 4.3.5-3 armhf common manpages relevant to all of the isc-dhcp packages

Am I interpreting that correctly? And if so, is the answer to simply uninstall ics-dhcp-client? Aside from this question, I'm convinced it is all working as intended on this platform.

@GigiBoot

This comment has been minimized.

Show comment
Hide comment
@GigiBoot

GigiBoot Mar 22, 2018

I get this error:

pi@raspberrypi:~/Desktop $ sudo bash ./rPi3-ap-setup.sh password apname
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
./rPi3-ap-setup.sh: line 35: /etc/hostapd/hostapd.conf: No such file or directory
sed: can't read /etc/default/hostapd: No such file or directory
Failed to enable unit: File hostapd.service: No such file or directory
Failed to enable unit: File dnsmasq.service: No such file or directory
Failed to start hostapd.service: Unit hostapd.service not found.
Failed to start dnsmasq.service: Unit dnsmasq.service not found.
All done! Please reboot

If I type : sudo bash Desktop/rPi3-ap-setup.sh YourWifiApName YourWifiApPassword the terminal gets frozen.
I have Pi zero W.How can I make this work?
I am a novice in this Pi programming.

GigiBoot commented Mar 22, 2018

I get this error:

pi@raspberrypi:~/Desktop $ sudo bash ./rPi3-ap-setup.sh password apname
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
./rPi3-ap-setup.sh: line 35: /etc/hostapd/hostapd.conf: No such file or directory
sed: can't read /etc/default/hostapd: No such file or directory
Failed to enable unit: File hostapd.service: No such file or directory
Failed to enable unit: File dnsmasq.service: No such file or directory
Failed to start hostapd.service: Unit hostapd.service not found.
Failed to start dnsmasq.service: Unit dnsmasq.service not found.
All done! Please reboot

If I type : sudo bash Desktop/rPi3-ap-setup.sh YourWifiApName YourWifiApPassword the terminal gets frozen.
I have Pi zero W.How can I make this work?
I am a novice in this Pi programming.

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Apr 10, 2018

@jimbo1969 sorry, as it states all over the place. This is intended to work with a Raspberry Pi 3. I Cannot comment on your needed changes for an earlier raspberry Pi or packages as I don't make Raspberry Pi distro. There is a networking fix for dhcpcd5 here https://gist.github.com/Lewiscowles1986/390d4d423a08c4663c0ada0adfe04cdb same deal. It should be installed before this script.

@GigiBoot, Looks like some of the stages fail, likely due to you not having networking setup. I've not run this on a PiZero-W. This script is only intended for a Raspberry Pi 3 and it's onboard network wlan

Owner

Lewiscowles1986 commented Apr 10, 2018

@jimbo1969 sorry, as it states all over the place. This is intended to work with a Raspberry Pi 3. I Cannot comment on your needed changes for an earlier raspberry Pi or packages as I don't make Raspberry Pi distro. There is a networking fix for dhcpcd5 here https://gist.github.com/Lewiscowles1986/390d4d423a08c4663c0ada0adfe04cdb same deal. It should be installed before this script.

@GigiBoot, Looks like some of the stages fail, likely due to you not having networking setup. I've not run this on a PiZero-W. This script is only intended for a Raspberry Pi 3 and it's onboard network wlan

@heartlandcoop-prichards

This comment has been minimized.

Show comment
Hide comment
@heartlandcoop-prichards

heartlandcoop-prichards Apr 12, 2018

This worked with Raspian Stretch March 2018
First I needed to mv your .sh:
Lewiscowles1986/dhcpcd.sh into the /usr/lib/dhcpcd5 directory:

sudo mv /usr/lib/dhcpcd5/dhcpcd /usr/lib/dhcpcd5/dhcpcd.orig

sudo mv /boot/dhcpcd.sh /usr/lib/dhcpcd5/dhcpcd

I then ran your script:
sudo ./rPi3-ap-setup.sh hello123 ApYo

I did need to make one modification, I added:
apt-get update
after apt-get upgrade.
I'm not sure why the upgrade was messing with the ability to install hostapd.

I also recommend placing both .sh files in the /boot directory and adding the command:
cp /boot/dhcpcd.sh /usr/lib/dhcpcd5/dhcpcd

This will remove one more manual step.
Thanks

heartlandcoop-prichards commented Apr 12, 2018

This worked with Raspian Stretch March 2018
First I needed to mv your .sh:
Lewiscowles1986/dhcpcd.sh into the /usr/lib/dhcpcd5 directory:

sudo mv /usr/lib/dhcpcd5/dhcpcd /usr/lib/dhcpcd5/dhcpcd.orig

sudo mv /boot/dhcpcd.sh /usr/lib/dhcpcd5/dhcpcd

I then ran your script:
sudo ./rPi3-ap-setup.sh hello123 ApYo

I did need to make one modification, I added:
apt-get update
after apt-get upgrade.
I'm not sure why the upgrade was messing with the ability to install hostapd.

I also recommend placing both .sh files in the /boot directory and adding the command:
cp /boot/dhcpcd.sh /usr/lib/dhcpcd5/dhcpcd

This will remove one more manual step.
Thanks

@swapab

This comment has been minimized.

Show comment
Hide comment
@swapab

swapab Apr 14, 2018

***EDIT: *** @Lewiscowles1986 the following scripts might have saved you time Adapter passthrough & Stretch dhcpcd fix. the below linked a blog post I've removed.

The script executed without any issues, but I was not able to get internet for my mobile devies(Connect, no internet)

I followed a combination of this gist and this blog: removed

I believe SET UP IPV4 FORWARDING section from removed did the trick for me.

  1. Execute ./rPi3-ap-setup.sh <password> <ssid>

  2. Explicitly set ipv4 forwarding

sudo vim /etc/sysctl.conf

remove the # from the beginning of the line containing net.ipv4.ip_forward=1
  1. share our Pi's internet connection to our devices connected over WiFi by the configuring a NAT between our wlan0 interface and our eth0 interface. We 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  
  1. However, we need these rules to be applied every time we reboot the Pi, so run sudo sh -c "iptables-save > /etc/iptables.ipv4.nat to save the rules to the file /etc/iptables.ipv4.nat. Now we need to run this after each reboot, so open the rc.local file with sudo nano /etc/rc.local and just above the line exit 0, add the following line
iptables-restore < /etc/iptables.ipv4.nat  
  1. It's working!!!

Thanks! @Lewiscowles1986 @frillip

swapab commented Apr 14, 2018

***EDIT: *** @Lewiscowles1986 the following scripts might have saved you time Adapter passthrough & Stretch dhcpcd fix. the below linked a blog post I've removed.

The script executed without any issues, but I was not able to get internet for my mobile devies(Connect, no internet)

I followed a combination of this gist and this blog: removed

I believe SET UP IPV4 FORWARDING section from removed did the trick for me.

  1. Execute ./rPi3-ap-setup.sh <password> <ssid>

  2. Explicitly set ipv4 forwarding

sudo vim /etc/sysctl.conf

remove the # from the beginning of the line containing net.ipv4.ip_forward=1
  1. share our Pi's internet connection to our devices connected over WiFi by the configuring a NAT between our wlan0 interface and our eth0 interface. We 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  
  1. However, we need these rules to be applied every time we reboot the Pi, so run sudo sh -c "iptables-save > /etc/iptables.ipv4.nat to save the rules to the file /etc/iptables.ipv4.nat. Now we need to run this after each reboot, so open the rc.local file with sudo nano /etc/rc.local and just above the line exit 0, add the following line
iptables-restore < /etc/iptables.ipv4.nat  
  1. It's working!!!

Thanks! @Lewiscowles1986 @frillip

@youwalther65

This comment has been minimized.

Show comment
Hide comment
@youwalther65

youwalther65 Apr 28, 2018

After struggling with several instructions on the Internet this script works perfect for my Raspberry Pi Zero W with latest Raspian Stretch Lite and dslrdashboard server to Wifi control my Nikon DSLR over a standalone SSID. Thank you very much for this.

youwalther65 commented Apr 28, 2018

After struggling with several instructions on the Internet this script works perfect for my Raspberry Pi Zero W with latest Raspian Stretch Lite and dslrdashboard server to Wifi control my Nikon DSLR over a standalone SSID. Thank you very much for this.

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
Owner

Lewiscowles1986 commented May 5, 2018

Thank you @youwalther65

@Maxl94

This comment has been minimized.

Show comment
Hide comment
@Maxl94

Maxl94 May 14, 2018

Thank's ๐Ÿ‘ I was struggling the complete day setting up the AP didn't get it working. Your script does it :-)

Also had the problem that eth0 disappear: but @JddAndrewLauren commet fixed that

Maxl94 commented May 14, 2018

Thank's ๐Ÿ‘ I was struggling the complete day setting up the AP didn't get it working. Your script does it :-)

Also had the problem that eth0 disappear: but @JddAndrewLauren commet fixed that

@RichardBronosky

This comment has been minimized.

Show comment
Hide comment
@RichardBronosky

RichardBronosky Jul 4, 2018

This is so awesome! I've made an RPi Zero W based gadget that I want to control via mobile phone. This was a VERY easy way to set up hostapd to allow me to connect device to device and not need a local network. I'll credit you when I publish my build notes. Thank you!

RichardBronosky commented Jul 4, 2018

This is so awesome! I've made an RPi Zero W based gadget that I want to control via mobile phone. This was a VERY easy way to set up hostapd to allow me to connect device to device and not need a local network. I'll credit you when I publish my build notes. Thank you!

@moppymopperson

This comment has been minimized.

Show comment
Hide comment
@moppymopperson

moppymopperson Jul 16, 2018

Worked on first try for me! Thanks to @JddAndrewLauren and @maxi94 for comments about getting eth0 back!

moppymopperson commented Jul 16, 2018

Worked on first try for me! Thanks to @JddAndrewLauren and @maxi94 for comments about getting eth0 back!

@Lewiscowles1986

This comment has been minimized.

Show comment
Hide comment
@Lewiscowles1986

Lewiscowles1986 Jul 17, 2018

Just a note, if you search the comments there are other ways to get eth0 back without adding an /etc/networking/interfaces entry for it ๐Ÿ˜‰

Thanks @RichardBronosky & @moppymopperson

Owner

Lewiscowles1986 commented Jul 17, 2018

Just a note, if you search the comments there are other ways to get eth0 back without adding an /etc/networking/interfaces entry for it ๐Ÿ˜‰

Thanks @RichardBronosky & @moppymopperson

@ChrisRichards2

This comment has been minimized.

Show comment
Hide comment
@ChrisRichards2

ChrisRichards2 Aug 4, 2018

Lewis
Thanks for your excellent script.
I have connected my rPi3 running Stretch Lite with your AP script to a USB tethered Samsung phone & forwarded AP traffic to a USB port.

Everything works fine & is stable. However if the throughput to the Internet is say 30Mbps when I connect the phone to a windows PC via a USB port, I am getting about 8Mbps when connecting the PC via the rPi3 AP. The cpu load on th rPi3 is minimal.

Have you any idea why this is so? Suggestions to improve?
Thanks
Chris

ChrisRichards2 commented Aug 4, 2018

Lewis
Thanks for your excellent script.
I have connected my rPi3 running Stretch Lite with your AP script to a USB tethered Samsung phone & forwarded AP traffic to a USB port.

Everything works fine & is stable. However if the throughput to the Internet is say 30Mbps when I connect the phone to a windows PC via a USB port, I am getting about 8Mbps when connecting the PC via the rPi3 AP. The cpu load on th rPi3 is minimal.

Have you any idea why this is so? Suggestions to improve?
Thanks
Chris

@amishm766

This comment has been minimized.

Show comment
Hide comment
@amishm766

amishm766 Aug 12, 2018

I have everything working i can connect to the access point and all the traffic is also routed from ethernet to access point but my ethernet icon says "connection to dhcpcd lost" though when i ifconfig it shows eth0 and also ip address. Plzz help me out about ethernet icon plzz.. Thnx in advance

amishm766 commented Aug 12, 2018

I have everything working i can connect to the access point and all the traffic is also routed from ethernet to access point but my ethernet icon says "connection to dhcpcd lost" though when i ifconfig it shows eth0 and also ip address. Plzz help me out about ethernet icon plzz.. Thnx in advance

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