Raspberry Pi 4 USB Networking

Just having installed the latest and greatest version of Ubuntu for Raspberry Pi I realised that most likely my access to the shell from my iPad wouldn't work anymore. The setup I had put together previously and worked fine on Raspberry OS just didn't work anymore. Let me preface this by saying that I don't just install things by hand; I use Ansible wherever possible to ensure repeatability and reduce errors usually caused by manual setups. Suffice to say the Ansible setup ran successfully but didn't have the desired effect on the new OS... duh!

The Backstory

Sometimes I like just taking my iPad pro with me, no heavy MacBook or any other bulky paraphernalia for that matter. But I also like to be able to know that if push comes to shove I can still do some work without having to ssh into some system via the interwebs. Hence the somewhat odd sidekick to my iPad Pro: a Raspberry Pi 4 with 8gb of memory and a 512gb SD card... Why? you ask. Well why not if it is possible?!

The Setup

The installation is relatively easy. Just follow the official instructions until you have a fully working Ubuntu running on your Raspberry Pi 4.

The following steps need to be executed on your SD card and the system-boot directory. This can be done by taking the SD card out of the Pi, inserting it into a card reader connected to your computer. You should see a drive show up named system-boot.

Edit the system-boot/comandline.txt, mine looks like this:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=LABEL=writable rootfstype=ext4 elevator=deadline rootwait modules-load=dwc2,g_ether g_ether.host_addr=<your-host-mac-addr> g_ether.dev_addr=<your-dev-mac-addr> fixrtc quiet splash

Then the following line needs to be added to system-boot/config.txt: dtoverlay=dwc2

Also update your system-boot/network-setup and add the following to the ethernet section:

usb0:
    dhcp4: false
    addresses:
      - 10.55.0.1/29
    optional: true

This is all you need to do on your SD card for now. Eject the SD and put it back into your Raspberry Pi. Boot up and access it the way you did previously. You're going to need to install dnsmasq and put the following configuration in place for it to be able to assign an IP address to anything connected via USB.

interface=usb0
dhcp-range=10.55.0.2,10.55.0.6,255.255.255.248,1h
dhcp-option=3
leasefile-ro

Ready

If all of the above checks out you should be able to connect the PI to your iPad via USB and log in via ssh using an app like blink.

ssh ubuntu@10.55.0.1 and you should be good to go...