SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2014-10-23 20:12:19

twoion
Emerald Caffeine
From: 星界
Registered: 2012-05-11
Posts: 1,648

[HowTo] Android<>Linux USB Tethering

For possibly future reference, the following describes the (very few) steps that are necessary for getting a well-configured Android phone to USB-tether with your Linux box.

If your Android has been crippled by your carrier as to prevent tethering with a computer -- I gather that this is a thing in some places --, you might have to employ other or more drastic measures which to cover this is not the right place. The following steps have been tested with an international Samsung Galaxy Express (@Android 4.1.2), Debian Sid and a 3.14 kernel.

The gist is that we use the usbnet driver and the Linux RNDIS implementation (Remote Network Driver Interface Specification) to spawn another network interface usbX, over which we can establish a network connection as usual.

First, load the necessary kernel modules:

$ modprobe usbnet
$ modprobe rndis_host

Second, connect the phone via USB and enable USB tethering, for example: Settings > Wireless and networks > More settings > Tethering and portable hotspot > check the "USB tethering entry". In my case, Android somehow fails to detect the computer properly when the USB cable was already plugged in before turning the computer on...oh noes.

Third, run

$ ip link

You should see a device named usbX, where X is a number, that is an entry like this:

$ ip link
# ...
7: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 50
    link/ether 02:06:06:52:32:31 brd ff:ff:ff:ff:ff:ff

Fourth, establish a network connection using DHCP, for example using network-manager. If you don't use any network manager, dhclient is good for this (from the 'isc-dhcp-client' package):

$ dhclient usb0

Check whether the routing table has been set up correctly, for example:

$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.42.129  0.0.0.0         UG    0      0        0 usb0
192.168.42.0    *               255.255.255.0   U     0      0        0 usb0

You should now be able to connect to the internet. To release the DHCP lease after having ended the tethering, do

$ dhclient -r usb0

If all went well, you might want to load the kernel modules at boot time: Add these lines to /etc/modules:

usbnet
rndis_host

Done.

--
References: Android USB Tethering (Gentoo), Android tethering (Arch).


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

Help fund CrunchBang, donate to the project!

#2 2014-10-23 20:18:40

Head_on_a_Stick
CatMod
From: A world of pure imagination
Registered: 2014-01-21
Posts: 4,797

Re: [HowTo] Android<>Linux USB Tethering

Amazing! Thanks for this!
smile

Offline

#3 2014-10-24 06:53:50

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: [HowTo] Android<>Linux USB Tethering

twoion wrote:

In my case, Android somehow fails to detect the computer properly when the USB cable was already plugged in before turning the computer on...oh noes.

same here.

on arch all i do is run "sudo dhcpcd enp0s2...(some weird network name)". i found out more or less by accident at some point that this is possible.
is it ok to do it like that?

(the drivers usbnet and rndis_host already get loaded automatically)

Offline

#4 2014-10-24 17:34:13

twoion
Emerald Caffeine
From: 星界
Registered: 2012-05-11
Posts: 1,648

Re: [HowTo] Android<>Linux USB Tethering

ohnonot wrote:
twoion wrote:

In my case, Android somehow fails to detect the computer properly when the USB cable was already plugged in before turning the computer on...oh noes.

same here.

on arch all i do is run "sudo dhcpcd enp0s2...(some weird network name)". i found out more or less by accident at some point that this is possible.
is it ok to do it like that?

(the drivers usbnet and rndis_host already get loaded automatically)

Of course, it's just a different method using a different tool.


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo