1

I have an Ubuntu 12.10 system on my PC and an Android 4.1 system on my Galaxy Nexus. Now I would like to share the Internet connection of my PC via USB with my Phone. I have been searching with Google a lot, but I only found answers how you can share the Internet connection of the Phone with the PC, but I want it the other way around.

2

3 Answers 3

0

This is not possible. But if you have a rooted Android, there is a trick, it's called Reverse USB tethering. Check out this article, author did that on Fedora, but I guess there should be no problems achieving the same on Ubuntu.

1
  • link is broken and on a 15.10 not working either :-( Jan 14, 2016 at 13:45
0

A working solution for me on Kubuntu 15.10 & Android 4.2.2 was following

Requirements

Android

  1. busybox app installed
  2. USB cable to your computer
  3. USB Debugging enabled on your android device (to be able to adb from your pc)

Computer

  1. In your /etc/network/interfaces you need to have these two lines otherwise you'll get a no such device error

    allow-hotplug usb0
    auto usb0
    
  2. adb installed (apt-get install android-tools-adb)

Connection

  1. In your android, enable the Settings->Connections->Network connections->Tethering and portable hotspot->USB tethering option, this will create an USB connection to your computer which you can see with ifconfig command on your computer. Look @ the interface name which for me is enxf6759e7fbebd this time.

    enxf6759e7fbebd Link encap:Ethernet  HWaddr a2:61:3c:83:1c:38  
        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
        RX packets:6 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:464 (464.0 B)  TX bytes:0 (0.0 B)
    
    eth0      Link encap:Ethernet  HWaddr 50:e5:49:47:f4:fd  
        inet addr:192.168.178.20  Bcast:192.168.178.255  Mask:255.255.255.0
        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
        RX packets:40894966 errors:0 dropped:0 overruns:0 frame:0
        TX packets:86312833 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:1000 
        RX bytes:20969506400 (20.9 GB)  TX bytes:120329513606 (120.3 GB)
    
    lo        Link encap:Local Loopback  
        inet addr:127.0.0.1  Mask:255.0.0.0
        UP LOOPBACK RUNNING  MTU:65536  Metric:1
        RX packets:30521 errors:0 dropped:0 overruns:0 frame:0
        TX packets:30521 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:0 
        RX bytes:10868749 (10.8 MB)  TX bytes:10868749 (10.8 MB)
    
  2. Assign an IP address to your computer on this network interface with following command sudo ifconfig enxf6759e7fbebd 192.168.42.135 netmask 255.255.255.0 where enxf6759e7fbebd is the interface you got on previous step.

  3. Enable IP forwaring with

    sudo -- sh -c  'echo 1 > /proc/sys/net/ipv4/ip_forward'
    
  4. Enable nat on your computer with

    sudo iptables -t nat -F
    sudo iptables -t nat -A POSTROUTING -j MASQUERADE
    
  5. On your computer connect to your android device with

    adb shell
    su
    
  6. then already having your connection you can check with busybox ifconfig -a command

    rndis0    Link encap:Ethernet  HWaddr FA:08:D6:1A:35:90  
        inet addr:192.168.42.129  Bcast:192.168.42.255  Mask:255.255.255.0
        inet6 addr: fe80::f808:d6ff:fe1a:3590/64 Scope:Link
        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
        RX packets:0 errors:0 dropped:0 overruns:0 frame:0
        TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:1000 
        RX bytes:0 (0.0 B)  TX bytes:564 (564.0 B)
    

you can add default route to your computers network address you fixed in point 2 with busybox route add default gw 192.168.42.135 dev rndis0 and that's it (you can check your routes with busybox route command)

Script

I did a script that I run after enabling the USB Tethering option (point 1 above) that does the work for me

#!/bin/bash
interfaceName=$(ifconfig|grep enx|awk '{print $1}') #Getting interface name
sudo ifconfig $interfaceName 192.168.42.135 netmask 255.255.255.0 # setting Computer IP Address
sudo -- sh -c  'echo 1 > /proc/sys/net/ipv4/ip_forward' # Enabling IP Forwarding 
sudo iptables -t nat -F
sudo iptables -t nat -A POSTROUTING -j MASQUERADE
adb shell "su -c 'busybox route add default gw 192.168.42.135 dev rndis0'"
0

I have found a great tool https://github.com/vvviperrr/SimpleRT. It is quite simple to use and does not require root permissions on your phone.

I tested SimpleRT using Sony Z3 Compact and Ubuntu 16.10 installed on laptop.

The steps are following:

  1. Install APK provided on SimpleRT
  2. Clone SimpleRT Git repo, or just chose "Download ZIP"
  3. Find your active Internet interface using terminal:
    route | grep '^default' | grep -o '[^ ]*$'
    
  4. Replace in simple-rt-cli/iface_up.sh LOCAL_INTERFACE value from command above.
  5. Type "make" in simple-rt-cli directory.
  6. Run terminal as root and start CLI:
    ./simple-rt
    
  7. Connect your phone using USB cable

Issues (taken from the official page): Some apps do not recognize the reverse tethered internet connection due to ConnectivityManager policy. Just leave WiFi or 3g connection active, connection will go through SimpleRT anyway.

1
  • Could you explain installation and usage in your answer, please?
    – Zanna
    Feb 20, 2017 at 19:29

Not the answer you're looking for? Browse other questions tagged .