Tuesday, March 08, 2011

Android and Linux tethering

If you have no idea what tethering is, then fear not, Wikipedia to the rescue!

Tethering is a method to share the Internet connection of an Internet-capable mobile phone. This sharing can be via cable, or wirelessly over Bluetooth or Wi-Fi — if Wi-Fi, the tethering feature is often branded as a mobile hotspot and can typically service several devices.

Most Android phones have a feature to make this simple, but either the ROM I flashed my device with has a bug or my service provider does not support WIFI hotspot, whatever the case I need to connect via the USB cable.

In short, this is how to go about it:

  • Install OpenVPN

    sudo apt-get install openvpn

  • Enable USB debugging on your phone. Settings > Applications > Development > USB debugging.

  • Download or install the Android SDK
    On Arch Linux you just install both android-sdk and android-sdk-platform-tools. If you need to download it:

  • Now extract the package:

    tar xvzf http://dl.google.com/android/android-sdk_r10-linux_x86.tgz -C /opt

  • Run "android" and install the platform tools needed:

    cd /opt/android-sdk-linux_x86/tools

    From the menu, choose "Available packages" and install the Android SDK platform-tools.

  • Add the /opt/android-sdk-linux_x86/platform-tools directory to your path:

    nano -w .bashrc

    You will need to log out and back in for the path to be recognized.

  • We now need our device ID:

    Bus 001 Device 009: ID 22b8:41da Motorola PCS

  • Next we create the needed udev rules so that the device gets recognized:

    sudo nano -w /etc/udev/rules.d/91-android.rules
    SUBSYSTEM==”usb”, SYSFS{idVendor}==”id″, MODE=”0666″

    On my phone the last part will look like this, change yours according to your device ID:
    SUBSYSTEM==”usb”, SYSFS{"22b8:41da"}==”22b8″, MODE=”0666″

  • You can connect your phone to the PC now, if it is not already connected, remember to make sure you have USB debugging enabled.
    If all went well your phone should now be picked up:

    adb devices
    List of devices attached 
    04039C5D09016014 device

  • Download and install AzLink:

    wget http://lfx.org/azilink/azilink.apk
    adb install azilink.apk

    You should see the AzLink app in the phone applications menu now.

  • On your PC:

    adb forward tcp:41927 tcp:41927

    On your phone, open the AzLink application and check the option "Service Active". You should see a message under Status:
    "Waiting for connection"

  • Download and run the following on your PC:

    wget http://azilink.googlecode.com/files/azilink.ovpn
    sudo openvpn azilink.ovpn

    On your phone the status should now change to:
    "Connected to host"

    You can now kill all network connections on you PC (wifi and lan) and disable them for the moment, we do not need them any more.

  • Finally, the last step.
    Do not close the terminal from where you ran the commands just now! Doing so will kill your connection to the phone.
    In a new terminal we only now need to edit our resolv.conf and we should have internet access!

    nano -w /etc/resolv.conf

You should be able to browse the internet now from your phones data connection (GPRS, HSDPA, etc.)

Reply with your comments and if you encounter any problems!