Tethering the iPhone 3g with Linux.

The aspect of the iPhone that made me hesitate in buying one the most was losing my ability to gain internet connectivity on my laptop though my phone. I’ve used this when I’m out of town at times to get connectivity, and it’s been quite the handy tool when there are no wifi hotspots to be found.

Today, I jailbroke my phone and managed to get a SOCKS proxy running on it. With a bit of Ad-Hoc wifi from my laptop, browsing the web with more Gs was easily at my fingertips. Here’s what I did.

  1. Jailbreak the iPhone. I used winpwn. It was pretty easy, and the internet will tell you how.
  2. Install 3proxy, insomniac, and either OpenSSH or mobile terminal.
  3. Either from a ssh session or the terminal, run proxy
  4. Set up a DHCP server on the laptop. This requires a config file, which I’ll include later. You could also use a static IP if that’s your bag.
  5. Bring the wifi card down and set it in Ad-Hoc mode. I did this using NetworkManager because I’ve become lazy, but its pretty easy to do with iwconfig as well.
  6. Take the wifi card up and assign it an IP in the same subnet as what your dhcp server is using.
  7. Turn on insomnia so your wifi connection doesn’t get shut down when the device goes idle.
  8. Have the iPhone connect to the Ad-Hoc network. I left dhcpd in foreground mode with debug on to watch the phone request an IP.
  9. Set firefox to use a SOCKS v5 proxy on port 1080 with the IP address your phone.
  10. Enable network.proxy.socks_remote_dns in about:config in Firefox. You need DNS to be routed across the proxy rather than firefox trying to hit whatever (likely invalid) nameserver is in /etc/resolv.conf
  11. Enjoy the internets.

The end result is your traffic goes over wifi to a proxy on the iPhone, and then out the 3G radio to ATT’s network. It’s a little flaky and to be honest I only plan on using this when I have no other means of using the Internet and I really need connectivity. The 3G network aspect of this is rather nice compared to the EDGE speeds I was used to with the Pearl. Being able to talk to the GPRS modem on the phone was much more functional, though. Proxies are a pain. I haven’t checked to see if ping times are worse or better over HSDPA versus EDGE.

As for the dhcpd.conf, it was pretty minimalist:

ddns-update-style ad-hoc;
subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.10 192.168.1.20;
}

It could be simpler, and I could do static IP assignment so I don’t have to adjust Firefox’s proxy settings, but it worked long enough as a proof of concept.