iPhone laptop internet access

Long time no post. I’ve been in the process of both moving and changing jobs, so I’ve definitely neglected the blog. The move, however, has left me without Internet access (akin to being without oxygen) and so I’ve been surviving on my iPhone. Of course, given that my iPhone functions as yet another *nix box to me, I set out to get my laptop some internet by way of my iPhone. If I’m breaking terms of agreement here, then this is all just pretend.

This post is for linux users. It doesn’t explain how to do it on your crappy windows box, although if you’re at all savvy, you should be able to figure it out in the same way. Or just google around for keywords like iphone tether laptop.

In my scenario, I’ve got a linux laptop running Debian/sid and a jail-freed iPhone. There are quite a few howto’s already out there, such as this one which I followed for awhile… until I thought I found a less complicated way. There was also this one, but again, I thought it seemed easier to do it my way. Not saying, of course, that my way is the best way… this is just how I did it. I also stumbled upon a couple of gotchas that I had not seen outlined elsewhere, so read on for more awesomeness.

I use the Cydia package installer by Jay Freeman on my iPhone because it’s gloriously built on top of one of my favorite tools, APT. He has made the keen move of not reinventing the wheel here, and instead improving it. Good design principles. Via Cydia, I have simply installed ssh on my iPhone.

So the steps of setting up your little iPhone <-> laptop network will be:

First, let’s create the ad-hoc wireless network. On your linux laptop, assuming you’ve ever used your wireless before, you should have ‘iwconfig’ installed. The goal here is to create an ad-hoc network that your iPhone will be able to join. You can do so with something similar to the following:

In this example, my wireless interface is ‘wlan0′.

rwoodrum@shamp:~$ sudo iwconfig wlan0 mode ad-hoc
rwoodrum@shamp:~$ sudo iwconfig wlan0 essid "iphone_adhoc"
rwoodrum@shamp:~$ sudo ifconfig wlan0 up
rwoodrum@shamp:~$ sudo iwconfig
lo        no wireless extensions.

eth2      no wireless extensions.

wmaster0  no wireless extensions.

wlan0     IEEE 802.11g  ESSID:"iphone_adhoc"
          Mode:Ad-Hoc  Frequency:2.412 GHz  Cell: 8A:B3:63:C0:DB:B2
          Tx-Power=27 dBm
          Retry min limit:7   RTS thr:off   Fragment thr=2352 B
          Encryption key:off
          Link Quality:0  Signal level:0  Noise level:0
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

So you can see above that my wireless card is configured in ad-hoc mode and that the ssid is “iphone_adhoc”.

Now if you search for wireless networks with your iPhone, you should see the “iphone_adhoc” network in your network list under Settings -> Wi-Fi. Choose to join the network by tapping it. Note that by joining an ad-hoc network, your iPhone will retain its network configuration on the Edge network (interface ip1) and it will retain a default route to the Internet based on the Edge network. This is important.

Now you need to get them on the same network. If you elect to use the link-local addresses in the 169.254/16 network, just note the address on your iPhone and subsequently configure your laptop to be on the same network. For example, if your iPhone comes up with address 169.254.105.88/16, you could put your laptop as 169.254.105.89/16. Alternatively, you could go the extra step to put them on a different network of your choosing. Because extra steps are for the uncool, I’ll just let the iPhone choose it’s address in the 169.254/16 network and put my laptop on the same network like this:

sudo ifconfig wlan0 169.254.105.89 netmask 255.255.0.0

You should now be able to ping your iPhone from your laptop.

At this point, I’ll bring up gotcha #1. When your iPhone auto-locks, your connection will die. From this point out, it’s probably a lot easier to simply disable this. To do so, go under Settings -> General -> Auto-Lock and change it to “Never.” Just don’t forget to change it back.

Now, we need to ssh into the iPhone using it as a socks proxy. This will allow the connections of our laptop to go through the iPhone. To establish this connection, ssh to your iPhone using something like the following. In my example, I’m simply ssh’ing as the ‘mobile’ user (the default user on the iPhone):

rwoodrum@shamp$ ssh -f -N -D 9999 mobile@169.254.105.88

This will put ssh into the background listening on tcp/9999. If a connection is received, it will forward it over the secure connection and subsequently use the application level protocol to determine where to connect from there. Before you can use this, however, you should configure your Iceweasel/Firefox to shunt DNS lookups over this channel as well. You do this by editing the ‘network.proxy.socks_remote_dns’ value to ‘true’ under ‘about:config’ in the browser.

You must also configure your socks proxy under Edit -> Preferences -> Advanced tab -> Settings button to point to your new ssh socks proxy. To do this, enter under ‘SOCKS Host’ the value 127.0.0.1 with port 9999. You must ensure that no other proxy values exist. All others must be blank.

Now, on your laptop, modify the routing table to add the iPhone as the default route to the Internet. If my iPhone has an address of 169.254.105.88, I would do this like so:

rwoodrum@shamp$ sudo route add -net 0.0.0.0/0 gw 169.254.105.88

You’re almost done.

You may need to shutdown Iceweasel/Firefox entirely just to make sure all the application level changes take effect.

You should now be able to fire up your browser and hit something like google.com. It’ll be slow… but it’ll work.

One thing you may experience is that during your internet browsing, Iceweasel/Firefox will suddenly complain about timeouts. You may also notice that the Edge icon on your iPhone has changed to a wireless connection. The Edge connection seems to periodically “shut down” when not used directly from the iPhone. To remedy this situation, I simply fired up the “weather” button and periodically switched it from city to city so the update would take place. This fires up the Edge connection from the iPhone itself and seems to breathe life back into the connection via the laptop. Not ideal… but at the time of this writing, it’s what worked.  Alternatively from a shell on the phone you could just start a ping or something.  Given limited bandwidth, however, you may want to increase to every x number of seconds or something.

Comments appreciated! I’d be happy to help anyone in need with a beloved iPhone and no beloved Internet!

Comments

Leave a Reply