Share internet to the Raspberry Pi Zero

By Russell Barnes. Posted

Use one Raspberry Pi to share its internet with a Pi Zero through the GPIO ports, using Point-to-Point Protocol

Point-to-Point Protocol (PPP) is how everyone used to access the internet, back in the days of dial-up. You can use it with your Pi Zero to piggyback on the internet connection of another Pi which is already online. This saves the single micro-USB data connector to use with something else, if you don't want to hook up a USB hub and need to connect more than just a WiFi dongle.

You'll need...

  • A Raspberry Pi A, B, A+, B+ or 2
  • A Raspberry Pi Zero
  • 2× SD cards, both with a fresh install of Raspbian Jessie
  • 2× male-to-female jumper cables
  • A blob of Blu-Tack or plasticine

The full article can be found in The MagPi 41 and was written by Dave Honess

For the following steps, the host Raspberry Pi needs to have internet access. First, enable IPv4 forwarding by going into the terminal and using:

sudo nano /etc/sysctl.conf

Find the line net.ipv4.ip_forward=1 and remove the # symbol at the start of the line. Save and exit using CTRL+X and then pressing Y. Now run this command to reload the config:

sudo sysctl -p

Next install the ppp package:

sudo apt-get install ppp -y

The plan is to use the UART GPIO pins to link the host Pi to the Zero. We need to use physical GPIO pin numbers 8 and 10; these pins are otherwise known as TXD (transmit) and RXD (receive).

By default, there is a login prompt running on the UART, so we first need to disable it:

cd /boot
sudo cp cmdline.txt old_cmdline
sudo nano cmdline.txt

You should see this:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsc

Remove console=ttyAMA0,115200, then save and exit. For the speed of the data link to be acceptable, we need to speed up the UART internal clock:

sudo nano config.txt

Append inituartclock=16000000 to the
bottom of the file, then save and exit. Then we need to disable the login prompt service that runs
on the UART:

sudo systemctl disable serial-getty@ttyAMA0.service

Reboot the Pi. We now need to create an options file that will configure the PPP service when it starts:

sudo nano /etc/ppp/options.ttyAMA0

Copy the following lines into the file:

noauth
nocrtscts
xonxoff
passive
local
maxfail 0
nodetach
192.168.0.100:192.168.0.101
persist
proxyarp

Save and exit. The two IP addresses need to be available on your LAN, and should be different to the one allocated to the host Pi’s Ethernet adaptor. Next, create a config file that tells the PPP service to start automatically on boot:

cd /etc/systemd/system/
sudo nano rpippp.service

Copy the lines below into the file:

[Unit]
Description=PPP
[Service]
Type=idle
ExecStart=/usr/sbin/pppd -d /dev/ttyAMA0 1000000
Restart=always
[Install]
WantedBy=multi-user.target
Alias=ppp.service

Now run the following commands to enable the service:

sudo systemctl daemon-reload
sudo systemctl enable rpippp.service

Shut down the Raspberry Pi.

On the Zero

It's a good idea to change the host name on the Zero in order to avoid confusion when you’re SSHed into it:

sudo nano /etc/hostname

Change raspberrypi to zero, then:

sudo nano /etc/hosts

Do the same again: raspberrypi to zero. Save and exit. Next, install the ppp package:

sudo apt-get install ppp -y

As with the host Raspberry Pi, you’ll need to disable the login prompt in the same way as before. When you get to creating an options file, use this:

noauth
nocrtscts
xonxoff
passive
local
maxfail 0
defaultroute
persist
nodetach
192.168.0.101:192.168.0.100

Next, we need to preconfigure a DNS server, otherwise the Zero will not be able to perform DNS queries.

sudo nano /etc/resolvconf.conf

Find the line #nameservers=127.0.0.1 and insert the line nameservers=192.168.0.1 below it. Save and exit.

Now run the following commands to enable the service:

sudo systemctl daemon-reload
sudo systemctl enable rpippp.service

Shut down the Pi Zero.

Put it all together

Connect the UART ‘pins’ of the Pi Zero as shown in the main image on the opposite page. Use a blob of Blu-Tack or plasticine to wedge the male ends of the jumper cables so that they're in contact with the metal holes on the Zero; remember, it's physical GPIO pin numbers 8 and 10.

Boot up both the host Pi and the Zero. The following command can be used to monitor the status
of the PPP service:

sudo systemctl status rpippp.service

This will give you the log file of the PPP service.

The following line indicates that the connection has been established (the pid number for you will be different):

Script /etc/ppp/ip-up finished (pid ###), status = 0x0

If you have any issues or see error messages, you can restart the PPP service using this command:

sudo systemctl restart rpippp.service

You should now be able to SSH into the Zero using this command:

ssh pi@192.168.0.101

From The MagPi store

Subscribe

Subscribe to the newsletter

Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.