Monday, February 18, 2008

TUTORIAL: Better iPhone tethering

YOU NEED TO HAVE A JAILBROKEN PHONE AND DOWNLOAD THIS FILE.

Tethering allows you to access your iPhone's mobile data connection through
your laptop using WiFi. This can be very useful for nerd emergencies where the
iPhone is your only connection to the Internet, such as in an airport or in
the middle of a corn field.

These instructions describe how to tether your Leopard-based notebook. The
steps for other operating systems (such as Windows) are likely different, but
should be possible to do.

NOTE: Check your mobile carrier's terms of service before using. Some mobile
service providers consider it a violation of their terms of service to
tether.

WHAT YOU WILL NEED

1. A WiFi-enabled notebook running Leopard
2. A jailbroken iPhone, running the BSD Subsystem
3. My port of BIND/DNS from here: http://www.zdziarski.com/iphone/

HOW-TO

Step 1: Create an Ad-Hoc Network

Leopard has the ability to easily create ad-hoc networks on-the-fly. You'll
need to create one of these so that the iPhone and your notebook can share
a WiFi network connection.

To create an ad-hoc network, click on the airport icon on the menubar in
Leopard. Select "Create Network...". You will be prompted to "Create a
Computer-to-Computer network". You can name the network anything you like -
we will use "Tethering". Once you have named it, click "OK".

NOTE: The iPhone appears to have difficulty connecting to an ad-hoc network
that is password-protected (e.g. WEP encrypted). You'll want to avoid
requiring a password to join the network.

Step 2: Set the Notebook's Local IP

At this point, your ad-hoc network has been created and your notebook is
connected to it, but because your notebook doesn't run a DHCP server, a
nonroutable IP address will be assigned. You'll need to manually set an
IP address and netmask so that the iPhone and the notebook can talk to each
other. The easiest way to do this is by manually configuring the wireless
interface from a terminal window.

Open a terminal window and type the following command in Leopard:
# sudo ifconfig en1 inet 192.168.0.1 netmask 255.255.255.0

The IP address of your wireless interface will now be set to 192.168.0.1.

Step 3: Connect the iPhone to the ad-hoc network

Now connect your iPhone to the ad-hoc network. Go to Settings -> WiFi.
You should see the name of your ad-hoc network on the network list (in
our example, "Tethering"). Tap the network and you should connect.

Once connected, you'll need to configure the iPhone to have a static address
on the network. Tap the blue disclosure arrow to bring up the iPhone's
network settings. Tap "Static" to set the information manually. Now enter:

IP Address: 192.168.0.2
Subnet Mask: 255.255.255.0
DNS: [ IP of your ISP's DNS Server ]

Press the back button (labeled "Wi-Fi Networks") for these changes to
take effect.

You should now be able to ping 192.168.0.2 from your notebook. If you
can't, you've done something wrong. Go back and repeat these steps.

Step 4: Run SOCKS Relay Daemon

Once both devices are connected to the ad-hoc network, you can start up
the SOCKS daemon on the iPhone. If you have the BSD subsystem installed,
you should be able to just type 'srelay' from MobileTerminal, or ssh into
your iPhone and run it from there. It will launch into the background.

To confirm that it is running, you can run:
# netstat -an grep LISTEN

You should see:

tcp4 0 0 *.1080 *.* LISTEN

Step 5: Set up DNS

If you are tethering specifically to use Firefox, you won't need to set up
the iPhone's DNS server. Instead, go into Firefox's configuration by
typing "about:config" into the URL window and hitting enter. Scroll down
to find the network.proxy.socks_remote_dns option and set it to true.

If you're using any other applications over our tethered connection, you
may need to run a DNS server from your iPhone to provide name resolution.
Install the BIND/DNS package from http://www.zdziarski.com/iphone/ and
extract it onto the iPhone:

# cd /
# tar -zxvf bind-9.4.2_arm-apple-darwin.tar.gz

You should now be able to start the DNS server by running:
# named -c /var/named/named.conf

If you have any problems, try running it with the -g argument to run it
in the foreground, to display stderr.

You'll need to set /etc/resolv.conf to use 192.168.0.2

Step 6: Configure your Applications

Apple has made some recent changes to Leopard so that setting the iPhone
as a SOCKS server in the network preferences will cause the connection to
be lost. This means you'll have to configure your applications individually
to use the iPhone as a SOCKS proxy. Some of the more popular applications
are below:

Firefox:
Go into Firefox preferences -> Advanced -> Network Tab. Click the
"Settings..." button in the "Connection" section. Select
"Manual proxy configuration". For SOCKS host, use 192.168.0.2 Port 1080

SSH:
Use the -L flag in SSH to port forward any ports to the iPhone, and
then from the iPhone to your destination machine. This will allow you
to tunnel your IMAP/POP mail and whatnot.

That's it - you should be able to connect via SOCKS

No comments: