Ditch Your Cable Modem/ISP With a Tethered iPhone and Raspberry Pi

Last month, I wrote a blog post about tethering your iPhone to your Raspberry Pi. I got a lot of emails regarding this post, and one in particular caught my eye. It was from a fellow tech-enthusiast/cord cutter who wanted to save the ~60$ a month that he was paying for his cable modem, and instead tether his iPhone which already has a data plan.

Before getting started I realize this setup is not for power users, but instead for people who may

  • -travel often for work
  • -own a second residence and don’t want to pay two internet bills
  • -have tethering paid for by their employer
  • -have light internet usage or unlimited data plans
  • -cord cutters on a budget

 

Intrigued by this idea, I started testing it myself and got it working fairly easily. I already covered the full operating system setup in the Raspberry Pi/iPhone Tethering post, so I will just start with the tethering portion for this tutorial.

Prerequisites

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

sudo apt-get update
sudo apt-get install gvfs ipheth-utils
sudo apt-get install libimobiledevice-utils ifuse 
sudo apt-get install 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.

Hot Swapping

So now we have our Raspberry Pi Recognizing our iPhone, but in the scenario we are trying to account for – we need to be able to hotswap our phone on and off our networks for it to be truly useful. To do so, 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.

In my testing, tethering with only worked when the iPhone is mounted. To do this, we need to implement the ifuse package we downloaded earlier. First, 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, at this point the iPhone must manually be mounted each time it is plugged using the ifuse command.

Finishing the iPhone Portion

Having the Raspberry Pi connected to the internet via the iPhone is an important step, but it is a hassle to have to mount the iPhone everytime.

To automate the process, we need to create 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
/etc/init.d/networking restart #this may not be necessary, but just a safe guard to rebridge the connection
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”

 

Success!

iPhone Tethered Raspberry Pi

Replacing your Cable Modem with the Raspberry Pi

This is the part of this tutorial I found the most fascinating. I’m sure most of my readers already have their Wireless Router and Firewall configured exactly how they want, and don’t want to have to change any of those settings. The goal here is to just take the uplink ethernet cable from the router out of the cable modem and into the Raspberry Pi and then practice business as usual.

Bridging the Gap

In order to do this, we just need to bridge the connection from the iPhone interface (eth1) with the built in ethernet interface (eth0). To do so, we first need to install the bridge utilities,

sudo apt-get install bridge-utils

and then edit our network interfaces file again

sudo nano /etc/network/interfaces

and add the following lines

auto br0
iface br0 inet dhcp
bridge_ports eth1 eth0

Save and close the interfaces file, and reboot the rPi

sudo reboot

At this point, I logged into my Wireless Router and gave it a static IP, and used google’s public DNS. I am sure this step could be skipped if we setup a simple dhcp server on the rPi. When I have that working I will update this post with the optional step.

router ss

Results

Here is just a quick picture of my demo environment.
iphone-router-setup
I also did some speed tests and got some remarkable results. 10mb/s over Verizon’s 4G LTE. I am willing to bet that is faster than many home WiFi networks. Upload speeds were a less impressive, but still useful .25 mb/s.

downloadspeed

Troubleshooting

I noticed that because of the boot order of the network interfaces, and mounting of the iPhone, it worked best if I did a quick network reset after the device had fully booted. To do so, edit the rc.local file

sudo nano /etc/rc.local

and add the following line before the exit 0

/etc/init.d/networking restart

This will reestablish the bridge if the iPhone wasn’t tethered in time on boot.

If you have any other questions, just comment on this post.


4 comments

  1. Confirmed that this method works as advertised. This is awesome! Thank you, Dave!

  2. Carriers like T-Mobile are currently restricting users with unlimited data plans to ~2.5GB per month before they start nickel-and-diming customers on upgrades (e.g. 4.5, 6.5, 10.5GB) which will not support streaming HDTV for more than a few hours. If anyone figures out how to cajole the iPhone to act as a hotspot but report only mobile data usage you win the Internet.

  3. Hi,

    The phone keeps popping up a Trust warning over and over again. The Trust/Not Trust buttons appear and the Trust button is greyed out. I am using iOS 7 and wonder if you have had it working since the latest update ?

    Cheers,

    Dave.

  4. Hi,

    The phone keeps popping up a Trust warning over and over again. The Trust/Not Trust buttons appear and the Trust button is greyed out. I am using iOS 7 and wonder if you have had it working since the latest update ?

    Cheers,

    Dave.

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>