[Android General] anserinae:
this has been tested on ICS. You will need Terminal Emulator with root privileges. you may not have to use (or have different) full path to the binaries but they are shown when used as part of a file eg. "/system/bin/".

Android

Settings -> More... -> Tethering & portable hotspot -> USB tethering

this will bring up the usb network device with an automatically assigned IP address on both the host and client ie. PC and phone.

Linux

$ sudo su
# echo 1 > /proc/sys/net/ipv4/ip_forward
# exit
$ ifconfig
[b]usb0[/b] Link encap:Ethernet HWaddr 1e:98:35:16:12:cd
inet addr:[b]192.168.42.170[/b] Bcast:192.168.42.255 Mask:255.255.255.0
inet6 addr: fe80::1c98:35ff:fe16:12cd/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:537 errors:0 dropped:0 overruns:0 frame:0
TX packets:671 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:55661 (55.6 KB) TX bytes:346260 (346.2 KB)

look for device usbX where X is the connected device number. e. if there is only one tethered device connected it would most likely be usb0.

grab the PC usbX devices IP prefixed with "inet addr:". in this example the address is 192.168.42.170.

if you do not see a usbX network device, you will have to setup RNDIS, which is outside the scope of this example howto.

Android

Apps -> Terminal Emulator

open terminal emulator.

$ su
# route add default gw [b]192.168.42.170[/b] dev usb0
# exit
$ exit

NB, substitute with the PC IP address you obtained earlier.

with these steps completed, the phone will send outgoing packets to the PC address then the PC will forward packets to its default gw (gateway).

my router at work (where i use this) is already forwarding for the example network class above so i do not have to go any further than this.

google play appears to work but downloading does not seem to actually happen. i tried leaving mobile data enabled with this method and it did not work, others may have success. i obviously do not have a wifi AP to connect to, so it still might be possible to connect to an AP and use this method to enable download in google play (but that seems a bit redundant if you are able to connect via wifi in the first place).

at this point try the browser and attempt to load any site. if it does not work then continue on with the remaining steps; you can either bridge the usbX and ethX device (or whatever your LAN device is), change the IP (on both PC and phone) of usbX to the same network class (as your LAN) or have the PC network translate on behalf of the phone (untested as i dont need it). below is an example of NAT (network address translation) for linux; for bridging or changing the IP addresses please use google for a howto.

Linux

$ vi nat_ethX.sh

use an editor and paste the follow code below into the script or type the three lines below manually (ignoring the first line).

#!/bin/sh
/sbin/iptables -F --table nat
/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables --table nat -A POSTROUTING -o eth0 -j MASQUERADE

replace eth0 with the actual PC ethX network device name relevant to your LAN setup.

$ chmod 744 nat_ethX.sh
$ sudo ./nat_ethX.sh

change the permissions of the file and run it.

again this is untested, but your PC should now be sending packets from its own IP address on behalf of the phone which your router is already accepting.

iptables -F --table nat

to remove the NAT iptables rules

Wi-Fi Hotspot

Settings -> More... -> Tethering & portable hotspot -> Portable Wi-Fi hotspot

this will bring up the wifi network device with a static IP on the host and an automatically assigned IP address on the client ie. first phone and second phone (in this example).

on the second phone, connect to the newly created AP from the first phone.

as wifi is enabled on the second phone google play will actually download. you do not need to setup anything else on the second phone.

Android (first phone)

Apps -> Terminal Emulator

open terminal emulator.

$ su
# route add default gw [b]192.168.42.170[/b] dev usb0

if you enable the wifi hotspot on the first phone, you must once again reset the default gw in the route table.

$ su
# echo 1 > /proc/sys/net/ipv4/ip_forward

IP forwarding should have been automatically set when enabling the wifi hotspot feature. you should not have to do this step, it should not break anything if you do.

#!/system/bin/sh
/system/bin/iptables -F --table nat
/system/bin/iptables -P FORWARD ACCEPT
/system/bin/iptables --table nat -A POSTROUTING -o usb0 -j MASQUERADE

again you can probably route another way, but here i am using NAT once more as in my case, the wifi hotspot / AP device wl0.1 is set to another network class (192.168.43.0) from that of usb0 (192.168.42.0). like the example above, you can place this in a file and run it, or type the three lines manually (ignoring the first line).

iptables -F --table nat

to remove the NAT iptables rules

Terminal Emulator (extra info.)

$ ifconfig
$ iwconfig

you can check the wifi hotspot network device name and information, in my case it is wl0.1. use google for more information on these commands.

$ ip route show

is another way to see the route table, if the default route command does not print the table with the ROM you are using.