Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
Looks like a 12.10 bug, see here: ubuntuforums.org/showthread.php?t=2028250 – Daniel Mar 27 '13 at 11:11
    
@DanielPass, seems like you didn't understood the question, author is talking about opposite, tethering from computer. – Andrejs Cainikovs Mar 27 '13 at 12:10
3  

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.

share|improve this answer
    
link is broken and on a 15.10 not working either :-( – Philippe Gachoud Jan 14 at 13:45

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'"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.