Skip to content

Instantly share code, notes, and snippets.

@brenr
Last active July 29, 2025 00:35
Show Gist options
  • Save brenr/d85592e4d2a66120d12e0ad63cc9b9a2 to your computer and use it in GitHub Desktop.
Save brenr/d85592e4d2a66120d12e0ad63cc9b9a2 to your computer and use it in GitHub Desktop.
OpenWRT Smartphone Tethering

OpenWRT Router Pre-configured for Smartphone Tethering

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).

Building the firmware

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.

  1. 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).

  2. Below the search box, expand the Customize section.

  3. 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
    
  4. 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
  5. Now click the Request Build button. Now go make some coffee (yes it's required otherwise it won't work).

  6. 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.

  7. After it's downloaded, go ahead and uncompress it. (Archive Utility on macOS, 7-Zip/Winrar on Windows, etc).

Writing the firmware

Option 1) Using a router with an OS already on it

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.

Option 2) Writing directly to an SD card

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.

Enable tethering on smartphone

  1. 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.

Recommendations

  • 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.

Credits

@rlan
Copy link

rlan commented Jul 16, 2025

@ZandoBob Thank you very much for sharing technical details. And doing so middle of the night!
I was just thinking about switching to Verizon's Visible. What a coincident.

I understand you live in the woods. I guess that means there are no good wired Internet carriers. Do you use this setup as a replacement for that? What is your experience on the connection stability in a typical week?

Do you use in a hybrid mode, i.e. carry out your phone and connect back to Pi when returning? If so, how is the reconnection experience to Pi and Verizon.

@ZandoBob
Copy link

@rlan Yep, I use it to run my home network. Stability is... pretty okay, I'd say it's up 80% or more of the time. Every now and then it'll goof up and I reboot the router and phone and then it behaves again. That iPhone SE I got off ebay for $140, it runs the hotspot nearly 24/7. I have removed it for troubleshooting or to take on a trip with me as a spare phone. When reconnecting it usually just works right away, since the script above saves the authentication .plist it doesn't even ask for the "trust this computer" confirmation. You can look up what ttl settings you need and where to input those in OpenWRT, I believe it's a TTL setting of 65. That'll make Verizon think the traffic is from the phone itself, not the hotspot, so it will run at full speed until you hit the data cap, where it drops to 5mbps (or 10mbps with the higher tier plan). Neither Verizon nor Visible have complained at me about the terabyte or so of data I use per month (looking at cell statistics, I'm at 910GB used since June 18th, so almost exactly a month ago).

@rlan
Copy link

rlan commented Jul 18, 2025

@ZandoBob Thank you for sharing your usage experience. When it goofs up, besides rebooting the router (Pi), do you need touch operate the phone? I'm curious about what can be and can not be automated.

@ZandoBob
Copy link

@rlan IDK honestly, I always have the phone unlocked when reconnecting so I can see if the hotspot is active, and I always cycle the hotspot off and on as a troubleshooting step, I haven't tried just rebooting the router alone.

@rlan
Copy link

rlan commented Jul 21, 2025

@ZandoBob Thanks again :)

@elanora96
Copy link

Fantastic guide, thank you. I just used opkg to install the pkgs listed (on a friend's network) and then ran the provided script.

Working great so far on Verizon with my iPhone 15 Pro (iOS 26 Beta 4) and Linksys EA6350v3 (OpenWrt 24.10.1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment