sebar
Posts: 27
Joined: Thu Jan 04, 2018 9:49 am

Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 12:20 am

Hello guys,

I know there's plenty of guides on how to create a bridge or accesspoint or an extender.
But for my usecase I haven't found a guide yet.
I am using a Pi 4 in an ArgoOne case as my desktop computer.
Using a USB 3 WLAN dongle connected to a cable I can get a much better signal from my router.
How can I share this internet connection over the built-in WLAN chip?
In other words, have e.g. my mobile access the internet over the built-in chip, which gets the internet over the dongle?

Is this scenario even realistic?
Would dnsmasq be the weapon of choice here?

Thanks a ton in advance!

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

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 7:29 am

If I understand what you want, it is possible.
You want to use wlan0 (onboard) as an access point and wlan1 (usb) as the internet gateway, right?
My advice applies to RaspiOS only. Please mention if you use another OS.

sebar
Posts: 27
Joined: Thu Jan 04, 2018 9:49 am

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 8:27 am

Yes, this is what I want.

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

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 12:03 pm

OK. First you must check if your wireless interface names are persistent. From my experience, when adding a usb wlan, sometimes during boot, the usb wlan initializes as wlan0, and the onboard wlan initializes as wlan1. Do you see this happening?

Boot the RPi without the usb dongle. Note the mac address of the onboard unit. Shut down. Insert the dongle and reboot.
Is the wlan0 mac address the onboard unit's mac?

Edit: My apology. I had to find my setup code. If the onboard ends up as wlan1, here is how to fix it.
To make onboard wlan assignments persistent. Change mac addresses to your system.
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"
My advice applies to RaspiOS only. Please mention if you use another OS.

sebar
Posts: 27
Joined: Thu Jan 04, 2018 9:49 am

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 1:59 pm

It seems to be persistent:
dongle as wlan1
onboard as wlan0

That's a good thing, right? :)

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

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 3:09 pm

Yes, that is a good thing. Keep an eye on it though. Mine switched only now and then. But onward:
First, ensure your OS is up to date.

Code: Select all

sudo apt-get update
sudo apt-get upgrade
Then install the dnsmasq module.

Code: Select all

sudo apt-get install dnsmasq hostapd
My /etc/dhcpcd.conf addition:

Code: Select all

interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant
My /etc/dnsmasq.conf file

Code: Select all

interface=wlan0
dhcp-range=192.168.4.8,192.168.4.250,255.255.255.0,12h
My /etc/hostapd/hostapd.conf file

Code: Select all

country_code=US
interface=wlan0
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
My iptables rule. Note wlan1.

Code: Select all

sudo iptables -t nat -A  POSTROUTING -o wlan1 -j MASQUERADE
Then make the iptables rule permanent.

Code: Select all

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Then in /etc/rc.local, add this:

Code: Select all

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

Check WiFi network settings with ifconfig. wlan0 should show 192.168.4.1

Check service status
sudo service dnsmasq status
sudo service hostapd status
Both should show active (running)
My advice applies to RaspiOS only. Please mention if you use another OS.

sebar
Posts: 27
Joined: Thu Jan 04, 2018 9:49 am

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 3:51 pm

Thanks a lot so far!
This didn't work though.

Code: Select all

sudo service dnsmasq status 
failed to create listening socket for port 53: Address already in use

Code: Select all

sudo service hostapd status
inactive (dead)
...no new Network is showing.
I've been wondering: your etc/hostapd/hostapd.conf says

Code: Select all

driver=nl80211
What driver is that? Mine (Pi4, Mate, Networkicon in taskbar) is "rtl88x2bu"for the dongle and "brcmfmac" for the on-board chip.

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

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 4:10 pm

I have a RPi4 4GB with this setup, except eth0 as the gateway. That would have no impact on the AP.

This applies to Raspbian OS. Is that what you are using?
My advice applies to RaspiOS only. Please mention if you use another OS.

sebar
Posts: 27
Joined: Thu Jan 04, 2018 9:49 am

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 4:39 pm

I am using Ubuntu Mate.
But I have come a step closer.
Seems that resolvconf is getting in the way.
When I stop that service and restart the other two the new WLAN Network appears!
My phone can't get an IP from it though.

sebar
Posts: 27
Joined: Thu Jan 04, 2018 9:49 am

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 5:52 pm

Yet one step further!
I can connect to the new WLAN, but it offers no internet.

sebar
Posts: 27
Joined: Thu Jan 04, 2018 9:49 am

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 9:48 pm

I've been searching everywhere now, but I can't get the internet of wlan1 shared with wlan0.
Just to be clear:
wlan1 is the dongle, it has internet
wlan0 is onboard, it's supposed to serve as an access point

Maybe

Code: Select all

ifconfig
reveals something to you... if not to me.

ifconfig

Code: Select all

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.4.0  netmask 255.255.255.0  broadcast 192.168.4.255
        ether dc:a6:32:29:22:e7  txqueuelen 1000  (Ethernet)
        RX packets 12  bytes 1676 (1.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 26  bytes 5139 (5.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.39  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::80d9:d1af:502d:baa8  prefixlen 64  scopeid 0x20<link>
        ether 00:e0:4c:4d:25:a0  txqueuelen 1000  (Ethernet)
        RX packets 979  bytes 510570 (510.5 KB)
        RX errors 0  dropped 174  overruns 0  frame 0
        TX packets 756  bytes 122496 (122.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 10:15 pm

192.168.4.0 is not a valid address. It should be 192.168.4.1.
wlan1 looks good.
My advice applies to RaspiOS only. Please mention if you use another OS.

sebar
Posts: 27
Joined: Thu Jan 04, 2018 9:49 am

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 10:40 pm

Code: Select all

sudo ifconfig wlan0 192.168.4.1 netmask 255.255.255.0
same result...

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

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 10:47 pm

In /etc/dhcpcd.conf

Code: Select all

interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant
My advice applies to RaspiOS only. Please mention if you use another OS.

sebar
Posts: 27
Joined: Thu Jan 04, 2018 9:49 am

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 10:58 pm

Was already like that.

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

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 11:21 pm

Then what happened to get this?

Code: Select all

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.4.0  netmask 255.255.255.0  broadcast 192.168.4.255
It should look like this

Code: Select all

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.4.1  netmask 255.255.255.0  broadcast 192.168.4.255
Edit: Have you made any changes to /etc/network/interfaces?"
My advice applies to RaspiOS only. Please mention if you use another OS.

sebar
Posts: 27
Joined: Thu Jan 04, 2018 9:49 am

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 11:41 pm

My /etc/network/interfaces

Code: Select all

source-directory /etc/network/interfaces.d
iface ap0 inet manual
...should be doing nothing... or not?

The wlan0 IP I get by running

Code: Select all

sudo ifconfig wlan0 192.168.4.1 netmask 255.255.255.0
...with any arbitrary IP...

The

Code: Select all

/etc/resolv.conf
keep annoying me, though.
After each reboot it contains some weird nameserver that I have to change manually to get wlan1 to work.
I change it to

Code: Select all

nameserver 8.8.8.8
Beats me why that is and how to make it permanent.

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

Re: Pi 4 using WLAN dongle + built-in chip

Fri Feb 05, 2021 11:48 pm

This should not be there. I suggest you remove it.

Code: Select all

iface ap0 inet manual
This should be the only uncommented line in that file.

Code: Select all

source-directory /etc/network/interfaces.d
I have no idea what else you've tried. One of them is setting the wlan0 ip to 192.168.4.0.
My advice applies to RaspiOS only. Please mention if you use another OS.

sebar
Posts: 27
Joined: Thu Jan 04, 2018 9:49 am

Re: Pi 4 using WLAN dongle + built-in chip

Sat Feb 06, 2021 12:04 am

I removed that line and did a reboot.
Here is what happens:
ping heise.de
ping: heise.de: Temporary failure in name resolution

Code: Select all

sudo service resolvconf stop
edit /etc/resolv.conf:
change

Code: Select all

nameserver 127.0.0.1
to

Code: Select all

nameserver 8.8.8.8

Code: Select all

ping heise.de
PING heise.de (193.99.144.80) 56(84) bytes of data.
64 bytes from redirector.heise.de (193.99.144.80): icmp_seq=1 ttl=246 time=12.4 ms
[wlan1 is up and running]

SSID of wlan0 is not yet showing

Code: Select all

sudo ifconfig wlan0 192.168.4.1 netmask 255.255.255.0
sudo service dnsmasq restart
sudo service hostapd restart
SSID of wlan0 is showing, my phone connects to it, but has no internet

sebar
Posts: 27
Joined: Thu Jan 04, 2018 9:49 am

Re: Pi 4 using WLAN dongle + built-in chip

Sat Feb 06, 2021 11:12 am

Update:
I created a permanent solution for the resolv.conf by editing the file

Code: Select all

/etc/resolvconf/resolv.conf.d/head
where I put in

Code: Select all

nameserver 8.8.8.8
The funny thing is that my phone (and other devices) can connect to the on-board WLAN flawlessly,
and even the warning sign "NO INTERNET" has disappered.
But it STILL doesn't share the internet of wlan1 (dongle)!

I am starting to suspect three things:
- my dongle/driver cannot function as an AP
- I am failing to privide a proper DNS for wlan0
- Ubuntu Mate's network manager is messing with the manual settings

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

Re: Pi 4 using WLAN dongle + built-in chip

Sat Feb 06, 2021 12:40 pm

Ubuntu Mate's network manager is messing with the manual settings
This works only with Raspbian OS. I have no such code for Ubuntu.
My advice applies to RaspiOS only. Please mention if you use another OS.

Return to “Advanced users”