1

I have a USB data modem (Huawei E3131) and a RaspberryPi 3B+. I would like to use the Pi as a Wi-Fi hotspot. Pi connects to the internet via USB data modem and creates hotpsot for other devices. So, I've came up with two options:

  1. Using Pi's Wi-Fi module
  2. Using Pi's ethernet port and external router (preferable)

However, I don't really know how to approach the problem and if it's even possible. Thanks for any help and suggestions on how to accomplish it.

  • First of all you need an internet connection established with the data modem. Do you have one? What does "two options" mean? Do you want to connect to the internet on the ethernet port and when it isn't available, then connect by data modem? – Ingo May 26 at 9:59
  • @Ingo I described everything in a very straightforward way in the post. What you don't understand? I have an USB data modem. I want to connect it to my RaspberryPi via USB. Pi connects to the internet via USB data modem. Then, it shares the connection via ethernet with my Wi-Fi router, so that other devices can connect to the internet. – leller May 26 at 12:53
  • You want to connect the USB data modem to the RasPi. Did you actually do it and have an internet connection? That was my question. If not then you should do and write: "I have established an internet connection to my provider with the data modem." This is important because I cannot help you with this and it doesn't make sense to work on an answer without it. Then you wrote about two options. That I understood as the one option or the other. – Ingo May 26 at 13:07
  • Alright, sorry, then. Yes, I managed to get the internet working. Pi is connected to the internet via USB cellular data modem – leller May 26 at 13:12
  • There is another point I do not understand. You "would like to use the Pi as a Wi-Fi hotspot" and from the comment: "it shares the connection via ethernet with my Wi-Fi router". Do you want to have two access points, one on the RasPi and one with your Wi-Fi router? – Ingo May 26 at 13:19
0

I assume the RasPi is connected to the internet with interface ppp0 and get the ip address for it from the USB data modem. To eth0 you have to give a static ip address. I use 192.168.50.2 for example.

Example for this setup:

                    wired                    USB         wan
local WiFi-router <──────~> (eth0)RPi(ppp0) <───> modem <---> INTERNET
                             /           \
                       192.168.50.2      (dhcp
                                       from modem)

You should have both interfaces available each with its own ip address. The ip addresses should be on different subnets, for example eth0 with 192.168.50.2 and ppp0 with 10.1.1.180. Now you have to enable routing so that data packages are transmitted between the both interfaces. To enable this you have to turn on ip forwarding. There are several ways to do it. I don't know what configuration you are using. You can enable it direct to the kernel with:

rpi ~$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

Or you can uncomment this in /etc/sysctl.conf and reboot:

# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1

Or with systemd-networkd you can add IPForward=yes to the [Network] section in one of your /etc/systemd/network/*.network files.

Now you have to fake the modem to tell it that all data packages are comming from the RasPi and not from the underlaying local network. We do it with a NAT (Network Address Translation). Execute this command:

rpi ~$ sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

The last step now is to tell all clients on your local network that the internet router is the RasPi. You have to configure the DHCP server on the local WiFi router to give the ip address 192.168.50.2 to all clients as internet router ip address (default gateway). If this is a problem then you can disable the DHCP server on the local WiFi router and setup one on the RasPi.

  • Thank you very much! How do I give static ip address to eth0? – leller May 26 at 16:40
  • @leller It depends on what networking system do you use. Do you have already a preference? If you want to use default dhcpcd then have a look at /etc/dhcpcd.conf. If you prefer systemd-networkd then I can help you step by step and can give more details in the answer. With systemd-networkd you configure interfaces with files in /etc/systemd/network/. There you can set a static ip address. – Ingo May 26 at 20:17
  • I don't have any experience with any of these. I'd be really gratefull for step-by-step guide – leller May 26 at 20:27
  • @leller OK, let's try with systemd-networkd. But there is one uncertainty: how to start and stop the internet connection with the modem. That's difficult to assist remotely. Best you make a backup from your SD Card, so you can always revert. I will revise the answer to be more specific, but just a moment please. Please make a connection to the internet and execute these two commands on the RasPis command line: ip addr and ip route. Edit your question and copy and paste the output into the question. – Ingo May 26 at 20:53

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.