0

Setting up Raspberry Pi 4B as a routed access point

Hi guys

I want to set up my Raspberry Pi 4B as a routed access point. Many IoT-devices in the subnetwork 192.168.7.x should connect to my RasPi over an Edimax EW-788Un WiFi dongle (wlan1). The RasPi should connect itself to my home network over onboard WiFi (wlan0). Here a list of the resources I have already considered:

Simultaneously connect to a wifi network and create a wifi AP https://github.com/garyexplains/examples/blob/master/raspberry_pi_router.md https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.md

Following those guides, I have apt-get installed the following packages

dnsmasq
hostapd

My files are set up like so:

DHCP

/etc/dhcpcd.conf:

hostname
clientid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option interface_mtu
require dhcp_server_identifier
slaac private

interface wlan1
static ip_address=192.168.7.1/24
nohook wpa_supplicant

dnsmasq

/etc/dnsmasq.conf:

interface=wlan1
dhcp-range=192.168.7.100,192.168.7.120,255.255.255.0,24h
domain=wlan
address=/gw.wlan/192.168.7.1

IP-Forwarding

/etc/sysctl.conf:

net.ipv4.ip_forward=1

/etc/iptables.ipv4.nat:

*filter
:INPUT ACCEPT [20652:1431292]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [15820:11346033]
COMMIT
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A POSTROUTING -o wlan0 -j MASQUERADE
COMMIT

hostapd

/etc/hostapd/hostapd.conf:

country_code=CH
interface=wlan1
driver=nl80211
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=swagsystem
wpa_passphrase=swagsystem

PROBLEM:

Upon start (sudo systemctl start hostapd) of the hostapd service, the following error occurs:

Job for hostapd.service failed because the control process exited with error code.
See "systemctl status hostapd.service" and "journalctl -xe" for details.

Invoking systemctl status hostapd.service yelds:

● hostapd.service - Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator
   Loaded: loaded (/lib/systemd/system/hostapd.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Tue 2020-06-16 14:16:19 CEST; 924ms ago
  Process: 2684 ExecStart=/usr/sbin/hostapd -B -P /run/hostapd.pid -B $DAEMON_OPTS ${DAEMON_CONF} (code=exited, status=1/FAIL

(^^ it cut off there at the end)

iwconfig yields:

eth0      no wireless extensions.

wlan0     IEEE 802.11  ESSID:"NalasEmpire"  
          Mode:Managed  Frequency:5.5 GHz  Access Point: 1C:24:CD:33:35:69   
          Bit Rate=200 Mb/s   Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on
          Link Quality=70/70  Signal level=-40 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:53  Invalid misc:0   Missed beacon:0

lo        no wireless extensions.

wlan1     IEEE 802.11  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm   
          Retry short limit:7   RTS thr=2347 B   Fragment thr:off
          Power Management:off

wlan1 (my edimax dongle) was previously tuned in to the same network as wlan0. The setup kinda did something to it, but idk exactly what.

Does anyone see where I went wrong or what could be the problem?

EDIT1:

  • I switched to using predictable network interfaces (found int sudo rasp-config). This switched my wlan1 to wlx08beac0a717c (idk if that changed sth.)

  • I put in the driver driver=nl80211 back into hostapd (idk if that changed sth.)

  • Made it run by default using sudo update-rc.d hostapd defaults

  • I used sudo hostapd -B /etc/hostapd/hostapd.conf to start the daemon. This turned up an Error in the config file after which it is not allow to use less than 8 characters for the WPA passphrase. Changed that and well: it works! At least to the point that a new network now appears in my choice of available wifi-networks.

A new error appeared though:

wlx08beac0a717c: interface state UNINITIALIZED->COUNTRY_UPDATE

Q1: So I know that for the onboard wifi to set the country code you can do it in raspi-config, but how do I do it for the edimax wifi dongle?

Q2: I'm unsure whether to add an /etc/network/interfaces.d/native_wifi.cfg file. As of the moment I don't have it, but what is its use? Do I need to set the Edimax interface to static and provide a subnetmask? It appears in some guides, but not in all.

glades
  • 155
  • 1
  • 6

1 Answers1

2

it seems there is a problem to coordinate all the additional helpers. But there is an easy way to just configure the Raspberry Pi OS with no need to install additional programs. You can use systemd-networkd to do all things. It has all needed features built-in. You just configure it, what make thinks lean and well-arranged. You can look at Access point as WiFi router/repeater with additional WiFi-dongle how to do it.

Ingo
  • 40,606
  • 15
  • 76
  • 189
  • Thank, I wish I would have stumbled upon your solution earlier! I'm kinda hesitant now to change to the other solution though as it's running quite nicely :) – glades Jun 17 '20 at 13:43
  • @glades If the answer helped you it would be nice if you could accept it ;-) Or if you have found another solution so please write your own answer and accept it after two days. There is nothing wrong with self-answers. Only accepting an answer will finish the question and it will not pop up again and again for years. – Ingo Jun 17 '20 at 16:14
  • "use `systemd-networkd` to do **all** things" ... ? new car for me ? I will have to learn more of this :) +1 – Seamus Jun 17 '20 at 19:17
  • @Seamus "to do all **networking** things ..."? Also to general? (: – Ingo Jun 17 '20 at 20:12