How to Tether Your Raspberry Pi with your iPhone 5

If you have been reading my blog lately you know that I have done a lot of projects involving Raspberry Pi‘s, the $35 dollar credit card sized Linux computer. Because of its small size, I recently started of thinking of projects that would allow me to be mobile with the Pi.

That led me to this post.

There are plenty of resources online about tethering the iPhone 5 with the graphical interface, but I wanted to be able ‘hotswap’ my Raspberry Pi’s Internet connection without command line, and without the graphical interface.  Plug and play, essentially.

I was able to get this working last night using Raspian (a free operating system based on Debian optimized for the Raspberry Pi hardware) and a few scripts.

Prerequisites

Make sure your iPhone is disconnected and proceed to install the following iPhone and file system utilities. Open up a terminal or SSH into your Pi and run the following commands:

sudo apt-get install gvfs ipheth-utils
sudo apt-get install libimobiledevice-utils gvfs-backends gvfs-bin gvfs-fuse

After these are installed, and with your iPhone still not plugged in, lets take a look at our available interfaces. Run the following commands:

ifconfig -s

If you have a standard installation, you should see two interfaces, eth0 and lo.

tether iphone 5 raspberry pi

The reason we did this step was to make sure we correctly identified the name of the iPhone’s network interface. Now that you have this list you can turn on your iPhone’s Personal Hotspot and then plug it into your Raspberry Pi’s USB port, and issue the same command.

ifconfig -s

iphone raspberry pi

Your Pi should now recognize your iPhone is plugged in and assign its network interface a name, usually eth1. Now we need to edit our interfaces file to allow for hotswapping and dchp.

Unplug your iPhone and then open up your network interfaces file

sudo nano /etc/network/interfaces

and add the following lines, where eth1 is the name identified above.

allow-hotplug eth1
iface eth1 inet dhcp

Save and close the interfaces file.

Graphical Interface

If you are using the graphical interface, you are now done and the above commands were all that were necessary to use your iPhone as an Internet connection!

You can test this by starting your desktop environment

startx

Then unplug your Ethernet connection, start your Personal Hotspot, and plug in your iPhone. A popup message saying a “Removable medium is inserted” , that is safe to close. Then open a terminal, and run the following command:

ping google.com

You should be connected to the Internet!

Command Line

In my testing, tethering with command line only will only work when the iPhone is mounted. To do this, we need the ifuse package:

sudo aptitude install ifuse

and create a mount directory for the iPhone

sudo mkdir /media/iPhone

Now we can disconnect the ethernet of the Pi, turn on the iPhone’s Hotspot , and plug in then mount the iPhone.

sudo ifuse /media/iPhone

The Internet should now be tethered from your iPhone. Remember, while using command prompt only, the iPhone must manually be mounted each time it is plugged in using the ifuse command.

Putting It All Together

Now that we know how to tether the phone in the graphical interface, and the command line interface, we can add a script(thanks to users djpod and benebeck on the raspberrypi.org forums) that will automatically mount the iPhone it is plugged in.

To automate the process, I put the following script named iphoneconnect in /lib/udev/:

sudo nano /lib/udev/iphoneconnect

#!/bin/bash
umount /media/iPhone #when the iPhone is unplugged, it is not automatically unmounted.
ifuse /media/iPhone
ipheth_pair

Remember to make the script executable

sudo chmod 755 /lib/udev/iphoneconnect

The final step is to edit the file ’90-iphone-tether.rules’ in the ‘/lib/udev/rules.d’ directory.

sudo nano /lib/udev/rules.d/90-iphone-tether.rules

This is the script that runs automatically when ever we plug in the iPhone, and we want to edit it to call the script we created (/lib/udev/iphoneconnect) instead of what it currently calls (/lib/udev/ipheth_pair). To do this, we just edit the 5th line of the file replacing ipheth_pair with iphoneconnect.

The file should look like this


# 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+="iphoneconnect"

LABEL="ipheth_rules_end"

Thats it! Your Raspberry Pi will now automatically Tether your iPhone without Graphical Interface and without Command line!

 

 

 

iPhone Tethered Raspberry Pi

 

My command line speed tests averaged at about 1.5mb/s  download over Verizon LTE neat Boston, MA.

wget --output-document=/dev/null http://speedtest.wdc01.softlayer.com/downloads/test500.zip

26 comments

  1. Scott Barbour

    Hey Dave,

    Your post here is very timely! I’d really appreciate it if you could shoot me a quick email. I’d like to get your opinion on a project I have in mind related to tethering with RBP. Thanks in advance.

  2. Hello Dave,
    Brilliant post! I have a question however, there are Bluetooth 3.0 High Speed & Wi-Fi Combo USB Mini adapters. Could you do the above (with any smartphone) wirelessly? I am building up the courage to buy my RasPi. I say courage because I would like to be able to use it anywhere I go, so an internet connection is essential.
    Your thoughts?
    J.

    • dconroy

      Given the number of ways I’ve found to be able to get these online, I don’t think it’ll be a problem.

      Ive gotten them to work with wifi, bluetooth, ethernet, as an access point, with or without dhcp, 3g, and am very close to get 4g working.

      Good luck and shoot me an email if you have any questions getting started.

      • Hello, I am now worked on a project using pi to receive data from the gpio, I would like to know how can I connect the pi with iPhone via wifi so the data can stream out to the server or else.

        Thanks for your tuto… just found it works on my iPhone 5s.

  3. Does this have to be an iPhone 5 or will other models work too ?

    • dconroy

      I believe its any iPhone with Personal Hotspot capabilities.

    • OK I answered my own question by being patient and waiting to try it tonight…tethered perfectly good job!

      Next question – how do I find the IP to SSH/VNC into it? I have a script that auto runs on bootup to email me with the IP but it didn’t run when hooked upto the iPhone, I am guessing it doesn’t get the IP quickly enough todo it. Have no idea how tethering works, never needed todo it on my laptop so all info appreciated!

      Thanks

      Andy

      • Nathan

        You should be able to call your script from the iphoneconnect script above.

  4. Looks like a great project. Would I there after be able to to Rasbmc using the tethering or would I need to do something else?

    • dconroy

      I haven’t tested it but I dont see why you couldnt using Rasbmc with this type of tethering.

      Dave

  5. Is there a way to do this with a iPod?

    • dconroy

      Don’t think so, unless it has a wifi connection? Then perhaps

      • It is connected to wifi, do you think it will be worth the time to try it?

        • It doesn’t work, I just tried

          • dconroy

            Oh ok, Cody – thanks for giving it a shot! How far along did it get?

          • The pi wouldn’t recognize it like it did with the iPhone, and Unfortunately the iPod will not give off its own wifi signal even if it is connected to wifi :/

  6. Did iOS 7 break this? I have an iPhone 5 with iOS 7.0.2 and when i connect the iPhone to the Pi i get “Do you want to trust this computer with your data?” on my phone and a popup with “the device ‘Trevor’s iPhone’ is locked. Enter the passcode on the device and try again. When i hit Trust on the iPhone the popups come right back. Please help! Thanks for the work on the guide.

    • I’m in the exact same boat.. not only did iOS 7 prevent the above operation, it took away wifi completely on my iPhone 4S.
      Dave Conroy, if your somewhere out there with iOS 7… please do your magic.

      • I’m getting the Trust issue too, IOS7 here.

        Is there a workaround?

        Thanks!

      • Yes please Dave, same problem here. I checked out there is an updated libimobiledevice-utils which solves the problem but it doesn’t appear to be compiled for Pi yet. If I manage to figure out how to compile i’ll post back.

        • Yep same boat. IOS7 does not work. Please fix it if you can.

          • I added the raspberry jessie repo and installed 1.1.5-2 version of libimobiledevice-utils but still run in the same issues with IOS 7.0. Anyone successful yet???

          • Same here – stock and now jailbroken (evasion) on 7.0.4, and no dice. Tried MyWi as well as PDANet, and still getting pop-up.

    • I have the same problem of trust popup with IOS 7.0.4 Any help you can offer will be highly appreciated.
      Glen

Trackbacks/Pingbacks

  1. Ditch Your Cable Modem/ISP With a Tethered iPhone and Raspberry Pi | DaveConroy.com - [...] month, I wrote a blog post about tethering your iPhone to your Raspberry Pi. I got a lot of …
  2. Tether Your Raspberry Pi to Your Smartphone | The Cannabis Strain Directory Blog - [...] How to Tether Your Raspberry Pi with Your iPhone 5 | Dave Conroy [...]
  3. bring-your-Own WiFi « Daan Olieroock - [...] plane ride home. A Pi can act as WiFi amplifier, virtual private network, portable media center or tethered to …
  4. Tether Your Raspberry Pi To Your Smartphone | Lifehacker Australia - [...] How to Tether Your Raspberry Pi with Your iPhone 5 [Dave Conroy] [...]
  5. Tether Your Raspberry Pi to Your Smartphone « Music RSS - [...] How to Tether Your Raspberry Pi with Your iPhone 5 | Dave Conroy [...]
  6. Headless tethering between Raspberry Pi and iPhone - [...] necessarily have a target application. But there’s a lot of potential. It’s a headless setup for tethering your Raspberry …
  7. rndm(mod) » Headless tethering between Raspberry Pi and iPhone - [...] necessarily have a target application. But there’s a lot of potential. It’s a headless setup for tethering your Raspberry …
  8. Headless tethering between Raspberry Pi and iPhone - RaspberryPiBoards - [...] necessarily have a target application. But there’s a lot of potential. It’s a headless setup for tethering your Raspberry …
  9. Headless tethering between Raspberry Pi and iPhone | Daily IT News on IT BlogIT Blog - [...] necessarily have a target application. But there’s a lot of potential. It’s a headless setup for tethering your Raspberry …
  10. Headless tethering between Raspberry Pi and iPhone | Blog of MPRosa - [...] necessarily have a target application. But there’s a lot of potential. It’s a headless setup for tethering your Raspberry …
  11. Tethering sin cabeza entre Raspberry Pi y iPhone - | Indagadores |Seguridad informatica |Seguridad en internet - [...] truco no tiene necesariamente una aplicación de destino. Pero hay un gran potencial. Es un instalación sin cabeza …
  12. Headless tethering between Raspberry Pi and iPhone | Make, Electronics projects, electronic Circuits, DIY projects, Microcontroller Projects - makeelectronic.com - [...] necessarily enjoy a ambition use. Only there’s a multiple of possibility. It’s a headless setup for tethering your Raspberry …
  13. How to Tether Your Raspberry Pi with your iPhone 5 @Raspberry_Pi #piday #raspberrypi « adafruit industries blog - [...] Dave Conroy writes: [...]
  14. Anchored: #3 » Michael Leonard - [...] [Link] This walkthrough from Dave shows how you can mount your iPhone on Raspberry Pi even if you don’t …

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>