I need to share my eth0 with two WLAN CARD:
1 -> DONGLE WIFI TP-LINK (WLAN 0)
2 -> INTEGRATED WIFI OF RASPBERRY (WLAN 1).
I tried with RASPAP, create_AP but only one works :s, how can i make work both?
Thanks for helping
I need to share my eth0 with two WLAN CARD:
1 -> DONGLE WIFI TP-LINK (WLAN 0)
2 -> INTEGRATED WIFI OF RASPBERRY (WLAN 1).
I tried with RASPAP, create_AP but only one works :s, how can i make work both?
Thanks for helping
You have two physical WiFi interfaces available to create two access points, the built-in wlan0 and that from the USB/WiFi dongle wlan1. With systemd-networkd you can make two independent services. Then you can use routing or bridging to get connected to the internet with your home internet router. With routing you have different subnets with different ip address ranges for each access point and for your home network. With a bridge, all devices, no matter what access point they are connected to, will become a member of your home network with its ip address range and its resources. They will also use the DHCP server from the home internet router so you don't have to worry about that.
Tested with
Raspbian Buster Lite 2019-09-26 on a Raspberry Pi 4B updated at 2019-10-18
Updates done with sudo apt update && sudo apt full-upgrade && sudo reboot
.
For detailed information look at (1). Here only in short. Execute these commands:
# disable classic networking
rpi ~$ sudo -Es
rpi ~# systemctl mask networking.service 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 systemd-resolved.service
rpi ~# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
To configure wpa_supplicant create these 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):
rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf <<EOF
country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="RPiNet"
mode=2
key_mgmt=WPA-PSK
psk="verySecretPassword"
frequency=2412 # channel 1
}
EOF
rpi ~# chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
rpi ~# systemctl disable wpa_supplicant.service
rpi ~# systemctl enable wpa_supplicant@wlan0.service
Repeat the setup for wlan0 as shown above but just replace all substrings wlan0
with wlan1
and the settings ssid=
and psk=
. Using another frequency, maybe 2437 (channel 6), is a good idea for performance reasons because wifi channels are a shared medium.
Start with General Setup. Then come back here.
We need a Network Address Translation (NAT) on interface eth0 to reach all devices on the access points. Create it with:
rpi ~# systemctl --full --force edit nat@.service
In the empty editor insert these statements, save them and quit the editor:
[Unit]
Description=NAT for interface %i
After=systemd-networkd.service
BindsTo=systemd-networkd.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/iptables -t nat -A POSTROUTING -o %i -j MASQUERADE
ExecStopPost=-/sbin/iptables -t nat -D POSTROUTING -o %i -j MASQUERADE
[Install]
WantedBy=systemd-networkd.service
Enable the new service:
rpi ~# systemctl enable nat@eth0.service
Create these files:
rpi ~# cat > /etc/systemd/network/04-eth0.network <<EOF
[Match]
Name=eth0
[Network]
DHCP=yes
IPForward=yes
EOF
rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
Address=192.168.4.1/24
DHCPServer=yes
[DHCPServer]
DNS=84.200.69.80 1.1.1.1
EOF
rpi ~# cat > /etc/systemd/network/12-wlan1.network <<EOF
[Match]
Name=wlan1
[Network]
Address=192.168.5.1/24
DHCPServer=yes
[DHCPServer]
DNS=84.200.69.80 1.1.1.1
EOF
Reboot.
That's it.
Start with General Setup. Then come back here.
We have to tell wpa_supplicant that its interface is slave of a bridge. Otherwise it will reject client connects with "wrong password" means the key negotiation does not work. When we tell /sbin/wpa_supplicant with option -dbr0
to use a bridge then the interface must already be a member of the bridge. That's what we do with the drop in file (overlay) for the wpa_supplicant service. The empty statement ExecStart=
deletes the old entry. Otherwise you have two lines ExecStart=
and wpa_supplicant will start two times. The original ExecStart=
you can view with systemctl cat wpa_supplicant@.service
. Modify its service with:
rpi ~# systemctl edit wpa_supplicant@.service
In the empty editor insert these statements, save them and quit the editor:
[Service]
ExecStartPre=/sbin/iw dev %i set type __ap
ExecStartPre=/bin/ip link set %i master br0
ExecStart=
ExecStart=/sbin/wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-%I.conf -Dnl80211,wext -i%I -bbr0
ExecStopPost=-/bin/ip link set %i nomaster
ExecStopPost=-/sbin/iw dev %i set type managed
Create these files:
rpi ~# cat > /etc/systemd/network/02-br0.netdev <<EOF
[NetDev]
Name=br0
Kind=bridge
EOF
rpi ~# cat > /etc/systemd/network/04-br0_add-eth0.network <<EOF
[Match]
Name=eth0
[Network]
Bridge=br0
EOF
rpi ~# cat > /etc/systemd/network/12-br0_up.network <<EOF
[Match]
Name=br0
[Network]
DHCP=yes
EOF
Reboot.
That's it.
references:
[1] Howto migrate from networking to systemd-networkd with dynamic failover
key_mgmt=WPA-PSK
or add lineproto=RSN WPA
to the network block in/etc/wpa_supplicant/wpa_supplicant.conf
. – Ingo Oct 18 '19 at 16:21PoolOffset=
andPoolSize=
in section [DHCPServer]. Look atman systemd.network
for this. – Ingo Oct 18 '19 at 17:01network={ mode=2 ssid="Work" psk="Password01" frequency=2412 proto=RSN key_mgmt=WPA-PSK pairwise=CCMP group=CCMP auth_alg=OPEN }
Even a windows computer tell me: " Unable to connect to this network. – Pi3.14 Oct 21 '19 at 08:37