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

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,167
  • 1
  • 8
  • 19
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
  • 62,573
  • 32
  • 113
  • 225
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
  • 42,961
  • 20
  • 87
  • 207