Learn how you can create a 4G hotspot using a Raspberry Pi and a wireless modem without sacrificing your Ethernet port!
I previously discussed several different methods for getting your Raspberry Pi online on-the-go. One of the methods I covered was to use a smartphone to create a hotspot that the Pi can connect to.
In this article, Iâll discuss how the Raspberry Pi can be set up to act as the hotspot so that other devices can use it to connect to a cellular or Ethernet network.
You can use your Raspberry Pi to create a 4G hotspot!
Choose a Network Adapter
Before you begin, decide which network adapter you want to make accessible via the Raspberry Piâs Wi-Fi adapter. In my case, thatâll be a 3G cellular modem connected via USB.
For me, it was important that the Raspberry Pi still be reachable via its standard Ethernet port even when it's acting as a hotspot. However, at the end of this article, Iâll also show you how you can share the Ethernet port over the Raspberry Piâs wireless adapter.
When you use a cellular adapter, make sure that itâs set up correctly and that itâs working.
Take Note of the Adapter Values
On your Raspberry Pi, execute the following command to list the available network interfaces:
Once you type in the command you should see something like this:
Your available network interfaces.
Take note of the name, address, and netmask of the networking adapter you want to use. In this example, that is eth0, 192.168.0.30, and 24 bits (255.255.255.0).
Keep in mind that this is only an example, and I used eth1 as described above.
Install the Necessary Software
Youâll need to install a couple of small applications for this to work. Before doing that make sure to run the update command:
Once thatâs finished, install the following programs:
sudo apt install hostapd bridge-utils
hostapd is a user space daemon for access point and authentication servers. The bridge-utils will make your life much easier when configuring the networking bridge.
The access point daemon automatically starts when it is installed. However, we need to configure it first. Therefore, you need to turn it off manually:
sudo systemctl stop hostapd
Build a Network Bridge
A networking bridge simply connects two or more virtual or real networking devices. In this project, I set up a single bridge that connects eth1 and wlan0 so that that internet connection of eth1 can be shared over the Piâs Wi-Fi adapter.
To make eth1 sharable, you first have to edit the DHCP daemonâs config file so that eth1 and wlan0 donât get an address assigned automatically:
sudo nano /etc/dhcpcd.conf
In the file, add the following two lines to the end of the file:
Next, you need to create a new bridge by typing:
Where br0 is the name of the new bridge. Next, you need to specify which adapters you want to bridge:
sudo brctl addif br0 eth1
In this case, itâs only one adapter on br0. The addif command will make eth1 a port of the bridge, which means that all frames received on eth1 will be treated as if they were destined for the bridge.
Configuring the Interfaces
Next, weâll have to define and configure the new bridge. Create a new file in:
and add the following lines to it:
Then create two new configuration files as follows:
In the second file, make sure to use the IP-Address that you wrote down earlier. I used the address of the eth1 interface.
Also, make sure to change the gateway to the correct address. You can use a public DNS server, like I did, or get the correct one from your ISP.
Once thatâs done, restart the daemon:
sudo systemctl restart systemd-networkd
Access Point Setup
Next, we have to configure the access point itself.
In this config file, you can change the SSID and the password of the network, that the Raspberry Pi will create. This file also states which adapter the bridge should use as the other end.
Create a new file:
sudo nano /etc/hostapd/hostapd.conf
And add the following lines to it:
Then restart the access point daemon:
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
Once thatâs done, you can use your phone to verify that you can establish a connection and browse the Internet.
Sharing an Ethernet Connection
In this example, I shared a 3G cellular connection via the Piâs Wi-Fi adapter. That effectively created a 3G wireless hotspot similar to the one you can create with any modern smartphone.
However, itâs also possible to share the Raspberry Piâs ethernet port over a wireless connection. For that, simply replace all instances of eth1 with eth0, which is the ethernet port on the Raspberry Pi. Make sure to also change the IP address and gateway accordingly!
If you are interested in more information regarding networks, take a look at the following web resources: