As an alternate method (which does the same as the Perl script shown here, but without the need of Perl), you can use what's suggested here, which I'll transcribe below (with some modifications I made):
First, install bind9, since it'll avoid problems with DNS forwarding.
sudo apt-get install bind9
Add a POSTROUTING rule to iptables:
sudo iptables -A POSTROUTING -t nat -j MASQUERADE
Allow packet forwarding:
echo 1 | sudo tee -a /proc/sys/net/ipv4/ip_forward
Now plug in your phone and select 'internet pass through'.
Wait for the device to appear in ifconfig
.
Check it is also in arp
.
I found I had to unplug the device then plug it in again for it to appear in arp
, things don't work properly if arp
doesn't show the device.
The device will then sit waiting for HTC Sync to send it a message, so you have to mock HTC Syncs message:
#change this line to be more specific if you have more than one usb network device
phone_usb_device="usb"
get_ip ()
{
arp -n | grep $phone_usb_device | awk '{print $1}'
}
#TODO: This needs a timeout and loop needs cleaning up, but works fine and borrowed from another post.
echo "waiting for IP on computer usb"
while [[ `get_ip` < 192 ]];do sleep 2; done
phoneip=`get_ip`
echo "IP adress is $phoneip "
echo -n -e "\x00\x02\x00\x00" | nc -q 2 $phoneip 6000 > /dev/null
The latter part could be turned into a D-Bus script.
If you just want to test the Internet Pass Through feature, you can use the very last line only, for all the phone needs is that binary sequence on port 6000.
Hope that helps.