In this guide, I'll be using:
- iPhone 12 Pro on iOS 15.1.1 as my tethering device
- Raspberry Pi 4 with OpenWRT version 21.02.1
- 64GB Sandisk micro SD card
The goal with this guide is to create a pre-configured OpenWRT router that:
- Is plug and play to provide out-of-the-box smartphone tethering
- Supports both iPhone and Android (comment below if you are having any issues).
Trust me, this is extremely simple. Since the goal is zero configuration, we'll build the OpenWRT image to be flashed onto either the router, or SD card for the Raspberry Pi 4 in my case.
-
Go to the image builder tool and search for the model of your router. In my case, I'll choose Raspberry Pi 4B/400/4CM (64bit).
-
Below the search box, expand the Customize section.
-
In the Custom package selection text box, you'll see a space-separated list of packages that is required by default for your OpenWRT router to work. Add a space at the end then add the following:
kmod-usb-net-rndis kmod-nls-base kmod-usb-core kmod-usb-net kmod-usb-net-cdc-ether opkg kmod-usb2 kmod-usb3 kmod-usb-storage kmod-usb-storage-uas usbutils kmod-usb-net-ipheth usbmuxd libimobiledevice usbutils hub-ctrl rsync xxd vim iptables-mod-ipopt kmod-ipt-ipopt
-
In the next section, Custom script to run on first boot (optional), paste the following. Note: you may need to replace eth1 with usb0 in this script, depending on your router - in my case, it's eth1.
# Patch ipheth for iOS 14+ cd /lib/modules/$(uname -r) cp -ia ipheth.ko ipheth.ko.orig xxd ipheth.ko.orig | sed 's/05EC/05EA/g' | xxd -r > ipheth.ko rmmod ipheth; modprobe ipheth # Call usbmuxd usbmuxd -v # Add usbmuxd to autostart sed -i -e "\$i usbmuxd" /etc/rc.local # Enable tethering uci add_list dhcp.wan.ra_flags='none' uci set network.wan=interface uci set network.wan.proto='dhcp' uci set network.wan.device='eth1' uci set network.wan.ttl='65' uci commit network /etc/init.d/network restart # Save connectivity checking script cat << "EOF" > /root/wan-watchdog.sh #!/bin/sh # Fetch WAN gateway . /lib/functions/network.sh network_flush_cache network_find_wan NET_IF network_get_gateway NET_GW "${NET_IF}" # Check WAN connectivity TRIES="0" while [ "${TRIES}" -lt 5 ] do if ping -c 1 -w 3 "${NET_GW}" &> /dev/null then exit 0 else let TRIES++ fi done # Restart network /etc/init.d/network stop hub-ctrl -h 0 -P 1 -p 0 sleep 1 hub-ctrl -h 0 -P 1 -p 1 /etc/init.d/network start EOF chmod +x /root/wan-watchdog.sh # Add cron job cat << "EOF" >> /etc/crontabs/root * * * * * /root/wan-watchdog.sh EOF # Save watchdog script mkdir -p /etc/lockdown cat << "EOF" > /etc/lockdown/watchdog.sh #!/bin/sh # A small script to make life with iPhone tethering less cumbersome on OpenWrt # Petr Vyskocil, Apr 2020 # Public domain # After you successfully allow iPhone tethering, copy files with name like # /var/lib/lockdown/12345678-9ABCDEF012345678.plist to /etc/lockdown/locks. # That way, you won't have to set up trust again after router reboots. if [ -e /etc/lockdown/locks ] then mkdir -p /var/lib/lockdown cp -f /etc/lockdown/locks/* /var/lib/lockdown/ fi # lockdown records restored, now we can launch usbmuxd. Don't launch it sooner! usbmuxd # We are up and running now. But unfortunately if your carrier signal is weak, iPhone will # drop connection from time to time and you'd have to unplug and replug USB cable to start tethering # again. Script below automates that activity. # First wait a bit - we just brought the interface up by usbmuxd sleep 20 # If we see iPhone ethernet interface, try to ping iPhone router's address (172.20.10.1). # When the ping is unsuccessful, rebind iPhone ethernet USB driver and wait for things to settle down while : do for i in /sys/bus/usb/drivers/ipheth/*:* do test -e "${i}" || continue ping -w 3 172.20.10.1 &> /dev/null if [ "${?}" -ne 0 ]; then echo "${i##*/}" > "${i%/*}"/unbind echo "${i##*/}" > "${i%/*}"/bind sleep 20 fi done sleep 1 done EOF chmod +x /etc/lockdown/watchdog.sh # Add watchdog script to autostart sed -i -e "\$i (/etc/lockdown/watchdog.sh) &" /etc/rc.local
-
Now click the Request Build button. Now go make some coffee (yes it's required otherwise it won't work).
-
Once finished, you should see four possible image downloads at the bottom. If you have a router that's currently running and you want to flash over it, you'll want the sysupgrade (ext4) however in my case, it'll be a factory flash, so of course I'll download the factory (ext4) image.
-
After it's downloaded, go ahead and uncompress it. (Archive Utility on macOS, 7-Zip/Winrar on Windows, etc).
Find the setting to upgrade the firmware and in the file chooser, choose the .img file you just uncompressed. Upgrade the firmware and sit back.
Use Balena Etcher (on macOS) to write the .img file to the SD card or if you're on Windows, you can use something like Rufus. Once finished, slot the micro SD card into the Raspberry Pi 4 and boot it up.
- Plug your smartphone into the USB port of the router or Raspberry Pi and enable tethering. On an iPhone, you'll be prompted to Trust the first time.
- Set a strong password on the router's web interface
- Disable SSH via the OpenWRT web interface if you have no need for it
- Set a strong password for the root user. Preferably authenticate with keypair.