SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Pi 3 as wiireless client and wireless AP?

Thu Jun 21, 2018 11:15 am

You can switch the interface names.
To make onboard wlan always wlan1
Create file /etc/udev/rules.d/72-static-name.rules
Add this:

Code: Select all

ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*",
ATTR{address}=="00:c0:ca:96:d8:8b", KERNEL=="w*",NAME="wlan0"

ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*",
ATTR{address}=="b8:27:eb:1e:56:52", KERNEL=="w*",NAME="wlan1"
Change the mac addresses to suit your needs.

Add a masquerade for the interface connecting to the internet.

Edit: Like I stated on the other thread, the performance and stability is not what I expected. Bear in mind the single radio uses the same frequency for the AP and WAN, and must stop listening to the AP localnet when transmitting and receiving to/from the internet and vice versa.

wanstreet
Posts: 39
Joined: Fri Jun 01, 2018 5:28 am

Re: Pi 3 as wiireless client and wireless AP?

Thu Jun 21, 2018 12:04 pm

Stkenneth wrote:
Tue May 29, 2018 5:49 am
Hi guys,
I'm running on stretch here
And did all the following and had 99% success

I have my client side as dhcp, I run dnsmasq on my ap side to give out ip. So far everything is working

The pi can connect to internet through wlan0, and my pc can connect and get an ip through uap0.
Here's the problem, so dnsmasq does it work by giving out ip, and my pc can receive the ip settings. But other than that nothing works. I cannot ping 192.168.42.1 (the uap0 gateway), I cannot ssh to it, and cannot and to it.

But funny thing is, if I run hostapd on wlan0 (restart the pi and DO NOT create uap0 interface), change the hostapd conf to run on wlan0 interface, it works. I can access 192.168.42.1
But once I created uap0 and tried to run hostapd on wlan0 again, it says "wlan0 wasn't started"
And I know for stretch it supposed to show that. So I have to run it on the AP interface. In the uap0 interface my pc can get ip address and connect but cannot ping/vnc/ssh the 192.168.42.1.

Thanks for all the great tutorial!
Specially @anthony19114 @surfertim!
I followed your steps and it seems uap0 is getting APIPA as an address, but other devices are getting ip address as per the dhcp rules.

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Pi 3 as wiireless client and wireless AP?

Thu Jun 21, 2018 12:09 pm

Did you use this?
Edit /etc/rc.local and add this above "exit 0". Note that is two underscores on __ap.

Code: Select all

service hostapd stop
service dnsmasq stop
iw dev wlan0 interface add uap0 type __ap
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
ifdown wlan0
ip link set uap0 up
ip addr add 192.168.4.1/24 broadcast 192.168.4.255 dev uap0
service hostapd start
ifup wlan0
service dnsmasq start

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Pi 3 as wiireless client and wireless AP?

Thu Jun 21, 2018 12:13 pm

Here is the entire setup that works with all RPis I tested, including the Zero W.
Add this to /etc/network/interfaces

Code: Select all

auto wlan0
iface wlan0 inet dhcp
	wpa-ssid "MySSID"
	wpa-psk "MyPassphrase"
Reboot. This will cause the dhcpcd service to fail.

Insure your OS is up to date.

Code: Select all

sudo apt-get update
sudo apt-get upgrade
Install the modules.

Code: Select all

sudo apt-get install dnsmasq hostapd
Edit /etc/rc.local and add this above "exit 0". Note that is two underscores on __ap.

Code: Select all

service hostapd stop
service dnsmasq stop
iw dev wlan0 interface add uap0 type __ap
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
ifdown wlan0
ip link set uap0 up
ip addr add 192.168.4.1/24 broadcast 192.168.4.255 dev uap0
service hostapd start
ifup wlan0
service dnsmasq start
The /etc/dnsmasq.conf file

Code: Select all

interface=uap0
dhcp-range=192.168.4.20,192.168.4.100,255.255.255.0,12h
The /etc/hostapd/hostapd.conf file. If you change the wpa_passphrase, it must be 8 to 63 characters. No shorter or longer!

Code: Select all

interface=uap0
driver=nl80211
ssid=RPiNet
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Edit /etc/default/hostapd, uncomment and change this:

Code: Select all

DAEMON_CONF="/etc/hostapd/hostapd.conf"
Edit /etc/sysctl.conf and uncomment

Code: Select all

net.ipv4.ip_forward=1
Reboot.

wanstreet
Posts: 39
Joined: Fri Jun 01, 2018 5:28 am

Re: Pi 3 as wiireless client and wireless AP?

Thu Jun 21, 2018 1:17 pm

ok, I will try your work.
thanks man.

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Pi 3 as wiireless client and wireless AP?

Thu Jun 21, 2018 1:29 pm

I haven't tried it in a while. Let me know if it works for you.

wanstreet
Posts: 39
Joined: Fri Jun 01, 2018 5:28 am

Re: Pi 3 as wiireless client and wireless AP?

Thu Jun 21, 2018 2:47 pm

it didnt work.
I rebooted and then "no network interfaces" problem.
so i removed the network/interfaces lines.
then I made some small changes. in the dhcpcd.conf file.
heres the img as to what i did
Image
now after reboot, wlan0 is getting a proper ip address
but uap0 is not getting ip address.
so from terminal i have to repeat these 3 steps

Code: Select all

sudo systemctl restart hostapd
sudo systemctl restart dnsmasq
sudo systemctl restart dhcpcd
after that the rpi is connected to net,
and the devices connected to the AP is getting IP address.
But the devices connected to the ap cannot connect to internet.

I used that peebles github instructions, that one also is not working properly,
even using that also i had to use those 3 commands in the terminal to get both the interfaces working simultaneously.
But using that tutorial the devices connect to AP can connect to internet.
Attachments
2018-06-21-143054_1366x768_scrot.png
2018-06-21-143054_1366x768_scrot.png (83.97 KiB) Viewed 1140 times
2018-06-21-143054_1366x768_scrot.png
2018-06-21-143054_1366x768_scrot.png (83.97 KiB) Viewed 1140 times

wanstreet
Posts: 39
Joined: Fri Jun 01, 2018 5:28 am

Re: Pi 3 as wiireless client and wireless AP?

Thu Jun 21, 2018 2:49 pm

well my work time is up.
post any suggestions i will follow them up tomorrow..
all hell the think tank!!!!!!!!!!!!!

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Pi 3 as wiireless client and wireless AP?

Thu Jun 21, 2018 6:26 pm

I tested an old setup I had laying around and it works. I tested it on a RPi3B+ using 2018-04-18 full version .
This is for Stretch ONLY!
DO NOT MODIFY /etc/network/interfaces FILE! The only uncommented line in that file should be
source-directory /etc/network/interfaces.d

First, insure your OS is up to date.

Code: Select all

sudo apt-get update
sudo apt-get upgrade
Open /etc/wpa_supplicant/wpa_supplicant.conf with a text editor.
Save as /etc/wpa_supplicant/wpa_supplicant-wlan0.conf.
Add this to wpa_supplicant-wlan0.conf

Code: Select all

network={
   ssid="MySSID"
   psk="MyPassphrase"
}
Then install the modules.

Code: Select all

sudo apt-get install dnsmasq hostapd
Edit /etc/rc.local and add this above "exit 0". Note that is two underscores.

Code: Select all

iw dev wlan0 interface add uap0 type __ap
iptables -t nat -A  POSTROUTING -o wlan0 -j MASQUERADE
The /etc/dhcpcd.conf addition:

Code: Select all

interface uap0
static ip_address=192.168.4.1/24
The /etc/dnsmasq.conf file

Code: Select all

interface=uap0
dhcp-range=192.168.4.20,192.168.4.100,255.255.255.0,12h
The /etc/hostapd/hostapd.conf file. If you change the wpa_passphrase, it must be 8 to 63 characters. No shorter or longer!

Code: Select all

interface=uap0
#driver=nl80211
ssid=RPiNet
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Edit /etc/default/hostapd, uncomment and change this:

Code: Select all

DAEMON_CONF="/etc/hostapd/hostapd.conf"
Edit /etc/sysctl.conf and uncomment

Code: Select all

net.ipv4.ip_forward=1
Reboot.

wanstreet
Posts: 39
Joined: Fri Jun 01, 2018 5:28 am

Re: Pi 3 as wiireless client and wireless AP?

Fri Jun 22, 2018 6:18 am

wanstreet wrote:
Thu Jun 21, 2018 2:47 pm
it didnt work.
I rebooted and then "no network interfaces" problem.
so i removed the network/interfaces lines.
then I made some small changes. in the dhcpcd.conf file.
heres the img as to what i did
Image
now after reboot, wlan0 is getting a proper ip address
but uap0 is not getting ip address.
so from terminal i have to repeat these 3 steps

Code: Select all

sudo systemctl restart hostapd
sudo systemctl restart dnsmasq
sudo systemctl restart dhcpcd
after that the rpi is connected to net,
and the devices connected to the AP is getting IP address.
But the devices connected to the ap cannot connect to internet.

I used that peebles github instructions, that one also is not working properly,
even using that also i had to use those 3 commands in the terminal to get both the interfaces working simultaneously.
But using that tutorial the devices connect to AP can connect to internet.
whatever changes i made here.
after this i am running a python script,

Code: Select all

import os
import time
from time import sleep

time.sleep(10)
os.system('sudo systemctl restart hostapd')
time.sleep(2)
os.system('sudo systemctl restart dnsmasq')
os.system('sudo systemctl restart dhcpcd')

dats all, now on reboot everything works fine.
the devices connected to the AP can access the internet but its kinda slow.

shanem2
Posts: 13
Joined: Tue Jan 23, 2018 10:38 am

Re: Pi 3 as wiireless client and wireless AP?

Fri Jun 22, 2018 6:45 am

I've just tried what SuferTim suggested but it wipes out my Interfaces, as below;

uap0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether b8:27:eb:aa:aa:aa txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether b8:27:eb:aa:aa:aa txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Before applying this config, my wlan0 had an IP Address. I also came across another article to create these additional interfaces, but I saw the same behavior;

https://blog.thewalr.us/2017/09/26/rasp ... mode-wifi/

epoch1970
Posts: 2075
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Pi 3 as wiireless client and wireless AP?

Fri Jun 22, 2018 7:51 am

You can fumble with some of that if you want: viewtopic.php?f=28&t=212991
Extra comments: power management off is necessary; uap0 bridging definitely does not work; the requirement to unload the module seems dependent on kernel or OS version, try avoiding it if possible; reliable operation looks possible.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Pi 3 as wiireless client and wireless AP?

Fri Jun 22, 2018 11:07 am

the devices connected to the AP can access the internet but its kinda slow.
You were warned.

wanstreet
Posts: 39
Joined: Fri Jun 01, 2018 5:28 am

Re: Pi 3 as wiireless client and wireless AP?

Fri Jun 22, 2018 12:21 pm

SurferTim wrote:
Fri Jun 22, 2018 11:07 am
the devices connected to the AP can access the internet but its kinda slow.
You were warned.
yup..
You're the man.. :geek: :geek:

sora03
Posts: 188
Joined: Mon Dec 29, 2014 4:11 pm
Contact: Website

Re: Pi 3 as wiireless client and wireless AP?

Sat Jun 23, 2018 12:57 pm

so, does this work for 3B and 3B+, I'd like to know before buying one
FLOSS enthusiast, Debian user (linux-libre)

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Pi 3 as wiireless client and wireless AP?

Sat Jun 23, 2018 1:02 pm

sora03 wrote: so, does this work for 3B and 3B+, I'd like to know before buying one
Yes if set up on a fresh install, but also consider yourself warned about speed and reliability.

Edit: These shortcomings will be most noticeable when streaming videos like YouTube.

sora03
Posts: 188
Joined: Mon Dec 29, 2014 4:11 pm
Contact: Website

Re: Pi 3 as wiireless client and wireless AP?

Mon Jun 25, 2018 2:47 am

SurferTim wrote:
Sat Jun 23, 2018 1:02 pm
sora03 wrote: so, does this work for 3B and 3B+, I'd like to know before buying one
Yes if set up on a fresh install, but also consider yourself warned about speed and reliability.

Edit: These shortcomings will be most noticeable when streaming videos like YouTube.
good to know them, I do not care about the speed, as I have a very slow internet.

Anyway can anyone post the output of sudo iw list, I'd like to see the 'valid interface combinations;' STA+AP or something like that. I wonder if this is possible with external USB wifi dongles too
FLOSS enthusiast, Debian user (linux-libre)

wanstreet
Posts: 39
Joined: Fri Jun 01, 2018 5:28 am

Re: Pi 3 as wiireless client and wireless AP?

Mon Jun 25, 2018 8:28 am

sora03 wrote:
Sat Jun 23, 2018 12:57 pm
so, does this work for 3B and 3B+, I'd like to know before buying one
yes it works, still needs sme testing as to how many devices can connect to it, which i dont know.
the connection is not stable.

shanem2
Posts: 13
Joined: Tue Jan 23, 2018 10:38 am

Re: Pi 3 as wiireless client and wireless AP?

Wed Jun 27, 2018 5:54 am

@SurferTim and @wanstreet, Thanks for the details above and confirmation it works.

I've rebuilt my RPi 3B+ several times trying different things. Currently I've got the config which @SurferTim posted on Fri Jun 22, 2018 3:56 am.

I can see my uap0 and wlan0 interfaces, uap0 has the IP Address which my wireless users will use, but it refuses to join the AP of an external connection. Also users connecting to my AP on the RPi are unable to. They either get no error or Auth Failed errors.

This is what the interfaces look like;
uap0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a911:696c:c59f:117f prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:18:cb:3g txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 53 bytes 8066 (7.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether b8:27:eb:18:cb:3g txqueuelen 1000 (Ethernet)
RX packets 3 bytes 604 (604.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 27 bytes 4558 (4.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Has anyone able to post a "from scratch" config that be used?

wanstreet
Posts: 39
Joined: Fri Jun 01, 2018 5:28 am

Re: Pi 3 as wiireless client and wireless AP?

Wed Jun 27, 2018 10:08 am

it seems wlan0 is unable to get ip address from dhcpcd, the internal dhcp client
can you post the config details of dhcpcd.conf and dnsmasq.conf

wanstreet
Posts: 39
Joined: Fri Jun 01, 2018 5:28 am

Re: Pi 3 as wiireless client and wireless AP?

Wed Jun 27, 2018 10:11 am

did u make any changes in the /etc/network/interfaces file? if so then also post it here.
or else remove the changes u made in that file.

wanstreet
Posts: 39
Joined: Fri Jun 01, 2018 5:28 am

Re: Pi 3 as wiireless client and wireless AP?

Wed Jun 27, 2018 10:13 am

also after following @SurferTim's steps, did u restart, the hostapd, dnsmasq and dhcpcd services

shanem2
Posts: 13
Joined: Tue Jan 23, 2018 10:38 am

Re: Pi 3 as wiireless client and wireless AP?

Wed Jun 27, 2018 10:18 am

@wanstreet yes I rebooted. I also tried to restart the services 3 times as you mentioned in response.

no modifications to the /etc/network/interfaces file should there have been?

I'll post up configs tomorrow when have RPi out again.

wanstreet
Posts: 39
Joined: Fri Jun 01, 2018 5:28 am

Re: Pi 3 as wiireless client and wireless AP?

Wed Jun 27, 2018 10:50 am

no no, that file will be untouched.
ok, no problem

shanem2
Posts: 13
Joined: Tue Jan 23, 2018 10:38 am

Re: Pi 3 as wiireless client and wireless AP?

Wed Jun 27, 2018 11:40 am

@wanstreet, would there be any issue if connecting via Wireless initially. Unfortunately, I don't have access to a monitor or keyboard, etc.

So I followed; https://howchoo.com/g/ndy1zte2yjn/how-t ... t-ethernet to create the Wireless access. It works well.

I then SSH to the device using my mobile as a hotspot.

Question around the copy of wpa file to /etc/wpa_supplicant/wpa_supplicant-wlan0.conf. As I'm accessing via Wireless, my config already exists. Will this be an issue?

Also, is it best to start with a fresh dnsmasq.conf file? Previously I've been;

Code: Select all

mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig  
nano /etc/dnsmasq.conf
then adding;

Code: Select all

interface=uap0     
  dhcp-range=192.168.4.100,192.168.4.200,255.255.255.0,12h
The "wpa_passphrase=" in the "/etc/hostapd/hostapd.conf" file, as long as this is between 8 and 13, it should work? The same key has worked before as just an AP.

Thanks for your help on this. My kids will love it once I can get our NAS and Plex MS working, so they can watch videos, etc while we're traveling.

Return to “Networking and servers”