epoch1970
Posts: 2420
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Need help to make an hostapd AP on an RPI2 Raspbian Stretch

Sat Mar 16, 2019 6:06 pm

A bridge is like a physical network switch.
All interfaces that are member of a bridge belong to the same (L2) network, interfaces communicate directly with each other, based on their unique MAC address. To connect that network to other networks, IP (L3) and routing is used.

It is not possible to bridge a wifi interface that is a client (STA mode). The WiFi standard prohibits it.
It is possible to bridge a wifi interface that operates in AP mode. The WiFi standard allows it.

This is possible but only with ethernet + wifi AP:

Code: Select all

Internet <->[ISP box]<--ethernet LAN-->[eth0 Pi3 wlan0].)))   (((.[wifi client]
                     192.168.1.1          192.168.1.2              192.168.1.3
The Pi is setup as a bridged AP. Its bridge interface gets a single address from the ISP box. Clients get their address from the ISP box, through the bridge (the bridge is like a network switch). Every machine "sees" 2 other machines.

The only possible design with a wifi STA is this:

Code: Select all

Internet <->[ISP box].))) wifi LAN#1 (((.[wlan0 Pi3 wlan1].)))  wifi LAN#2  (((.[wifi client to Pi]
               192.168.1.1       192.168.1.2         192.168.4.1         192.168.4.2
The ISP box is a router + wifi AP. The Pi is a wifi client to the ISP box, a router + wifi AP to some clients. The Pi has 2 addresses, one on each network. The ISP box "sees" 2 machines: itself and the Pi. The Pi "sees" the ISP box, and all its wifi clients. When a wifi client to the Pi wants to go to the Internet, the Pi masquerades the traffic as if it were requested by itself, that keeps the ISP box happy.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

deli13
Posts: 10
Joined: Mon Mar 11, 2019 6:03 pm

Re: Need help to make an hostapd AP on an RPI2 Raspbian Stretch

Mon Mar 18, 2019 1:01 pm

I have tried to rebuild it using wlan1 instead of eth0 and stuck at the following:

sudo brctl addif br0 wlan1
can't add wlan1 to bridge br0: Operation not supported

Also,
systemctl status hostapd.service
● 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 Mon 2019-03-18 12:55:20 GMT; 2s ago
Process: 1376 ExecStart=/usr/sbin/hostapd -P /run/hostapd.pid -B $DAEMON_OPTS ${DAEMON_CONF} (code=exited, status=1/FAILURE)

Mar 18 12:55:20 DeliPi systemd[1]: hostapd.service: Control process exited, code=exited status=1
Mar 18 12:55:20 DeliPi systemd[1]: Failed to start Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator.
Mar 18 12:55:20 DeliPi systemd[1]: hostapd.service: Unit entered failed state.
Mar 18 12:55:20 DeliPi systemd[1]: hostapd.service: Failed with result 'exit-code'.
Mar 18 12:55:22 DeliPi systemd[1]: hostapd.service: Service hold-off time over, scheduling restart.
Mar 18 12:55:22 DeliPi systemd[1]: Stopped Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator.
Mar 18 12:55:22 DeliPi systemd[1]: Starting Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator...

My hostapd.conf

interface=wlan0
bridge=br0
#driver=nl80211
ssid=DeliPiAP
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=060901261209
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

epoch1970
Posts: 2420
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Need help to make an hostapd AP on an RPI2 Raspbian Stretch

Mon Mar 18, 2019 3:28 pm

deli13 wrote:
Mon Mar 18, 2019 1:01 pm
can't add wlan1 to bridge br0: Operation not supported
that is of no consequence. From its config file, hostapd adds wlan0 to br0 itself.
You don't need to do it manually.

If you do it manually, the interface must be in AP mode beforehand (cf. my last post). It's in STA mode by default, hence "Operation not supported".

EDIT. I see you're still trying to add both interfaces to the bridge... Good luck, then.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

deli13
Posts: 10
Joined: Mon Mar 11, 2019 6:03 pm

Re: Need help to make an hostapd AP on an RPI2 Raspbian Stretch

Mon Mar 18, 2019 6:49 pm

Removed 'bridge' part.
Now I can connect the the AP (wlan0) and have an IP from desired range: 192.168.4.2-192.168.4.11

The only thing left is to use wlan1 instead of eth0.

deli13
Posts: 10
Joined: Mon Mar 11, 2019 6:03 pm

Re: Need help to make an hostapd AP on an RPI2 Raspbian Stretch

Mon Mar 18, 2019 10:44 pm

sudo iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE did the trick.

Now I have working set which contains:

Raspberry Pi 2
Two Edimax EW-7811-Un dongles
wlan0 used as AP with static IP 192.168.4.1; clients get IP from Pi's dhcpcd with range 192.168.4.2-192.168.4.11
wlan1 used for connecting to the Internet; gets IP from ISP dhcp server
etho not used (but still active and can be used instead of wlan1)

Issues I have:

When trying to switch internet connection on wlan1, Pi cannot connect. Moreover, it loses its previous connection. After Pi reboot everything works with previous connection, but still cannot switch to another one. Will test by turning the previous connection (router) off.

Planning to create an IP reservation by MAC for Pi's clients.

rudiratlos
Posts: 125
Joined: Tue May 01, 2012 8:47 am

Re: Need help to make an hostapd AP on an RPI2 Raspbian Stretch

Tue Mar 19, 2019 4:03 pm

you can use this script, it uses 2 wlan adapter. wlan0 as hotspot adpter. eth0 or wlan1 for internet connection.

https://github.com/rudiratlos/hotspot

Return to “Networking and servers”