Ethernet Gadget

The Ethernet Gadget is a little more difficult to set up, but is a lot more powerful because you can tunnel networking, VNC, ssh and scp files, etc. Basically you get the ability to log in to the console as well as anything else you could want to do over a network connection

Note that even though it's called "Ethernet Gadget" you do not use an Ethernet cable! The only cable is the USB micro-B cable from your computer to your Pi Zero. The Pi 'appears' like an Ethernet device.

You can even share your desktop computer's network setup so your Pi can access the internet through your computer via the USB cable! Cool huh?

Thx for the tips from Andrew, as of May 2016, Raspbian Jessie does not require a new kernel & has raspberrypi.local setup by default so it's a lot easier

Step 0. Download and install latest Jessie

We're using Jessie Lite but plain Jessie Raspbian should work too! We're using Jessie Lite but plain Jessie Raspbian should work too! You need May 2016 or later (tested with 2016-05-27)

This tutorial has the details

Step 1. Edit config.txt & cmdline.txt

After burning the SD card, do not eject it from your computer! Use a text editor to open up the config.txt file that is in the SD card post-burn.

Go to the bottom and add dtoverlay=dwc2as the last line:

Save the config.txt file as plain text and then open up cmdline.txt After rootwait (the last word on the first line) add a space and then modules-load=dwc2,g_ether

Boot Your Pi with USB

Plug in a MicroUSB cable from your Pi Zero's USB port to your computer.

If you have a console cable you can watch the Zero's console to see it enable the g_ether device:

You can also SSH in to raspberrypi.local - If you are using a Mac or Linux chances are you have Bonjour already installed. On Windows, you may need to add Bonjour support so it knows what to do with .local names

Advanced Networking (Fixed IP)

If you need to manage fixed IP addresses for some reason - here's some useful techniques for managing your Pi's Gadget Ethernet device. Otherwise, you can always just keep using raspberrypi.local

You can now log in and check that you have a new network device called usb0

  • sudo ifconfig -a

Try plugging the Pi Zero into your computer now. For example, on a Mac, we plugged it in

As you can see above, between the first ifconfig and second, the network came up with an address. The problem this is a arbitrary (DHCP) address, and we dont want to have to guess it.

We can configure this device to have a fixed address (this makes it easier to find on a network!)

  •  sudo nano /etc/network/interfaces

and add at the end

allow-hotplug usb0
iface usb0 inet static
        address 192.168.7.2
        netmask 255.255.255.0
        network 192.168.7.0
        broadcast 192.168.7.255
        gateway 192.168.7.1

This will give the Raspberry Pi the IP Address 192.168.7.2

you can change this to a different address but unless you're sure that 192.168.7.* is unavailable, keep it as above for now.

Save the file and run

  • sudo ifdown usb0 (this may fail, its fine)
  • sudo ifup usb0
  • ifconfig usb0

to verify it now has the 192.168.7.2 address

Now on your computer you'll need to set it up as well.

If you are using a Mac as the Host Computer

On a Mac OS X machine, open up the System Preferences -> Network box.

You'll see the device show up as an RNDIS/Ethernet Gadget. it'll probably be set up for DHCP by default so change it to Configure IP4 Manually

  • For the IP address pick 192.168.7.1 (note that this is not the same as the Pi Zero's address!)
  • For the subnet mask, use 255.255.255.0  (same as Pi)
  • For the router/gateway use 192.168.7.1 (same as Pi)

If you didnt use our suggested netconfig above on the Pi, you may have to adjust this one to match

Click Apply when done, and wait a minute or so.

You can use a terminal on the computer to check the IP address was set, your device will be called enX where X is some number, use ifconfig -a to see a list of all devices, chances are the Pi is the last one.

Once you can see that the IP address is set, try pinging the pi with

  • ping 192.168.7.2

To be honest, I rebooted the Pi after setting up the network config file, so if it doesnt work at first, try that.

Next up you can ssh into your pi from your Mac!

  • ssh [email protected]

If you are using Windows as the Host Machine

Plug in the Pi Zero into your computer, I'm using Windows 7 64-bit. It will automatically download and install the RNDIS Ethernet drivers

Check the Device Manager to check that it is a new network adapter

Open up Network and Sharing Center and click on Change Adapter Settings 

You'll see a list of all the myriad adapters you have. I have a lot but you'll likely only have 2 or 3. Find the RNDIS adapter and rename it pizero (makes it easier to find)

Then right-click and select Properties...

And select the Internet Protocol Version 4 (TCP/IPv4) from the connection list and click Properties

Enter in 192.168.7.1 as the computer's IP address and gateway (the gateway got erased later, I think Windows just automatically uses the IP address if they're the same) the subnet mask is 255.255.255.0 same as the Pi's

There's no DNS address

I unplugged & replugged in the Pi Zero, Windows will then identify the network.

Now you can use a command box to run ipconfig /all if you want to check out the stats on the connection

and ping 192.168.7.2 (the pi)

and even ssh!

Last updated on 2016-08-21 at 11.47.37 PM Published on 2015-12-24 at 05.29.22 PM