3

I'm running Ubuntu in the VMWare Player under Windows 7:

root@ubuntu:/# uname -a
Linux ubuntu 3.0.0-17-generic #30-Ubuntu SMP Thu Mar 8 17:34:21 UTC 2012 i686 \
i686 i386 GNU/Linux

I'm trying to establish a network connection to my HTC Desire via USB. After plugging it in the device shows up when typing the lsusb command:

root@ubuntu:/# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 003: ID 0bb4:0c87 High Tech Computer Corp. Desire (debug)

I can also talk to it via the Android Debug Bridge:

root@ubuntu:/# adb devices
List of devices attached 
HT08LPL00400    device

When I run ifconfig I expect the device to appear under usb0, but no USB interface shows up:

root@ubuntu:/# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0c:29:4f:5a:28  
          inet addr:192.168.159.145  Bcast:192.168.159.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe4f:5a28/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:251857 errors:1 dropped:1 overruns:0 frame:0
          TX packets:147151 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:340675522 (340.6 MB)  TX bytes:12163470 (12.1 MB)
          Interrupt:19 Base address:0x2000 

lo        Link encap:Local Loopback  
          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:15115 errors:0 dropped:0 overruns:0 frame:0
          TX packets:15115 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:5352740 (5.3 MB)  TX bytes:5352740 (5.3 MB)

Anyone knows what I can do? Thanks!

1 Answer 1

2

Adb works over USB, it doesn't set up a networking interface. ifconfig only shows networking interfaces.

If you want to run commands or copy files between Ubuntu and the Android phone, use the adb command:

adb shell ls /system
adb push myfile /data/data/myapp.example.com/

Some Android devices can appear as a USB storage device, I don't know if this includes yours. You may also try adbfs (not packaged for Ubuntu, as far as I know, so you'd need to compile it yourself).

If you want to establish a network connection, for example to use the Android phone as a gateway to the Internet (this is known as tethering), tell adb to establish a PPP connection over USB. The PPP interface will appear as a network interface in ifconfig. Here's a quick-and-dirty tethering script that tries to guess the right network interface on the Android device; run it as root and at your own risk (it wasn't design to be robust in weird setups).

# Interface with the default route on the Android device.
android_gw_if=$(adb shell ip route list 0.0.0.0/0 | sed -n -e 's/^.* dev  *\([^ ]*\).*/\1/p' -e 'T' -e 'q')
adb ppp "shell:pppd nodetach noauth noipdefault /dev/tty" nodetach noauth noipdefault notty 192.168.254.2:192.168.254.1
adb shell "echo 1 >/proc/sys/net/ipv4/ip_forward"
adb shell "iptables -P FORWARD ACCEPT"
adb shell "iptables -t nat -I POSTROUTING -s 192.168.254.2 -j MASQUERADE -o $android_gw_if"
sleep 1 # give the ppp connection time to establish itself
route add -net default gw 192.168.254.1
1
  • Thanks Gilles! I just want to receive UDP datagrams sent by the device to my host PC. On the device I'm sending the packages to the usb0 interface (IP 10.0.0.1). Now I don't know how to receive them without having USB on the host PC as network interface...
    – Mr. Omsn
    Apr 18, 2012 at 0:19

You must log in to answer this question.

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