Important: You are required to change your passwords used for Gentoo services and set an email address for your Wiki account if you haven't done so. See the full announcement and Wiki email policy change for more information.

Iphone USB Tethering

From Gentoo Wiki
Jump to: navigation, search

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

tested devices

  • iPhone 4S, iOS5

tools needed

app-pda/ipheth-pair found in dberkholz's overlay. You can set up the overlay with layman.

root # emerge --ask app-pda/ipheth-pair

ipheth interface

If ipheth-pair is installed successfully, plug in the iPhone with USE cable. You should see something like:

FiledmesgiPhone 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 172.20.10.2/28 brd 172.20.10.15 scope global eth1
    inet6 fe80::9c20:7bff:fe6b:94bd/64 scope link 
       valid_lft forever preferred_lft forever

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

IFACE=$1
ACTION=$2
...
SCRIPT=/etc/init.d/net.$IFACE
...
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"

LABEL="ipheth_rules_end"

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
rc_hotplug="net.eth1"

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