2

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

Pi3.14
  • 47
  • 6
  • Possible duplicate of [2 Wifi NIC's that each only connect to one (different from each other) network](https://raspberrypi.stackexchange.com/questions/98753/2-wifi-nics-that-each-only-connect-to-one-different-from-each-other-network) – Ingo Oct 16 '19 at 17:19
  • @Ingo i tried your solution there: https://raspberrypi.stackexchange.com/questions/95072/access-point-as-wifi-router-repeater-with-additional-wifi-dongle - 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 '19 at 07:51
  • @Ingo Now i can have internet on wlan1 :) with this metod (NAT METOD)https://raspberrypi.stackexchange.com/questions/88214/setting-up-a-raspberry-pi-as-an-access-point-the-easy-way/88234#88234 but on wlan0 dhcp server does not work :( on wlan1 the DHCP work great. – Pi3.14 Oct 17 '19 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 '19 at 12:59
  • It was unclear to me that you wanted two access points instead of having two client connections to two different remote hotspots. What do you do with **eth0**? Does this is connected to your home internet router? Do you want to have all devices on the same subnet of the home internet router, or do you want different subnets for access point WLAN0 and WLAN1? – Ingo Oct 17 '19 at 16:42
  • If my tutorials help you, it would be nice if you could upvote it? ;-) – Ingo Oct 17 '19 at 16:52
  • If you could outline how you got this to work in an answer that'd be great. – Fred Oct 18 '19 at 06:40
  • @Ingo I wanted to share my internet connection (home internet router) (ETH0) to 2SSID: Work and Guest. Work is on 192.168.50.1 and GUEST on 10.3.141.1. two different network. It works well :) – Pi3.14 Oct 18 '19 at 06:45
  • @Ingo how i can see the DHCP leases and where i can change dhcp range? because some people can connect 2 or 3, but not everybody. – Pi3.14 Oct 18 '19 at 08:46
  • @Ingo forget about DHCP, the fact is samsung device cannot connect to this. They need WPA2-AES minimum. What i can change on wpa_supplicant config to have WPA2-AES – Pi3.14 Oct 18 '19 at 13:25
  • After accept and/or any upvotes I will look ... ;-) – Ingo Oct 18 '19 at 14:51
  • @Ingo i dit it! – Pi3.14 Oct 18 '19 at 15:16
  • About WPA2-AES: try with deleted line `key_mgmt=WPA-PSK` or add line `proto=RSN WPA` to the network block in `/etc/wpa_supplicant/wpa_supplicant.conf`. – Ingo Oct 18 '19 at 16:21
  • I have googled for the place where [DHCPServer] stores its served leases but couldn't find anything, only similar questions without an answer. DHCP range can be changed with options `PoolOffset=` and `PoolSize=` in section [DHCPServer]. Look at `man systemd.network` for this. – Ingo Oct 18 '19 at 17:01
  • @Ingo does not work :( i tried this in relation with this https://w1.fi/cgit/hostap/plain/wpa_supplicant/wpa_supplicant.conf `network={ 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
  • 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 '19 at 08:45

1 Answers1

3

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

Ingo
  • 40,606
  • 15
  • 76
  • 189
  • that's right!! :) Thank you – Pi3.14 Oct 18 '19 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](https://raspberrypi.stackexchange.com/help) how this site works? – Ingo Oct 18 '19 at 14:49