Raspberry Pi Zero Internet connection through USB
Posted on December 7, 2018 by Paul
This is a short article about sharing your Internet connection through USB with a Raspberry Pi Zero. The procedure presented here will work with all versions of Raspberry Pi Zero (with or without onboard WiFi). You will need a Raspberry Pi Zero, a micro SD card and a USB to micro USB data cable.
Start by downloading the latest Raspbian image, I’ve used Raspbian Stretch Lite. Once the download is finished, extract the archive and flash it to your micro SD card. The Etcher flasher app works on macOS, Windows and Linux.
After you’ve flashed the SD card you will need to edit two files on this. I strongly suggest to use a proper text editor, e.g. Sublime Text, VS Code, Notepad++, Vim, Emacs and so on. Reinsert the SD card if it was ejected after was flashed and open config.txt, add the next line to the end of the file:
save and close the file.
Open cmdline.txt, this file has all parameters on a single line, separated by a single space, make sure to not add extra line endings or more than one space. Find the rootwait parameter and add a new parameter after it:
please note that in the above there is no space. Save and close the file.
Create an empty file named ssh on the SD card.
Note, if you are on Windows, you will need to install Bonjour Print Services.
Next, connect Raspberry Pi Zero to your computer through the USB cable, make sure this is inserted in the USB data port of your Pi and not in the power port. Wait about a minute and open a Terminal or, if you are on Windows, a Command Prompt and write:
or, if you are on Windows:
This is what I see on my Mac:
This is the result of pinging the Pi Zero on a Windows machine:
At this point, you should be able to use ssh to connect to your Pi Zero:
the default password is raspberry.
Note, if you are on Windows 10 1803 or newer you should be able to use directly ssh in a Command Prompt. For older versions of Windows you can install PuTTY or other ssh client.
Next, I will show you how to share your computer Internet connection with the Pi Zero.
If you are on macOS, open System Preferences, go to Sharing and check RNDIS/Ethernet Gadget and Internet Sharing:
Answer Yes when asked if you want to start sharing the Internet.
If you are on Windows, go to Settings, Network & Internet and select Network and Sharing Center. Next, click on your main Internet connection:
and go to Properties, Sharing. Select Allow other network users to connect through this computer’s Internet connection and from the drop down menu select one of the Ethernet options:
in my case Pi Zero was connected to Ethernet 2. Press OK.
Next, on your Pi Zero, check if you can access the Internet, e.g.:
This is what I see on my device:
If you want to learn more about Raspberry Pi, a very good book is Exploring Raspberry Pi by Derek Molloy: