Difference between revisions of "Android tethering"

From ArchWiki
Jump to navigation Jump to search
(→‎USB tethering: Improve formatting and wording, remove ifconfig)
Line 13: Line 13:
  
 
== USB tethering ==
 
== USB tethering ==
 
{{Out of date|{{Pkg|net-tools}} is deprecate, replace ''ifconfig'' with ''ip'' from {{Pkg|iproute2}}.}}
 
  
 
===Tools Needed===
 
===Tools Needed===
Line 21: Line 19:
  
 
=== Procedure ===
 
=== Procedure ===
*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)
+
* Enable USB Debugging. This is usually done from {{ic|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
+
* 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)
+
* 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)
+
* 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)
 
+
* Load the {{ic|usbnet}} module (if it's not already loaded). You will need root access to do that<!--
'''(The following step may not be needed. usbnet module may not be necessary, do it only if you do not see a usb0 or enp?s??u? interface in the ifconfig step)'''
+
--> <p>'''(This step may not be needed. usbnet module may not be necessary, do it only if you do not see a usb0 or enp?s??u? interface in the {{ic|ip link}} step)'''</p><!--
*Load the usbnet module(if it's not already loaded). You will need root access to do that
+
-->{{bc|# modprobe usbnet}}
# modprobe usbnet
+
* Make sure that the USB interface is recognized by the system by using the following command:<!--
 
+
--> {{bc|$ ip link}}<!--
*Make sure that the USB interface is recognized by the system by using the following command:
+
--><p>you should be able to see a usb0 or enp?s??u?-device listed like this (notice the enp0s20u3 device).</p>
$ ip link
 
 
 
you should be able to see a usb0 or enp?s??u?-device listed like this (notice the enp0s20u3 device).  
 
 
{{hc|# ip link|
 
{{hc|# ip link|
 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default  
 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default  
Line 43: Line 38:
 
5: enp0s20u3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
 
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
 
     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.}}
 
{{Note|Take care to use the device name from your own system in the following commands.}}
  
*To configure the new network device using the iproute toolkit, issue the following as root:
+
{{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.}}
# ip link set enp0s20u3 up && dhcpcd enp0s20u3
 
  
*To stop the network sharing, issue the command:
+
 
# dhcpcd -x enp0s20u3
+
* To configure the new network device using the iproute toolkit, issue the following as root:<!--
 +
--> {{bc|# ip link set enp0s20u3 up && dhcpcd enp0s20u3}}
 +
* To stop the network sharing, issue the command:<!--
 +
--> {{bc|# dhcpcd -x enp0s20u3}}
  
 
=== netctl ===
 
=== netctl ===
Line 65: Line 62:
  
 
=== dhcpcd ===
 
=== dhcpcd ===
Without using netctl or any other tool, just connect the phone, turn on USB tethering, and just run #dhcpcd.
+
 
 +
{{ic|dhcpcd}} can automatically detect unconfigured network interfaces and start a connection with them.
 +
 
 +
Just connect the phone, turn on USB tethering, and run
 +
{{bc|# dhcpcd}}
 +
 
 +
{{Note|This command will try to connect all network interfaces which have a cable connected and have no ip.}}
 +
 
 +
To disconnect, run
 +
{{bc|# dhcpcd -x}}
  
 
==USB tethering with OpenVPN==
 
==USB tethering with OpenVPN==

Revision as of 22:54, 12 February 2014

What is Tethering

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). In older versions of the Android OS, most unofficial ROMs have this option enabled.

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. See : menu/wireless & networks/Internet tethering/Wi-Fi access point

USB tethering

Tools Needed

  • 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

  • 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)
  • Load the usbnet module (if it's not already loaded). You will need root access to do that

    (This step may not be needed. usbnet module may not be necessary, do it only if you do not see a usb0 or enp?s??u? interface in the ip link step)

    # modprobe usbnet
  • 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.


  • To configure the new network device using the iproute toolkit, issue the following as root:
    # ip link set enp0s20u3 up && dhcpcd enp0s20u3
  • To stop the network sharing, issue the command:
    # dhcpcd -x enp0s20u3

netctl

To use netctl to configure USB tethering, just add a static ethernet configuration like:

/etc/netctl/usb-tether
Description='A basic dhcp Android tethering'
Interface=enp0s20u3
Connection=ethernet
IP=dhcp

dhcpcd

dhcpcd can automatically detect unconfigured network interfaces and start a connection with them.

Just connect the phone, turn on USB tethering, and run

# dhcpcd
Note: This command will try to connect all network interfaces which have a cable connected and have no ip.

To disconnect, run

# dhcpcd -x

USB tethering with OpenVPN

This method works for any old Android version and requires neither root access nor modifications in the phone (it is also suitable for Android 2.2 and later, but no longer required).

It does not require changes to your browser. In fact, all network traffic is transparently handled for any PC application (except ICMP pings). It is 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 on a powerful Acer Liquid).

Tools Needed

For Arch, you need to install the openvpn package. It is also required to have the Android SDK installed (which can be obtained here or from the AUR). On the phone, you need the azilink application, which is a Java-based NAT that will communicate with OpenVPN on your computer.

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 lsusb command. 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 udevadm control restart command (or reboot your computer) to make the change effective. 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

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:
    1. As plain user: adb forward tcp:41927 tcp:41927 (requires Android SDK installed)
    2. As root: openvpn AziLink.ovpn
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 

Troubleshooting

DNS

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

/etc/resolv.conf
nameserver 192.168.56.1

NetworkManager

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

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