Setting up a Raspberry Pi as an LTE Hotspot

Let's say you have a Raspberry Pi 4G/LTE Cellular Modem Kit and an available cellular connection. If you need to create a second Wi-Fi network in addition to your primary LTE network, the easiest solution is to create a called hotspot, an access point where the other devices you can control can connect to access the internet.

Let’s start with setting up the LTE hotspot.

πŸ“– Note

This method applies to Raspberry Pi OS versions prior to Debian Bookworm. For the latest Raspberry Pi OS, it's recommended to use nmcli. Raspberry Pi official hotspot documentations

Hardware

All the hardware needed to create our LTE hotspot is already included in the Raspberry Pi 4G/LTE Cellular Modem Kit. To set up the hardware please follow: Raspberry Pi 4G/LTE Cellular Modem Kit > Getting Started > Hardware Setup.

Preparation

Update / Upgrade Raspberry Pi OS packages.

sudo apt update && sudo apt upgrade -y

Reboot the system.

sudo reboot

Install requirements.

sudo apt install hostapd dnsmasq -y

Stop services to configure them.

sudo systemctl stop hostapd dnsmasq

Cellular Internet

Set up cellular internet connection. Please follow the instructions below to establish the cellular internet connection using ECM mode.

Configuration

❗️ Attention

Please note the cellular interface name. In this tutorial, the cellular interface is usb0. If your cellular interface is different, change all usb0 interface names.

Configure a static IP for the wlan0 interface.

sudo nano /etc/dhcpcd.conf

Add the following lines at the end open file.

interface wlan0 static ip_address=192.168.0.10/24 denyinterfaces wlan0 usb0

Configure the DHCP server (dnsmasq). Save the old configuration file and start configuring the clean configuration file.

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf

Add these lines to file and save.

interface=wlan0 dhcp-range=192.168.0.11,192.168.0.30,255.255.255.0,24h

Configure Access Point

We can now configure the access point details. We will set up a password-protected network so that only people with the password can connect.

Create a new file with the following command

sudo nano /etc/hostapd/hostapd.conf

Add these lines to the file and save. Change "NETWORK" and "PASSWORD" with yours.
Make sure each line has no extra spaces or tabs at the end or beginning.

interface=wlan0 bridge=br0 hw_mode=g channel=7 wmm_enabled=0 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP ssid=NETWORK wpa_passphrase=PASSWORD

Now we will tell the Pi where to find this configuration file.

sudo nano /etc/default/hostapd

Find #DAEMON_CONF="" line and change as below. Then save.

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Forward internet connection by using bridge. First, install bridge-utils.

sudo apt-get install bridge-utils -y

Create bridge and forward.

sudo brctl addbr br0
sudo brctl addif br0 usb0

Configure bridge.

sudo nano /etc/network/interfaces

Add following line at the end of the file and save.

auto br0 iface br0 inet manual bridge_ports usb0 wlan0

Check the hostapd service is masked. If service is masked, unmask the service.

sudo systemctl unmask hostapd
sudo systemctl enable hostapd

and then reboot.

sudo reboot

Finishing up!

Restart the Raspberry Pi and everything should now work as it should!