Iphone USB Tethering

From Gentoo Wiki
Jump to:navigation Jump to:search

This page is inspired by Android USB Tethering, and only documents the differences.

tested devices

  • iPhone 4S, iOS5
  • iPhone 5, iOS6
  • iPhone 5S, iOS9


KERNEL Linux 4.4
Device Drivers 
  -> Network device support (NETDEVICES)
    -> USB Network Adapters (USB_NET_DRIVERS)
         <*>  Apple iPhone USB Ethernet driver (USB_IPHETH)

tools needed

You will also need app-pda/usbmuxd and app-pda/ifuse from the default portage tree.

root #emerge --ask app-pda/usbmuxd app-pda/ifuse

ipheth interface

If everything is installed successfully, plug in the iPhone with USB cable. You should see something like:

CODE dmesg: iPhone ipheth
[    2.080017] usb 8-1: new high-speed USB device number 2 using ehci_hcd
[    2.215940] usb 8-1: New USB device found, idVendor=05ac, idProduct=12a0
[    2.215946] usb 8-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    2.215950] usb 8-1: Product: iPhone
[    2.215953] usb 8-1: Manufacturer: Apple Inc.
[    2.215956] usb 8-1: SerialNumber: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[   26.988569] ipheth 8-1:4.2: Apple iPhone USB Ethernet device attached
[   26.988939] usbcore: registered new interface driver ipheth

A new network interface eth1 plugged by ipheth can be found, after running dhcp on it:

root #ip a show eth1
4: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 9e:20:7b:6b:94:bd brd ff:ff:ff:ff:ff:ff
    inet brd scope global eth1
    inet6 fe80::9c20:7bff:fe6b:94bd/64 scope link 
       valid_lft forever preferred_lft forever

If you don't see the output on dmesg, try mounting your iphone via ifuse:

root #ifuse /mnt/

You need to unlock your device while ifuse is mounting and you need to allow the incoming connection on your phone. Ifuse will guide you through this process, just follow its instructions and try mounting until it succeeds.

udev trigger

The hotplug feature of OpenRC can be used to set up the ipheth interface automatically.

sys-fs/udev-init-scripts ships /lib/udev/net.sh, which can be used to hotplug network interfaces. The main part of the script is

FILE /lib/udev/net.shnet interface hotplug
IN_HOTPLUG=1 "${SCRIPT}" --quiet "${ACTION}"

and it can be called with a udev rule:

FILE /lib/udev/rules.d/90-iphone-tether.rulesnet.sh trigger
# udev rules for setting correct configuration and pairing on tethered iPhones
ATTR{idVendor}!="05ac", GOTO="ipheth_rules_end"

# Execute pairing program when appropriate
ACTION=="add", SUBSYSTEM=="net", ENV{ID_USB_DRIVER}=="ipheth", SYMLINK+="iphone", RUN+="ipheth-pair", RUN+="net.sh eth1 start"
SUBSYSTEM=="net", ACTION=="remove", ENV{ID_USB_DRIVER}=="ipheth", SYMLINK+="iphone", RUN+="net.sh %k stop"


Enable hotplug to eth1, the ipheth device:

FILE /etc/rc.confrc_hotplug
# rc_hotplug is a list of services that we allow to be hotplugged.
# By default we do not allow hotplugging.
# A hotplugged service is one started by a dynamic dev manager when a matching
# hardware device is found.
# This service is intrinsically included in the boot runlevel.
# To disable services, prefix with a !
# Example - rc_hotplug="net.wlan !net.*"
# This allows net.wlan and any service not matching net.* to be plugged.
# Example - rc_hotplug="*"
# This allows all services to be hotplugged

add net.eth1:

root #ln -s /etc/init.d/net.{lo,eth1}

After plugging in the iPhone, we can see the service started:

root #rc-status
Dynamic Runlevel: hotplugged
 net.eth1                        [  started  ]