Updated PiZero USB Networking Guide
As usual, I just want to make it as easy as possible to get USB networking on the PiZero and here is my latest guide.
Requirements a B/B+/2B Pi connected to the internet
- First, flash Jessie (full, not lite) onto a blank microSD card and put it into an internet connected Pi.
- Switch on the Pi.
- Boot it up and resize the root partition (open a terminal and enter
sudo raspi-config, then select expand and reboot).
- Once it starts up again, run
sudo BRANCH=next rpi-update. This will take a while.
- Next we need to make sure we are using the dwc2 USB driver by entering
sudo nano /boot/config.txtand then adding dtoverlay=dwc to the end of the file and then save it (Ctrl-X then Y then Enter)
sudo nano /etc/modulesand add dwc2 to the end of that file and the on next line add g_ether and then save it (Ctrl-X then Y then Enter)
Setting IP address
We need to create a special file that adds some extra IP aliases to make sure it will work under a lot of different conditions -so:
sudo nano /etc/dhcpcd.exit-hook
(this file probably doesn;t exist so it will be empty
# This script adds the desired static ip address as an alias aliasip= # USB alias case "$interface" in usb0) aliasip="169.254.64.64/16";; esac if [ -n "$aliasip" ]; then echo "Adding alias of $aliasip to $interface" >> /home/pi/hook.txt ip addr add "192.168.137.2" dev "$interface" ip addr add "$aliasip" dev "$interface" fi
and then run
sudo shutdown now
to switch your pi off
This card can now be placed into a PiZero
(Note for advanced geeks – the above code gets run about 6 times each boot and could do with a bit more TLC to make it less of a bodge 🙂
Getting Networking running between PiZero and Windows machine (see further down for Linux and Mac)
- Plug USB cable between PiZero (middle socket and PC) – the green light on the PiZero should flash once after about a second – your PC should beep like it does when you stick a device into a USB port.
Now, if you’ve not done anything like this before then a bit of configuring is needed on your Windows machine.
- It will try and install a USB networking driver and may appear to succeed but best bet is to go into control panel -system -device manager and see if little yellow mark against USB ethernet in Network Adaptors. If so simply follow these instructions up to the setting ip address part https://github.com/ev3dev/ev3dev/wiki/Setting-Up-Windows-USB-Ethernet-Networking
- Then unplug/plug USB and then get into Network Adaptors and click on Change Adaptor Settings.
- If you’ve got an unidentified USB Ethernet network adaptor then you are good to go. If it says “identifying” then just wait till it comes ready – can take a few minutes the first time.
Actually connecting To PiZero over USB
This is where you use Putty to connect to a terminal window on the PiZero
- Run Putty
- Enter 169.254.64.64 as IP address and press Open
- Answer yes to dialog box and then you should see PiZero login
Using Internet Connection Sharing
If you want internet access on the Pi, you’ll need to change your main network adaptor properties and enable it to share with your USB connection – this is what it looks like on my Win10 machine
When you plug your Pi in now, instead of it getting an IP address on 169.254.64.64 – you can access it using ip address 192.168.137.2
Simply add these lines to the bottom of your /etc/network/interfaces file
allow-hotplug usb0 auto usb0 iface usb0 inet static address 169.254.1.1 netmask 255.255.0.0
and reboot (or restart your network daemon)
Not done yet
Don’t have one – need someone to do this bit please 🙂