Configuring a Raspberry Pi Zero with USB Ethernet and OpenWRT
I needed a quick and dirty Wifi bridge and the Pi Zero W seemed perfect. However, it did not automatically configure the USB ethernet adapter I was using. Here’s how I got it working.
The aim here is to supply internet to the Pi via WiFi and have it supply internet to connected ethernet devices. Simple enough to implement with OpenWRT, but I only had a Pi Zero W on hand and it has no ethernet port and OpenWRT doesn’t automatically detect my USB ethernet adapter.
This caused problems because I needed to configure networking, but could not SSH to the Pi via the WiFi connection as I’d be changing the networking configuration and be booted out before finishing the configuration changes.
Everything could have been done on the command line with a connected keyboard/monitor, but connecting to a network using the LuCi web interface is much easier, hence the somewhat convoluted steps to allow for this.
The solution isn’t really complex, but it was annoying, so I figured it worth documenting.
I’ll keep it brief as none of this is re-inventing the wheel – there’s just a specific order that things need to be done in. The links for each step will provide details.
- Install OpenWRT on the Raspberry Pi Zero W
- (Temporarily) connect a keyboard, and monitor to the Pi
- Enable WiFi in OpenWRT via the command line
- Connect to the WiFi network broadcast by OpenWRT from another computer
- Open the LuCi web interfact to OpenWRT
- It’s much easier to configure WiFi from here, rather than on the command line
- Connect to your internet-connected WiFi network
- Replace any existing WiFi configuration
- This will kick you off of the default OpenWRT network
- Reboot OpenWRT
- OpenWRT is now connected to the internet via WiFi
- As it treats this as a WAN connection you will need to revert back to making changes on the command line via keyboard/monitor
- Install the driver for your USB ethernet adapter – this was not possible without the internet connection now being provided via WiFi
- Reboot OpenWRT
- The USB ethernet interface should now be eth0
ifconfigto list interfaces to confirm/if you are unsure
- Edit the network configuration by running
- We’re still doing all of this from the keyboard/mouse
- Replace the following lines in the file:
config interface 'lan' option device 'br-lan'
config interface 'lan' option device 'eth0'
- Reboot OpenWRT (again)
- Disconnect keyboard/monitor
- You can now access LuCI again on computers attached to the wired ethernet interface
- Pi Zero W/OpenWRT are now acting as a bridge, so you’ll be online on the wired side
- You can now continue updating your configuration through the web interface
- The network on the wired side will simply be getting it’s internet from your WiFi network and will have it’s own DHCP server, etc, provided by OpenWRT
- Recommended to restrict SSH/LuCi access to the ‘lan’ network only