Creating a 3G hotspot with the Raspberry Pi

IP Addresses

As part of the setup, you should also add a few lines to the Dnsmasq configuration file (Listing 7). Line 1, interface, makes sure the service only gives an IP address to devices in the local network. In line 2, Dnsmasq resolves names for its own /etc/hosts file, something that is very practical when devices found in the local network want access to one another. You should also designate static IP addresses for these local devices.

Listing 7



The dhcp-range defines the address range from which the DHCP server assigns IP addresses. In this example, the server used IPs between and, where the allocation remains constant for a period of 12 hours. IPs below are therefore suitable for computers that should receive a static IP address. The last item to take care of is to call

sudo update-rc.d -f dhcpcd remove

which is the DHCP client that comes activated with Raspbian.

Additional Points

The UMTS stick connected to the Rasp Pi should now be ready to dial-in to the mobile phone network. The local network should also be functioning. IP addresses are assigned to devices that are either logged in via WiFi or connected to the Rasp Pi Ethernet port. Devices can now reach the Internet, which means the technical work is finished; however, one small point must still be considered: Operating a Rasp Pi router is not exactly easy, because users must log in via the terminal for each action. Therefore, using a smartphone instead of a PC, which itself can be cumbersome under these circumstances, can be difficult.

Because of these difficulties, I installed lighttpd, a small HTTP server, and PHP with its associated software (Listing 1). Before you can use the server to control the system, you need to activate PHP and integrate a few useful standard pages by calling the first two commands in Listing 8 once. Next, you create a symbolic link in the webserver path to the phpsysinfo command [11] in line 3. This makes it possible to call status information via the browser.

Listing 8

Setting Up Browser Access

$ sudo lighttpd-enable-mod fastcgi-php
$ sudo service lighttpd force-reload
$ sudo ln -s /usr/share/phpsysinfo /var/www/sysinfo

If you now open the URL from the local network, the system will output a status page of technical information (Figure 3). To speed up the load time for this page significantly, make a small modification to the config.php file in the phpsysinfo directory /var/www/sysinfo. All you need to do is to set the value for PSI_JS_COMPRESSION to false, without quotation marks, and the page will load in a flash.

Figure 3: phpSysInfo provides a great deal of information about the current status of the Rasp Pi router in the form of an easy-to-understand web page.

The Debian package sources still have no web front end for vnStat data transfer statistics, so you need to download one from the project website [12] as a tarball and unzip the contents under /var/www. Using the commands from Listing 9, you should download the version of the web front end that is current as of September 2015, then unpack the archive under a suitable name and assign the necessary rights.

Listing 9

Setting Up vnStat Web Front End

$ wget
$ sudo tar xf vnstat_php_frontend-1.5.1.tar.gz -C /var/www
$ sudo mv /var/www/vnstat_php_frontend-1.5.1 /var/www/net
$ sudo chown -R www-data:www-data /var/www/net

You can now get the throughput information that comes from vnStat with a quick glance at (Figure 4). If necessary, you can adapt the web page in the /var/www/net/config.php file.

Figure 4: vnStat logs the volume of data that has been transmitted. The web front end provides the appropriate dashboards.

For more control options for the router, you can look at the web front end of the Raspberry Pi 3G Hotspot project that I'm still developing (Figure 5) on the GitHub pages for the project [13]. This simple interface lets you see the status of the connection and makes it possible to establish and terminate a connection. Additionally, you can shut down and restart a system. The homepage also contains links to the status information of phpSysInfo and the statistics for vnStat.

Figure 5: This web front end still under development controls the Raspberry Pi when it is used as a 3G hotspot.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content