1

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

  • @Ingo i tried your solution there: raspberrypi.stackexchange.com/questions/95072/… - I made the access point 2 times , one for wlan 0 and the other for wlan 1. It works well, i have two different SSID. Where i'm blocking now is i have DHCP on wlan 0 but not on wlan 1 . And on wlan 0 , i received an IP but i can't go to internet :/ I have to bridge the wlan to ethernet?? Thanks for your help! :) – Pi3.14 Oct 17 at 7:51
  • @Ingo Now i can have internet on wlan1 :) with this metod (NAT METOD)raspberrypi.stackexchange.com/questions/88214/… but on wlan0 dhcp server does not work :( on wlan1 the DHCP work great. – Pi3.14 Oct 17 at 12:39
  • @Ingo i made a mistake on the file 08-wlan0.service 09-wlan0.service. The 09-** file started with wlan0, i changed with wlan1 it works like a charm!!!! <3 thansk a lot for your easy steps to follow – Pi3.14 Oct 17 at 12:59
  • 1
    The problem that the samsung device cannot connect is another problem. Please open an new question about it. The comments here are not the right place to ask for details to present a solution. – Ingo Oct 21 at 8:45
2

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.


♦ General Setup

Enable systemd-networkd

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

Configure wpa_supplicant for wlan0 as access point

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

Configure wpa_supplicant for wlan1 as access point

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.


♦ Setup with routing

Start with General Setup. Then come back here.

Service for Network Address Translation

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

Configure interfaces

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.


♦ Setup with a bridge

Start with General Setup. Then come back here.

Prepare wpa_supplicant to use a bridge

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

Configure interfaces

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

  • that's right!! :) Thank you – Pi3.14 Oct 18 at 13:23
  • @Pi3.14 If anything help you so please accept the answer and/or upvote some of them. I have upvoted your question so you have more than 15 reputations to do that. Have you read the Help Center how this site works? – Ingo Oct 18 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.