1

I have a Raspberry Pi with 2 WiFi interfaces (built-in and USB dongle). I want to set up one of them (wlan0) to connect to a WiFi router for Internet access and the other one (wlan1) as an Access Point for clients to connect to.

I have the following, which worked perfectly fine in Raspbian Jessie:

/etc/network/interfaces

source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

# eth0 is upstream (Internet - currently unused)
iface eth0 inet manual

# wlan0 is upstream (Internet)
allow-hotplug wlan0
iface wlan0 inet manual

# eth1 and wlan1 are for clients

allow-hotplug eth1
iface eth1 inet manual

allow-hotplug wlan1
iface wlan1 inet manual

wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

/etc/wpa_supplicant/wpa_supplicant.conf

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
  ssid="UPSTREAM_SSID"
  psk="UPSTREAM_PASSWORD"
  proto=WPA
  key_mgmt=WPA-PSK
}

/etc/hostpad/hostapd.conf

logger_syslog=-1
logger_syslog_level=2

interface=wlan1
driver=nl80211
hw_mode=g
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]

ssid=MY_AP_SSID
wpa_passphrase=MY_AP_PASSWORD

This all worked in Jessie. In Raspbian Stretch, however, I cannot see my AP SSID broadcast. iwconfig shows UPSTREAM_SSID as the ESSID for both wlan0 and wlan1.

syslog has this (not sure if relevant):

syslog:Jun  2 16:07:00 atom hostapd[665]: Configuration file: /etc/hostapd/hostapd.conf
syslog:Jun  2 16:07:00 atom hostapd[665]: wlan1: Could not connect to kernel driver
syslog:Jun  2 16:07:00 atom hostapd[665]: Using interface wlan1 with hwaddr WLAN1_MAC and ssid "MY_AP_SSID"
syslog:Jun  2 16:07:00 atom hostapd[665]: wlan1: interface state UNINITIALIZED->ENABLED
syslog:Jun  2 16:07:00 atom hostapd[665]: wlan1: AP-ENABLED
syslog:Jun  2 16:07:00 atom hostapd: wlan1: STA UPSTREAM_ROUTER_MAC IEEE 802.11: disassociated
syslog:Jun  2 16:07:00 atom hostapd: wlan1: STA UPSTREAM_ROUTER_MAC IEEE 802.11: disassociated
syslog:Jun  2 16:07:00 atom hostapd: wlan1: STA UPSTREAM_ROUTER_MAC IEEE 802.11: disassociated
syslog:Jun  2 16:07:00 atom hostapd: wlan1: STA UPSTREAM_ROUTER_MAC IEEE 802.11: disassociated

So it doesn't seem like it's even trying to set up an AP but just connects to the upstream WiFi router using both WiFi cards!

Edit: Forgot to say that I had to add a /etc/dhcpcd.conf file in Stretch - under Jessie these settings were in /etc/network/interfaces

# ... all the stuff from the default file ...

interface eth1
static ip_address=192.168.5.1/24

interface wlan1
static ip_address=192.168.4.1/24

Edit 2: With Epehmeral's help I ended up getting it working by removing the interface wlan1 lines from /etc/dhcpcd.conf and instead adding this to /etc/network/interface:

iface wlan1 inet manual
  post-up ip a add 192.168.4.1/24 dev wlan1
  post-down ip a del 192.168.4.1/24 dev wlan1
EM0
  • 113
  • 5
  • What interface require to be the AP and the wpa client ? if wlan0 must be the AP, you have wrong in your hostapd.conf `interface=wlan1` must be `interface=wlan0` ? And remove `iface wlan0 inet manual` is a good option (because you are the AP and probably you want manipulate the dhcp/dns server) if wlan0 must be the AP. – Ephemeral Jun 02 '19 at 18:33
  • You cannot use `MANAGED mode` of an interface in the same time and `MASTER mode` (this require another configuration). An Access Point use `MASTER mode` only. Here probably you have a bad tool using this interface or a bad configuration in a file, causing your problem ... try to replace: `interface wlan1 static ip_address=192.168.4.1/24` to `interface wlan0 static ip_address=192.168.4.1/24` for your case, you want wlan0 as cllient dhcp/dns... And I do not understand how you assign the IP addresses of your AP clients because I do not see any DHCP / DNS server configuration? – Ephemeral Jun 02 '19 at 20:27
  • I want wlan1 to be the AP and wlan0 the uplink. I don't want wlan0 to have a static IP - that needs to pick up its IP from the upstream DHCP server. wlan1 (the AP) will need a static IP. I tried commenting out the wlan1 lines in dhcpcd.conf, but that hasn't made a difference. Interestingly, when I do `service hostapd restart` quickly followed by `iwconfig` it briefly shows ```wlan1 IEEE 802.11 ESSID:off/any Mode:Managed Access Point: Not-Associated``` but then if I run `iwconfig` again it says ```wlan1 IEEE 802.11 ESSID:"UPSTREAM_SSID" Mode:Managed``` – EM0 Jun 02 '19 at 20:34
  • I'll use dnsmasq as DHCP server for clients, but I'm not getting that far, since a client can't even see the AP SSID, so I didn't mention that in the question. – EM0 Jun 02 '19 at 20:35
  • Ha ok, thanks for the additional information ... I think with your new information. – Ephemeral Jun 02 '19 at 20:38
  • Have you try to : `sudo systemctl stop networking ` ? before trying to run the AP for testing if the AP want start on the interface ? (UP the interface is not require, hostapd will do that) because networking service can use this same interface and then put that in Managed mode when the dhcp client needs a lease or re-lease. (Remove all inet conf for the hostapd interface wlan1, in dhcpcd.conf , network/interfaces ...) I remember meeting a lot of problems with that ... – Ephemeral Jun 02 '19 at 20:52
  • Just tried `systemctl stop networking` and that disconnected me from the Internet (wlan0). Both wlans were still in managed mode but it tried to use wlan1 for the uplink and wlan0 was "unassociated". What I still don't understand is how wpa_supplicant decides which interface to use for its configuration. Some websites describe a wpa_supplicant configuration with multiple networks and http://blog.hoxnox.com/gentoo/wifi-hotspot.html describes how to configure an AP with it, without hostapd. That would be ideal for me in principle, but how do I tell it: use wlan0 for network X and wlan1 for Y. – EM0 Jun 02 '19 at 20:52
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/94423/discussion-between-ephemeral-and-em0). – Ephemeral Jun 02 '19 at 20:53

3 Answers3

2

A common mistake is the conflict between hostapd and the raspbian networking service that uses the same interface and therefore two different modes which causes the access point to stop. Ensure the interface is not used by the network service for get an ip address in '/etc/network/interfaces'and remove any dhcp configuration related to the AP interface.

enter image description here

Ephemeral
  • 2,057
  • 4
  • 18
  • 2
    With Epehmeral's help I ended up getting it working by removing the `interface wlan1` lines from /etc/dhcpcd.conf and instead adding this to /etc/network/interface: `iface wlan1 inet manual` `post-up ip a add 192.168.4.1/24 dev wlan1` `post-down ip a del 192.168.4.1/24 dev wlan1` – EM0 Jun 02 '19 at 23:48
1

The "solution" you have adopted uses an illegitimate mix of 2 networking systems. It may "work", but will not be robust. It would work, if you disable dhcpcd, otherwise you will have 2 systems trying to configure the networks, with unpredictable results.

The "correct" way of setting up one interface as an Access Point is to tell dhcpcd NOT to configure it. See Prevent dhcpcd from configuring an interface in How to set up networking/WiFi

Specifically add denyinterfaces wlan1 to the end of the /etc/dhcpcd.conf file (but above any other added interface lines). This allows dhcpcd to operate normally on wlan0.

See the Foundation tutorial Access Point

PS Any time you use multiple interfaces you should use Predictable Network Interface Names; The on-board WiFi will usually win the race between configuring the 2, but it is better to explicitly manage this, to avoid any race condition.

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • Well ideally I'd avoid dhcpcd at all. In Jessie I was able to configure dhcp just using /etc/network/interfaces, but I couldn't get that to work in Stretch. – EM0 Jun 03 '19 at 00:09
  • 1
    @EM0 that is your choice - it is possible to use Debian networking by disabling dhcpcd if you want (the linked tutorial explains how), but dhcpcd is more robust, which is why the Foundation adopted it. Disabling dhcpcd will prevent the GUI networking tool from running. – Milliways Jun 03 '19 at 00:13
  • Ah, thanks for `denyinterfaces`. You're probably right and I'm voting your answer, but after having spent over 10 hours (!!!) on this I simply do not want to spend another minute on it now as long as it works! – EM0 Jun 03 '19 at 18:05
0

Here is another suggestion to setup two physical WiFi interfaces to be used as access point and as uplink. You can use systemd-networkd to do everything consistent with only one networking system. There is no need to combine different networking systems like ifupdown and dhcpcd or install additional helpers like hostapd or dnsmasq. Everything is built-in.

With systemd-networkd you can give each interface its own service so you can configure and manage it independent from the other. How to do it you can look at Access point as WiFi repeater with additional WiFi-dongle.

Ingo
  • 40,606
  • 15
  • 76
  • 189