This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

Android USB Tethering

From Gentoo Wiki (test)
Jump to:navigation Jump to:search
Resources

Tethering means sharing the Internet connection of an Internet-capable mobile phone with other devices. This sharing can be offered over a wireless LAN (Wi-Fi), or over Bluetooth, or by physical connection using a cable (Tethering).

The focus of this article is USB tethering.

Android mobile phones can behave as an external network interface usbN, connected via the USB infrastructure. The usbN interface is in turn connected to the mobile phone LAN, providing dhcp server, DNS server, gateway and so on.

That is how a mobile phone can provide an Internet connection to another device.

Android phones are already equipped to provide this functionality. Simply connect the USB cable and go to Settings -> Wireless settings -> Tethering -> Tethering USB.

What you need is some kernel and network configuration on the other side (e.g. a laptop).

Kernel configuration

Version 3.0.6

KERNEL .config 3.0.6-gentoo
General setup  --->
    [*] Prompt for development and/or incomplete code/drivers
Device Drivers --->
    [*] Network device support --->
        USB Network Adapters --->
            [*] Multi-purpose USB Networking Framework
                <M> CDC Ethernet support
                <M> CDC EEM support
                <M> Simple USB Network Links (CDC Ethernet subset)
                <M>   Host for RNDIS and ActiveSync devices
            [*] Embedded ARM Linux links

Version 3.12.21

KERNEL .config 3.12.21-gentoo-r1
Device Drivers --->
    [*] Network device support --->
        USB Network Adapters --->
            [M] Multi-purpose USB Networking Framework
                <M> CDC Ethernet support
                <M> CDC EEM support
                [M] Simple USB Network Links (CDC Ethernet subset)
                    [*] Embedded ARM Linux links

Version 4.4.6

KERNEL .config 4.4.6-gentoo
Device Drivers --->
    [*] Network device support --->
        <M> USB Network Adapters --->
            <M> Multi-purpose USB Networking Framework
                <M>  CDC Ethernet support (smart devices such as cable modems)
                <M>  CDC EEM support
		<M>  Host for RNDIS and ActiveSync devices
                <M>  Simple USB Network Links (CDC Ethernet subset)
                     [*] Embedded ARM Linux links (iPaq, ...)

Features can either be built-in to the kernel or available as loadable modules.

Note
The RNDIS feature seems to only be needed in some cases. See this thread to learn more.

Tested devices

  • Fairphone 2 (Fairphone OS Android 6.0.1, build no FP2-gms-18.04.1) -- needed rndis_host module Processus42 (talk) 18:55, 11 October 2018 (UTC)
  • Google Nexus One (Android 2.3.6 build GRK39F)
  • Google Nexus 4 (Android 4.3 build JWR66Y - uses rndis_host)
  • HTC Desire HD (Android 2.3.6 Stock Rom build and Android 4.4.4 (unofficial CyanogenMod 11) -- needed rndis_host module for both Roms)
  • HTC One M7 (Sense 5.5, Android 4.3, Software number 3.62.401.1,HTC SDK API level 5.65 - I used rndis_host, cdc_ether and usbnet modules ONLY to get it to work)
  • Huawei Honor 4x (unofficial CyanogenMod 11 / Android 4.4.4, works great) -- needed rndis_host module AleiPhoenix (talk) 13:57, 3 July 2015 (UTC)
  • LG P350 (Android 2.2.1 build FRG83)
  • LG E400 (Android 2.3.6 build GRK39F)
  • LG L7 P705 (Android 4.1.2 build JZO54K)
  • Motorola Defy (Android 2.3.7 Cyanogenmod 7)
  • Motorola Moto G 4G 2013 (1st Gen) (Android 5.1) -- needed rndis_host module -- User:mercuriete
  • OnePlus One -- needed rndis_host module
  • Samsung Galaxy Grand Neo+ Duos (GT-I9060I / Android 4.4.4) -- onli needed rndis_host - cdc_ether - usbnet modules
  • Samsung Galaxy Nexus i9250 (Android 4.0.1 ITL41D, Android 6.0.1 (CyanogenMod 13)) -- needed rndis_host - Ant P. (talk) 00:12, 27 October 2018 (UTC)
  • Samsung Galaxy S i9000
  • Samsung Galaxy S2
  • Samsung Galaxy S3 (GT-I9300 Android 4.3 Stock Rom)
  • Samsung Galaxy S4 Mini Duos (GT-I9192, unofficial CyanogenMod 12.1 / Android 5.1) -- needed rndis_host module
  • Samsung Galaxy S5 (Android 6.0.1) -- needed rndis_host module
  • Samsung Galaxy S6 (Android 7.0) -- needed rndis_host module
  • Samsung Galaxy S7 -- needed rndis_host module
  • Samsung Galaxy Tab 2 7.0 (android 4.1.2)
  • Sony Xperia Go (St27i Android 4.1.2 Stock Rom build no 6.2.A.1.100 -- needed rndis_host module for me - User:LordVan )
  • Sony Xperia X Compact (Android 8.0.0, build no 34.4.A.2.118) -- needed rndis_host module and "Embedded ARM Linux links" (CONFIG_USB_ARMLINUX) on kernel 4.16.18 - Ahippo (talk) 18:58, 25 October 2018 (UTC)
  • Sony Xperia XZ Premium (G8142 Stock Android 8.0, build no 47.1.A.8.49) -- needed rndis_host module AleiPhoenix (talk) 06:56, 29 January 2018 (UTC)
  • Wileyfox Storm (CyanogenOS 13.1.5 - android 6.0.1)

Testing

root #dmesg
usb 1-7: New USB device found, idVendor=18d1, idProduct=4e13
usb 1-7: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-7: Product: Nexus One
usb 1-7: Manufacturer: Google, Inc.
usb 1-7: SerialNumber: HT9CSP803294
usb 1-7: usb_probe_device
usb 1-7: configuration #1 chosen from 1 choice
usb 1-7: adding 1-7:1.0 (config #1, interface 0)
rndis_host 1-7:1.0: usb_probe_interface
rndis_host 1-7:1.0: usb_probe_interface - got id
rndis_host 1-7:1.0: usb0: register 'rndis_host' at usb-0000:00:1d.7-7, RNDIS device, ea:61:37:88:a2:e5
usb 1-7: adding 1-7:1.1 (config #1, interface 1)
drivers/usb/core/inode.c: creating file '004'
hub 1-0:1.0: state 7 ports 8 chg 0000 evt fe80
uhci_hcd 0000:00:1d.0: reserve dev 2 ep81-INT, period 8, phase 4, 93 us
usb 1-7: link qh32-0001/ffff88021aa4bc80 start 1 [1/0 us]
usb0: no IPv6 routers present
root #ifconfig -a

If you see usb0 (0 may be a different number) you are all set.

Connecting

Since the mobile phone LAN changes its addresses, you need a DHCP client to configure the usbN device.

If you are on a laptop, you probably have a DHCP client. If not, emerge net-misc/dhcpcd:

root #emerge --ask net-misc/dhcpcd

Manually

Simply run dhcpcd after plug/mobile activation:

root #dhcpcd usb0

Permanent configuration

Edit your /etc/conf.d/net to have a permanent, automatic activation of the interface.

root #echo "config_usb0=\"dhcp\"" >> /etc/conf.d/net

Once plugged in and activated on the mobile phone side, the usb0 will be up and configured.

Checks

Run the usual checks to verify the connection:

root #ifconfig usb0
root #route
root #cat /etc/resolv.conf

Advanced network settings

DHCP is very quick, but the default settings don't give you as much freedom as you may want.

A possible scenario is that you are in a corporate, protected LAN context that doesn't provide Internet connection but you need to stay connected to have access to some Intranet resource.

Or maybe you have a free but limited connection (a public WiFi network allowing HTTP only, an evil firewall, etc.). Since mobile connections could be expensive, you could want to save money by tethering only when needed.

Here is a handful of examples pertaining to DHCP usage.

If you want to limit the information set by DHCP, you can fine-tune its behaviour.

E.g.:

root #dhcpcd --nogateway --nohook resolv.conf --nohook hostname usb0

This will let your default gateway, resolv.conf and hostname as they are, letting you provide extra info by hand.

E.g.:

root #route add -host my_sshd_remote_host_IP dev usb0

Finally, you can permanently configure your USB network interface.

E.g:

FILE /etc/conf.d/net
config_usb0="dhcp"
dhcpcd_usb0="--nogateway --nohook resolv.conf --nohook hostname"
# Special hosts
postup()
{
    if [[ "usb0" == ${IFACE} ]]; then
        route add -host my_sshd_remote_host_IP dev usb0
    fi
}

Generally, you can avoid every DHCP setting (see the man page) but gather them with:

root #dhcpcd -U usb0

Then you can set what you want in the postup hook.

See also