Difference between revisions of "Android tethering"

From ArchWiki
Jump to: navigation, search
(Tethering with proxy)
 
(61 intermediate revisions by 21 users not shown)
Line 1: Line 1:
 +
[[Category:Network sharing]]
 +
[[Category:Mobile devices]]
 
[[fr:Modem attache Android]]
 
[[fr:Modem attache Android]]
[[Category:Networking]]
+
[[ja:Android テザリング]]
==What is Tethering==
+
[[ru:Android tethering]]
 
+
Tethering is a way to have internet access on your PC through your smartphone using its network connection. USB tethering and Wi-Fi access point tethering are natively supported since Android 2.2 "Froyo".
Tethering is a way to have Internet access on your PC through your smartphone using its network connection.
+
USB and Wi-Fi access point tethering is natively supported from Android Froyo ( 2.2 ). Older versions of the Android OS, mostly unofficial roms
+
have this option enabled.
+
  
 
== Wi-Fi access point ==
 
== Wi-Fi access point ==
Using an Android phone as a Wi-Fi access point (using 3G) has been accessible by default since Froyo (Android 2.2) without needing to root the phone. Moreover, this method will discharge the battery rapidly and tends to cause intense heating, unlike USB.
+
Using an Android phone as a Wi-Fi access point (to a 3G/4G mobile internet connection) is available for devices running Android 2.2 "Froyo" or newer.
See : '''menu/wireless & networks/Internet tethering/Wi-Fi access point'''
+
  
== USB tethering ==
+
Enable it in {{ic|Settings -> Wireless & networks -> Internet tethering -> Wi-Fi access point}}
  
===Tools Needed===
+
{{Note|On some phones, this method will discharge the battery rapidly and tends to cause intense heating, unlike USB.}}
* Root access to the phone (for old Android versions, Froyo (Android 2.2) and beyond can do it natively)
+
* USB connection cable from your phone to PC
+
  
=== Procedure ===
+
== USB tethering ==
*Enable USB Debugging. This is usually done from Settings --> Applications --> Development --> USB debugging. Reboot the phone after checking this option to make sure USB debugging is enabled (if there is no such option, this step probably does not apply to your version of Android)
+
*Disconnect your computer from any wireless or wired networks
+
*Connect the phone to your computer using the USB cable (the USB connection mode -- Phone Portal, Memory Card or Charge only -- is not important, but please note that you will not be able to change the USB mode during tethering)
+
*Enable the tethering option from your phone. This is usually done from Settings --> Wireless & Networks --> Internet tethering (or Tethering & portable hotspot, for more recent versions)
+
  
'''(The following step may not be needed. usbnet module may not be necessary, do it only if you do not see a usb0 interface in the ifconfig step)'''
+
USB tethering is available for devices running Android 2.2 "Froyo" or newer.
*Load the usbnet module(if it's not already loaded). You will need root access to do that
+
modprobe usbnet
+
  
*Make sure that the USB interface is recognized by the system by using the following command:
+
* Disconnect your computer from any wireless or wired networks
ifconfig -a
+
* Connect the phone to your computer using the USB cable (the USB connection mode -- Phone Portal, Memory Card or Charge only -- is not important, but please note that you will not be able to change the USB mode during tethering)
 +
* Enable the tethering option from your phone. This is usually done from {{ic|Settings -> Wireless & networks -> Internet tethering}} (or {{ic|Tethering & portable hotspot}}, for more recent versions)
 +
* Make sure that the USB interface is recognized by the system by using the following command:
 +
: {{bc|$ ip link}}
 +
: You should be able to see a {{ic|usb0}} or {{ic|enp?s??u?}} device listed like this (notice the enp0s20u3 device).
 +
{{hc|# ip link|
 +
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
 +
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 +
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
 +
    link/ether ##:##:##:##:##:## brd ff:ff:ff:ff:ff:ff
 +
3: wlp2s0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
 +
    link/ether ##:##:##:##:##:## brd ff:ff:ff:ff:ff:ff
 +
5: enp0s20u3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
 +
    link/ether ##:##:##:##:##:## brd ff:ff:ff:ff:ff:ff
 +
}}
  
you should be able to see a usb0 device listed like this (notice the usb0 device):
+
{{Note|Take care to use the device name from your own system in the following commands.}}
{{hc|# ifconfig -a|
+
eth0      Link encap:Ethernet  HWaddr 00:16:36:FA:3E:31 
+
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
+
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
+
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
+
          collisions:0 txqueuelen:1000
+
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
+
  
lo        Link encap:Local Loopback 
+
{{Warning|The name may change depending on the usb port you use. You may want to [[Network configuration#Change_device_name|change the device name]] to create a unique name for your device regardless of the usb port.}}
          inet addr:127.0.0.1  Mask:255.0.0.0
+
          inet6 addr: ::1/128 Scope:Host
+
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
+
          RX packets:316435 errors:0 dropped:0 overruns:0 frame:0
+
          TX packets:316435 errors:0 dropped:0 overruns:0 carrier:0
+
          collisions:0 txqueuelen:0
+
          RX bytes:22875193 (21.8 Mb)  TX bytes:22875193 (21.8 Mb)
+
  
usb0      Link encap:Ethernet  HWaddr C2:5A:11:8D:43:F5 
+
* The final step is to [[Network configuration#Configure the IP address|configure a network connection]] on this interface. For example:  
          BROADCAST MULTICAST  MTU:1500  Metric:1
+
: {{bc|# dhcpcd enp0s20u3}}
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
+
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
+
          collisions:0 txqueuelen:1000
+
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
+
  
}}
+
==== Using systemd-networkd with udev ====
*Configure the new network device via DHCP using the following command:
+
ifconfig usb0 up && dhcpcd usb0
+
  
To configure the new network device using the iproute toolkit, issue the following as root:
+
Using [[systemd-networkd]] you can automatically adjust the networking to use the phone as the gateway when plugged in.
ip link set usb0 up && dhcpcd usb0
+
  
To stop the network sharing, issue the command:
+
{{hc|/etc/udev/rules.d/90-android-tethering.rules|<nowiki>
dhcpcd -x usb0
+
# Execute pairing program when appropriate
 +
ACTION=="add|remove", SUBSYSTEM=="net", ATTR{idVendor}=="18d1" ENV{ID_USB_DRIVER}=="rndis_host", SYMLINK+="android", RUN+="/usr/bin/systemctl restart systemd-networkd.service"
 +
</nowiki>}}
  
=== Netcfg ===
+
You may have to adjust the {{ic|idVendor}} attribute depending on your phone. You can check using ''udevadm'':
  
To use Netcfg to configure USB tethering, just add a static ethernet configuration like:
+
$ udevadm info /sys/class/net/enp0s26u1u2
  
{{hc|/etc/network.d/usb-tether|
+
Then create the corresponding systemd-networkd file:
CONNECTION&#61;'ethernet'
+
DESCRIPTION&#61;'A basic dhcp ethernet connection using iproute'
+
INTERFACE&#61;'usb0'
+
IP&#61;'dhcp'
+
}}
+
  
==USB tethering with OpenVPN==
+
{{hc|/etc/systemd/network/enp0s26u1u2.network|<nowiki>
This method works for any old Android version and does not requires root access nor modifications in the phone (it is also suitable for Android 2.2 and later, but no longer required).
+
[Match]
 +
Name=enp0s26u1u2
  
It does not requires changes to your browser; in fact transparently handles all network traffic for any PC application (except ICMP pings). It is somewhat CPU intensive in the phone at high usage rates (a 500 kbyte/sec data transfer rate may take more than 50% of phone CPU on a powerful Acer Liquid).
+
[Network]
 +
DHCP=ipv4
 +
</nowiki>}}
  
===Tools Needed===
+
==USB tethering with AziLink==
In Arch, you need to [[pacman|install]] the {{pkg|openvpn}} package. Is is also required the Android SDK installed (which can be obtained [http://developer.android.com/sdk/index.html here]). In the phone, the [http://code.google.com/p/azilink/ azilink] application, a Java-based NAT that will communicate with OpenVPN in your computer.
+
This method works for all known Android versions and requires neither root access nor modifications in the phone. It does not require changes to your browser. All network traffic is transparently handled (except ICMP pings). It may be somewhat CPU intensive on the phone at high usage rates (a 500 kBytes/sec data transfer rate may take more than 50% of phone CPU).
 +
 
 +
===Tools needed===
 +
For Arch, you need to [[install]] the {{pkg|openvpn}} package. You will also need to install the {{pkg|android-tools}} package for the ''adb'' tool and {{pkg|android-udev}} which sets up the correct {{ic|/usr/lib/udev/rules.d/51-android.rules}} file for your device to be recognized. On the phone, you need the [http://lfx.org/azilink/azilink.apk azulink.apk] ([https://github.com/aziwoqpd/azilink azilink homepage]). The android application acts as a NAT, adb forwards the ports to your phone, and your openvnp setup will connect to it.
  
 
====Configuring the phone connection in Arch Linux====
 
====Configuring the phone connection in Arch Linux====
  
Once you have installed the Android SDK, in order to use the provided tools your phone must be properly set up in [[udev]] and your Linux user needs to be granted rights. Otherwise you may need root privileges to use the Android SDK, which is not recommended. To perform this configuration, turn on USB debugging on the phone (usually in Settings -> Applications -> Development -> USB debugging), connect it to the PC by the USB cable and run the {{ic|lsusb}} command. The device should be listed. Example output for the Acer Liquid phone:
+
So that you do not have to run adb with sudo, we are going to grant your user permissions to your usb device. Make sure you have turned on USB debugging on the phone (usually in Settings -> Applications -> Development -> USB debugging) so that it will be shown as a device, and that it is plugged in to your computer via the USB cable. You should see it with you run the {{ic|lsusb}} command. Original azi link instructions are [https://raw.githubusercontent.com/aziwoqpd/azilink/master/HOWTO here]
 +
 
 +
The device should be listed. Example output for the Acer Liquid phone:
  
 
  Bus 001 Device 006: ID '''0502''':3202 Acer, Inc.  
 
  Bus 001 Device 006: ID '''0502''':3202 Acer, Inc.  
Line 92: Line 80:
 
Then, create the following file, replacing ''ciri'' by your own Linux user name, and '''0502''' by the vendor ID of your own phone:
 
Then, create the following file, replacing ''ciri'' by your own Linux user name, and '''0502''' by the vendor ID of your own phone:
  
{{hc|/etc/udev/rules.d/51-android.rules|2=
+
{{hc|/etc/udev/rules.d/51-android.rules|<nowiki>
<nowiki>SUBSYSTEM=="usb", ATTR(idVendor)=="0502", MODE="0666" OWNER="ciri"</nowiki>  
+
SUBSYSTEM=="usb", ATTR(idVendor)=="0502", MODE="0666" OWNER="ciri"
}}
+
</nowiki>}}
  
As root run the '''udevadm control restart''' command (or reboot your computer) to make the change effective.
+
As root run the {{ic|sudo udevadm control --reload}} command to make the change effective. To make sure the change took effect, run 'adb devices' and it should say 'device' instead of 'unauthorized'. Another way to make it take effect is to reboot. Another test is to run {{ic|adb shell}} to get to your phones unix prompt. The command should work without needing sudo.
Now run in your linux PC the '''adb shell''' command from the Android SDK as plain (non root) user: you should get a unix prompt ''in your phone''.
+
  
 
===Procedure===
 
===Procedure===
Line 106: Line 93:
 
# Run AziLink and make sure that the '''Service active''' option at the top is checked.
 
# Run AziLink and make sure that the '''Service active''' option at the top is checked.
 
# Run the following commands in your Linux PC:
 
# Run the following commands in your Linux PC:
##As plain user: '''adb forward tcp:41927 tcp:41927''' (requires Android SDK installed)
+
: {{bc|$ adb forward tcp:41927 tcp:41927}}
##As root: '''openvpn AziLink.ovpn'''
+
: {{bc|# sudo openvpn azilink.ovpn}}
  
{{hc|AziLink.ovpn|
+
azilink.ovpn source from [https://raw.githubusercontent.com/aziwoqpd/azilink/master/azilink.ovpn here]
<nowiki>dev tun
+
 
 +
{{hc|azilink.ovpn|<nowiki>
 +
dev tun
 
remote 127.0.0.1 41927 tcp-client
 
remote 127.0.0.1 41927 tcp-client
 
ifconfig 192.168.56.2 192.168.56.1
 
ifconfig 192.168.56.2 192.168.56.1
Line 117: Line 106:
 
socket-flags TCP_NODELAY
 
socket-flags TCP_NODELAY
 
keepalive 10 30
 
keepalive 10 30
dhcp-option DNS 192.168.56.1</nowiki>  
+
dhcp-option DNS 192.168.56.1
}}
+
</nowiki>}}
  
===Troubleshooting===
 
  
====DNS====
+
You may need to manually update the contents of [[resolv.conf]] to
You may need to manually update the contents of '''/etc/resolv.conf''' to
+
  
 
{{hc|/etc/resolv.conf|
 
{{hc|/etc/resolv.conf|
Line 129: Line 116:
 
}}
 
}}
  
====NetworkManager====
+
If you're running NetworkManager, you may need to stop it before running OpenVPN.
If you're running NetworkManager, you may need to stop it with '''systemctl stop NetworkManager''' before running OpenVPN.
+
 
 +
==USB tethering with EasyTether==
 +
 
 +
Get the [http://www.mobile-stream.com/easytether/drivers.html easytether] linux client software. The commands to set it up and run it are as follows.
 +
 
 +
# pacman -U easytether-0.8.5-2-x86_64.pkg.tar.xz
 +
# easytether-usb
 +
# dhcpcd tap-easytether
 +
 
 +
Make sure you have the EasyTether android app installed on your phone for it to connect to. Note: The Lite app disables some connections and you must have the paid app for full functionality. For this reason, using the AziLink setup is recommended instead.
 +
 
 +
==Tethering via Bluetooth==
 +
 
 +
Android (from at least 4.0 onwards, possibly earlier) can provide a Bluetooth personal-area network (PAN) in access point mode.
 +
 
 +
NetworkManager can perform this action and handle the network initialisation itself; consult its documentation for more details.
 +
 
 +
Alternatively: pair and ensure you can connect your computer and Android device, as described on [[Bluetooth]], then, substituting the address of the device (here given as {{ic|AA_BB_CC_DD_EE_FF}}), do:
 +
 
 +
{{bc|<nowiki>$ dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_AA_BB_CC_DD_EE_FF org.bluez.Network1.Connect string:'nap'</nowiki>}}
 +
 
 +
This will create a network interface {{ic|bnep0}}.  Finally, [[Network configuration#Configure the IP address|configure a network connection]] on this interface; Android offers DHCP by default.
  
 
==Tethering with SOCKS proxy==
 
==Tethering with SOCKS proxy==
Line 136: Line 144:
 
With this method tethering is achieved by port forwarding from the phone to the PC. This is suitable only for browsing. For Firefox, you should set '''network.proxy.socks_remote_dns''' to '''true''' in '''about:config''' ( address bar )
 
With this method tethering is achieved by port forwarding from the phone to the PC. This is suitable only for browsing. For Firefox, you should set '''network.proxy.socks_remote_dns''' to '''true''' in '''about:config''' ( address bar )
  
===Tools Needed===
+
===Tools needed===
* [https://aur.archlinux.org/packages/android-sdk/ android-sdk], [https://aur.archlinux.org/packages/android-sdk-platform-tools/ android-sdk-platform-tools], and [https://aur.archlinux.org/packages/android-udev/ android-udev] packages from AUR
+
* The {{Pkg|android-tools}} and {{Pkg|android-udev}} packages
 
* USB connection cable from your phone to PC
 
* USB connection cable from your phone to PC
 
* Either [http://graha.ms/androidproxy/ Tetherbot] or [https://code.google.com/p/proxoid/ Proxoid]
 
* Either [http://graha.ms/androidproxy/ Tetherbot] or [https://code.google.com/p/proxoid/ Proxoid]

Latest revision as of 21:59, 12 May 2016

Tethering is a way to have internet access on your PC through your smartphone using its network connection. USB tethering and Wi-Fi access point tethering are natively supported since Android 2.2 "Froyo".

Wi-Fi access point

Using an Android phone as a Wi-Fi access point (to a 3G/4G mobile internet connection) is available for devices running Android 2.2 "Froyo" or newer.

Enable it in Settings -> Wireless & networks -> Internet tethering -> Wi-Fi access point

Note: On some phones, this method will discharge the battery rapidly and tends to cause intense heating, unlike USB.

USB tethering

USB tethering is available for devices running Android 2.2 "Froyo" or newer.

  • Disconnect your computer from any wireless or wired networks
  • Connect the phone to your computer using the USB cable (the USB connection mode -- Phone Portal, Memory Card or Charge only -- is not important, but please note that you will not be able to change the USB mode during tethering)
  • Enable the tethering option from your phone. This is usually done from Settings -> Wireless & networks -> Internet tethering (or Tethering & portable hotspot, for more recent versions)
  • Make sure that the USB interface is recognized by the system by using the following command:
$ ip link
You should be able to see a usb0 or enp?s??u? device listed like this (notice the enp0s20u3 device).
# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether ##:##:##:##:##:## brd ff:ff:ff:ff:ff:ff
3: wlp2s0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
    link/ether ##:##:##:##:##:## brd ff:ff:ff:ff:ff:ff
5: enp0s20u3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether ##:##:##:##:##:## brd ff:ff:ff:ff:ff:ff
Note: Take care to use the device name from your own system in the following commands.
Warning: The name may change depending on the usb port you use. You may want to change the device name to create a unique name for your device regardless of the usb port.
# dhcpcd enp0s20u3

Using systemd-networkd with udev

Using systemd-networkd you can automatically adjust the networking to use the phone as the gateway when plugged in.

/etc/udev/rules.d/90-android-tethering.rules
# Execute pairing program when appropriate
ACTION=="add|remove", SUBSYSTEM=="net", ATTR{idVendor}=="18d1" ENV{ID_USB_DRIVER}=="rndis_host", SYMLINK+="android", RUN+="/usr/bin/systemctl restart systemd-networkd.service"

You may have to adjust the idVendor attribute depending on your phone. You can check using udevadm:

$ udevadm info /sys/class/net/enp0s26u1u2

Then create the corresponding systemd-networkd file:

/etc/systemd/network/enp0s26u1u2.network
[Match]
Name=enp0s26u1u2

[Network]
DHCP=ipv4

USB tethering with AziLink

This method works for all known Android versions and requires neither root access nor modifications in the phone. It does not require changes to your browser. All network traffic is transparently handled (except ICMP pings). It may be somewhat CPU intensive on the phone at high usage rates (a 500 kBytes/sec data transfer rate may take more than 50% of phone CPU).

Tools needed

For Arch, you need to install the openvpn package. You will also need to install the android-tools package for the adb tool and android-udev which sets up the correct /usr/lib/udev/rules.d/51-android.rules file for your device to be recognized. On the phone, you need the azulink.apk (azilink homepage). The android application acts as a NAT, adb forwards the ports to your phone, and your openvnp setup will connect to it.

Configuring the phone connection in Arch Linux

So that you do not have to run adb with sudo, we are going to grant your user permissions to your usb device. Make sure you have turned on USB debugging on the phone (usually in Settings -> Applications -> Development -> USB debugging) so that it will be shown as a device, and that it is plugged in to your computer via the USB cable. You should see it with you run the lsusb command. Original azi link instructions are here

The device should be listed. Example output for the Acer Liquid phone:

Bus 001 Device 006: ID 0502:3202 Acer, Inc. 

Then, create the following file, replacing ciri by your own Linux user name, and 0502 by the vendor ID of your own phone:

/etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR(idVendor)=="0502", MODE="0666" OWNER="ciri"

As root run the sudo udevadm control --reload command to make the change effective. To make sure the change took effect, run 'adb devices' and it should say 'device' instead of 'unauthorized'. Another way to make it take effect is to reboot. Another test is to run adb shell to get to your phones unix prompt. The command should work without needing sudo.

Procedure

Run the AziLink application in the phone and select "About" at the bottom to receive instructions, which basically are:

  1. You will have to enable USB debugging on the phone if it was not already enabled (usually in Settings -> Applications -> Development -> USB debugging).
  2. Connect the phone with the USB cable to the PC.
  3. Run AziLink and make sure that the Service active option at the top is checked.
  4. Run the following commands in your Linux PC:
$ adb forward tcp:41927 tcp:41927
# sudo openvpn azilink.ovpn

azilink.ovpn source from here

azilink.ovpn
dev tun
remote 127.0.0.1 41927 tcp-client
ifconfig 192.168.56.2 192.168.56.1
route 0.0.0.0 128.0.0.0
route 128.0.0.0 128.0.0.0
socket-flags TCP_NODELAY
keepalive 10 30
dhcp-option DNS 192.168.56.1


You may need to manually update the contents of resolv.conf to

/etc/resolv.conf
nameserver 192.168.56.1

If you're running NetworkManager, you may need to stop it before running OpenVPN.

USB tethering with EasyTether

Get the easytether linux client software. The commands to set it up and run it are as follows.

# pacman -U easytether-0.8.5-2-x86_64.pkg.tar.xz
# easytether-usb
# dhcpcd tap-easytether

Make sure you have the EasyTether android app installed on your phone for it to connect to. Note: The Lite app disables some connections and you must have the paid app for full functionality. For this reason, using the AziLink setup is recommended instead.

Tethering via Bluetooth

Android (from at least 4.0 onwards, possibly earlier) can provide a Bluetooth personal-area network (PAN) in access point mode.

NetworkManager can perform this action and handle the network initialisation itself; consult its documentation for more details.

Alternatively: pair and ensure you can connect your computer and Android device, as described on Bluetooth, then, substituting the address of the device (here given as AA_BB_CC_DD_EE_FF), do:

$ dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_AA_BB_CC_DD_EE_FF org.bluez.Network1.Connect string:'nap'

This will create a network interface bnep0. Finally, configure a network connection on this interface; Android offers DHCP by default.

Tethering with SOCKS proxy

With this method tethering is achieved by port forwarding from the phone to the PC. This is suitable only for browsing. For Firefox, you should set network.proxy.socks_remote_dns to true in about:config ( address bar )

Tools needed

Instructions

Tetherbot

Follow the instructions under Using the Socks Proxy on [1].

Proxoid

Follow the instructions demonstrated in the following link