I'm trying to make a very simple setup with my RPi. On the on-board standard wlan0 I want to connect to my home network normally, using a wpa_supplicant file this works very well.

Now I'm having issue because I plugged a wifi dongle in my RPi (Trendnet TEW-649UB) and I want to setup an AP on wlan1. It is properly detected by my RPi and I can ifconfig it.

wlan1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
    ether 00:14:d1:be:6a:a3  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

Now before anyone says look at the hundred of posts on the internet, I did and very few of them actually are for Raspbian Stretch, even the ones on the official website do not take into account Stretch.

Just for the record:

pi@race_tracker_gateway:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION="9 (stretch)"

So first here are my wpa_supplicant files. First the wlan0 one, which works fine because it connects at start-up to my network without any issue.

pi@race_tracker_gateway:~ $ cat /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
# allow frontend (e.g., wpa_cli) to be used by all
ctrl_interface=/var/run/wpa_supplicant GROUP=netdev
# home network; allow all valid ciphers
    id_str="Home WiFi"

I'm not really sure on what to put in the wlan1 supplicant file so I just kept the basics

pi@race_tracker_gateway:~ $ cat /etc/wpa_supplicant/wpa_supplicant-wlan1.conf
ctrl_interface=/var/run/wpa_supplicant GROUP=netdev

Searching around on the internet, after a while I found out I should not be modifying my /etc/network/interfaces file, so it is as default.

pi@race_tracker_gateway:~ $ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

Then I used part of this guide to configure dhcpcd : https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md My goal is to set a static ip address to the AP interface so I simply put the two last lines as shown here

pi@race_tracker_gateway:~ $ tail /etc/dhcpcd.conf 
#static ip_address=
#static routers=
#static domain_name_servers=

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0

interface wlan1
static ip_address=

I setup the dhcp address pool

pi@race_tracker_gateway:~ $ cat /etc/dnsmasq.conf
interface=wlan1      # Use the require wireless interface - usually wlan0

Then I configured hostapd and that's where I need help. Here is the content.

pi@race_tracker_gateway:~ $ cat /etc/hostapd/hostapd.conf

My problem is related to the driver line, because when I start hostapd I get an error.

pi@race_tracker_gateway:~ $ sudo hostapd /etc/hostapd/hostapd.conf 
Configuration file: /etc/hostapd/hostapd.conf
Line 2: invalid/unknown driver 'r8712u'
1 errors found in configuration file '/etc/hostapd/hostapd.conf'
Failed to set up interface with /etc/hostapd/hostapd.conf
Failed to initialize interface

I got the driver name doing the following

pi@race_tracker_gateway:~ $ sudo lshw -C network
       description: Wireless interface
       physical id: 3
       bus info: usb@1:1.2
       logical name: wlan1
       serial: 00:14:d1:be:6a:a3
       capabilities: ethernet physical wireless
       configuration: broadcast=yes driver=r8712u multicast=yes wireless=unassociated

However for some reason hostapd refuses to use that driver. I can get more info on the driver doing this.

pi@race_tracker_gateway:~ $ modinfo r8712u
filename:       /lib/modules/4.14.62-v7+/kernel/drivers/staging/rtl8712/r8712u.ko
firmware:       rtlwifi/rtl8712u.bin
author:         Larry Finger
description:    rtl871x wireless lan driver
license:        GPL

So I really don't understand why hostapd refuses this driver. When using the standard nl80211 I get the following error (if you are wondering why I changed driver).

pi@race_tracker_gateway:~ $ sudo hostapd /etc/hostapd/hostapd.conf
Configuration file: /etc/hostapd/hostapd.conf
nl80211: Could not configure driver mode
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
nl80211 driver initialization failed.
wlan1: interface state UNINITIALIZED->DISABLED
hostapd_free_hapd_data: Interface wlan1 wasn't started

So I guess here is my story, this is driving crazy, also it's driving me crazy because I've been trying to solve this problem for days and at some point I even managed to make it work, I could see my AP wifi, wlan1 was assigned the correct IP but after a reboot of the RPi and probably some more changing of settings it doesn't work anymore.

If someone could help me I'd be really grateful because I'm starting to think I'm crazy. I suspect something is wrong with the dongle because everytime I reboot my Pi I have the physically unplug and replug the dongle for it to show up as wlan1 so I guess something must be wrong.

  • I finally fixed it... I guess writing all of this out was good! The problem was related to a bug in the Linux Kernel, I did a sudo rpi-update and it's now working after reboot. Still having to restart hostapd after a reboot but that's a minor annoyance compared to not having it work at all.
    – Leo
    Commented Aug 29, 2018 at 15:53

1 Answer 1


I have found that it is better to use wlan0 as interface for the access point and wlan1 as client up-link. But this other way around does not answer the question. So I have made a new question Access point as WiFi repeater with additional WiFi-dongle. Look there for an up to date configuration. This answer here will not maintained anymore.

The real issue isn't a bug in the kernel. I assume that's why to much different components must play together.

Btw. it isn't a good idea to execute rpi-update unless yo exactly know why to do this or told by a developer to do it for testing. On github - rpi-update You will find:

Even on Raspbian you should only use this with a good reason. This gets you the latest bleeding edge kernel/firmware. There is always the possibility of regressions. Bug fixes and improvements will eventually make their way into new Raspbian releases and apt-get when they are considered sufficiently well tested. A good reason for using this would be if you like to help with the testing effort, and are happy to risk breakages and submit bug reports. These testers are welcome.

Do you know that the Raspberry Pi can span an access point and connect as client to another wifi network with its on board wifi chip? You do not need a second wifi dongle. How to do that you can look at Access point as WiFi repeater, optional with bridge.

But using a second wifi dongle is really very easy. With systemd-networkd and wpa_supplicant we have everything on the Raspberry Pi to setup what you want in a consistent way. There is no need to install additional software and fiddle with hostapd and dnsmasq. You have to switch to systemd-networkd and then simply set up wpa_supplicant one time for wlan0 as client and one time for wlan1 as access point. Then configure the interfaces and it's done. Let's do it. For reference I use Raspbian Stretch Lite 2018-11-13 updated with sudo apt update && sudo apt full-upgrade && sudo reboot done at 2019-02-02.

Enable systemd-networkd

For detailed information look at (1). Here only in short. Execute these commands:

# disable classic networking
rpi ~$ sudo -Es
rpi ~# systemctl mask networking.service
rpi ~# systemctl mask dhcpcd.service
rpi ~# mv /etc/network/interfaces /etc/network/interfaces~
rpi ~# sed -i '1i resolvconf=NO' /etc/resolvconf.conf

# enable systemd-networkd
rpi ~# systemctl enable systemd-networkd.service
rpi ~# systemctl enable systemd-resolved.service
rpi ~# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

Configure wpa_supplicant as client and as access point

To configure wpa_supplicant create these two files with your settings for country=, ssid=, psk= and maybe frequency= You can just copy and paste this in one block to your command line beginning with cat and including EOF (delimiter EOF will not get part of the file):

A) For client connection:

rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf <<EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

    ssid="[email protected]"

rpi ~# chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
rpi ~# systemctl enable [email protected]

For the connection to the internet router we use network address translation (NAT). To setup it we extend the service for wlan0 with:

rpi ~# systemctl edit [email protected]

In the empty editor insert these statements, save them and quit the editor:

ExecStartPre=/sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
ExecStopPost=-/sbin/iptables -t nat -D POSTROUTING -o wlan0 -j MASQUERADE

B) As access point:

rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan1.conf <<EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


rpi ~# chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan1.conf
rpi ~# systemctl enable [email protected]

Configure interfaces

Create these two files:

rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF

Because we don't have a bridge, so we need two different subnets. Be aware that the static ip address for the access point wlan1 belongs to another subnet than that from wlan0.

rpi ~# cat > /etc/systemd/network/12-wlan1.network <<EOF

That's it.

[1] Howto migrate from networking to systemd-networkd with dynamic failover

  • First of all, thanks a lot for the comment, it helps a lot! I really don't understand why all tutorials keep talking about /etc/interfaces etc... This method is way easier in my opinion. Anyway I wasn't aware I didn't need a dongle to do what I wanted so I followed the instructions and everything seem to be set properly, I have my wlan0 connect to my network properly and can access internet, then I have an ap0 interface which also get the correct static ip address however I can never see the AP from my mobile phone.
    – Leo
    Commented Sep 3, 2018 at 16:22
  • 1
    After looking around I finally found the problem... I had setup a passphrase of only 4 characters which is not enough so hostapd refused to start. I wish this problem would be easier to find!
    – Leo
    Commented Sep 3, 2018 at 16:48
  • @Leo Thanks for the hint. I will update that answer to share it with the community.
    – Ingo
    Commented Sep 3, 2018 at 18:31
  • No problem, you were really of a tremendous help thanks a lot! Now it works, I have one issue left now is that somehow I cannot reach my postgresql from the ap interface but I can from the wlan0 which is weird...
    – Leo
    Commented Sep 3, 2018 at 19:06
  • 1
    Just checked: ping -I wlan1 doesn't work because it tries to get through the AP (wlan1) to the internet. My assumption with ip forwarding was wrong. I do ping from my mobile phone (associated to the AP) and I get replies. Also browsing the internet works. Btw. it is a good idea to install helper sudo apt install rng-tools to get random numbers quicker for encryption.
    – Ingo
    Commented Feb 2, 2019 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.