2

I have the following equipment that I wish to utilise.

My internet connection is provided by way of a TP-Link M7350 3/4G modem. This does have a USB output that is capable of data sharing, but I don’t think that’s any use in this application.

My LAN is managed by an ASUS RT-AC51U. This has a USB port for a ‘back up’ 3/4G modem, but doesn’t appear compatible with the TPLink.

My next thought is to use a spare Pi Zero-W to bridge the gap, but I don’t know what terminology to search for, as networking is not my area at all!

I’m wondering if I can connect the Pi Wifi to the 4G modem (Yes, I can) but then route the internet traffic from 4G modem to Pi Zero Wifi, Pi Zero USB>Ethernet adapter, to the DSL port of the ASUS Router?

Is the Pi then an AP, Bridge, or something else?

I suspect the correct answer is in here, but unsure whereabouts Setting up a Raspberry Pi as an access point - the easy way

Thanks

4
  • 1
    The Raspi is a router. It routes traffic from the 4G modem through its wifi connection to the wired ethernet port and there to the DSL router and backwards. Where are the clients located that want to get into the internet? Are they all connected to the DSL router, or are they associated to the access point from the 4G modem, or mixed up?
    – Ingo
    Oct 17, 2018 at 13:29
  • Hey, they are connected (wired) to the DSL router. It’s a Pi Zero so doesn’t have an Ethernet port but i can get a USB > Ethernet adapter, right?
    – user92917
    Oct 17, 2018 at 14:11
  • Yes, you can use an USB to Ethernet adapter. As I understand there is the RPi0W used as router for the 4G modem and there is only one client, also a RPi0 (without wireless) that is connected to the DSL router and want to get into the internet. For what is the DSL connection? Does it isn't connected to an internet provider as usual?
    – Ingo
    Oct 17, 2018 at 15:55
  • Well I just want the RPi0W to ‘transfer’ the 4G internet connection in to the DSL router. I can connect the Rpi to the router via and Ethernet adapter and WAN port. All clients then connect to the router. But what is the Pi acting as? A bridge, a gateway, an access point!? I’m lost
    – user92917
    Oct 17, 2018 at 16:19

1 Answer 1

0

You can make the Raspberry Pi a router that routes ethernet packages between ethernet and wifi interface. It is not an access point. It connects by WiFi to the access point of the 4G modem. It is also not a bridge. Bridging on a wifi client connection is not supported by the on board wifi chip (1). From the view of the DSL router it may be a gateway to the internet, but I would say the real gateway is the 4G modem.

For a router you have to use different subnets, for example 192.168.4.0/24 for the 4G modem and the wifi connection to it and 192.168.10.0/24 for the wired ethernet connection to the DSL router. The most difficult thing on this setup could be that you have to configure the DSL router for its default gateway. There is no way around this.

I will show you how you can make the RasPi a router. I will use systemd-networkd for reasons. For reference I use Raspbian Stretch Lite 2018-06-27 updated with sudo apt update && sudo apt full-upgrade && sudo reboot.

Example for this setup:

                                                                     Client_A
               4G                NAT                                /
 INTERNET <-> modem <~.wifi.~> (wlan0)RPi(eth0) <---wired---> router <--wan--> DSL
                   \             /          \                /      \
               192.168.4.1    (dhcp)   192.168.10.60  192.168.10.1   Client_B

Setup systemd-networkd

For detailed information look at (2). Here only in short. Execute these commands:

rpi ~$ sudo -Es
rpi ~# systemctl mask networking.service
rpi ~# systemctl mask dhcpcd.service
rpi ~# sudo mv /etc/network/interfaces /etc/network/interfaces~
rpi ~# sed -i '1i resolvconf=NO' /etc/resolvconf.conf

rpi ~# systemctl enable systemd-networkd.service
rpi ~# systemctl enable systemd-resolved.service
rpi ~# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

Setup wifi client connection

Setup wpa_supplicant with this file and your settings for country=, ssid= and psk= and enable it. 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="[email protected]"
    psk="verySecretPassword"
}
EOF

rpi # chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
rpi # systemctl disable wpa_supplicant.service
rpi # systemctl enable [email protected]

There is a service to start and stop wpa_supplicant for the wifi connection. We add to it rules to manage a network address translation (NAT) that we need to connect to the 4G modem without static routes. Create a drop in file (3):

rpi ~# systemctl edit [email protected]

In the empty editor insert these statements, save them and quit the editor. Pay attention to the minus sign =-:

[Service]
ExecStartPost=/sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
ExecStopPost=-/sbin/iptables -t nat -D POSTROUTING -o wlan0 -j MASQUERADE

Configure interfaces

Create these files for interfaces eth0 and wlan0 with your settings. For eth0 don't use an ip address which is in the pool of the DHCP server from the DSL router.

rpi ~# cat > /etc/systemd/network/04-eth0.network <<EOF
[Match]
Name=eth0
[Network]
Address=192.168.10.60/24
IPForward=yes
EOF

rpi ~~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
DHCP=yes
EOF

Routing

To get routing complete working you have to configure the default gateway on the DSL router. You have to look how to configure it there. The DSL router is living on subnet 192.168.10.0/24 and it knows where to send packages with destination address of this subnet. But it does not know where to send packages with other destination addresses, means addresses to the internet. For this there is a default gateway to set. Set it on your DSL router to 192.168.10.60 so it sends all packages it does not know to this ip address. It's the RasPi and it knows where to go on. It sends the packages to its default gateway, that is 192.168.4.1, and so on. That's routing.

The RasPi has got its ip address on wlan0, e.g. 192.168.4.108, from the access point of the 4G modem. From that it has also got the default gateway to the 4G modem. It should look similar to this:

rpi ~$ ip route show
default via 192.168.4.1 dev wlan0 proto dhcp src 192.168.4.108 metric 1024
192.168.4.0/24 dev wlan0 proto kernel scope link src 192.168.4.108
192.168.4.1 dev eth0 proto dhcp scope link src 192.168.4.108 metric 1024
192.168.10.0/24 dev eth0 proto kernel scope link src 192.168.10.60

The important line is the first one with the default route. Don't be confused with this showing, it's only for understanding. It should be set automatically. You have to define the default route in the DSL router.

Reboot.
That's it.


refefences:
[1] Raspberry Pi WiFi to Ethernet Bridge for a server?
[2] Howto migrate from networking to systemd-networkd with dynamic failover
[3] man systemd.unit - overriding vendor settings

3
  • Ok, thanks for that it’s a great help! The router is now showing as connected to the internet, but clients connected to the router are unable to load pages. I told the router the internet connection is static IP with these details ‘IP Address: 192.168.4.0, Subnet Mask 255.255.255.0 and Default Gateway 192.168.10.60, based on your description of changes to files. I used Open DNS for the DNS servers, any ideas?
    – user92917
    Oct 20, 2018 at 14:14
  • Ah, found static route section and entered settings, still unsure as to how to set the internet connection (via the Rpi and 4g router) setting
    – user92917
    Oct 20, 2018 at 14:36
  • @user92917 It's always a bit difficult to configure a network i don't have access. It seems you don't need a static route. So forget it. You have to set the default gateway on the DSL router. I hope that does not disrupt the DSL connection. We will see. I have updated my answer.
    – Ingo
    Oct 20, 2018 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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