Not able to get reverse tethering working in android via usb - android

I went through this tutorial http://blog.mathieu.carbou.me/post/60454997009/reverse-usb-tethering-with-android-2-2 to reverse tether my android phone to use PC internet via USB.
Using following commands I am successfully able to create bridge br0.
sudo ifconfig eth0 0.0.0.0
sudo ifconfig usb0 0.0.0.0
sudo brctl addbr br0
sudo brctl addif br0 eth0
sudo brctl addif br0 usb0
sudo ifconfig br0 up
sudo dhclient br0
br0 has ip address : 172.16.138.102
My android phone is showing rndis0. I used following command using adb shell as root.
netcfg rndis0 dhcp
rndis0 was assigned ip : 172.16.138.109/24
Then I added default gateway for rndis0 interface.
route add default gw 172.16.138.102 dev rndis0
Still internet was not working on android. I tried several other tutorials but same info was mentioned everywhere. Am I missing something or I need to do something more for running internet?

Try to use Reverse Tethering tool.
Its in beta version so Android Browser will not know that Internet is working but you can surf internet.

Use gnirehtet.
Note: After getting connected to gnirehtet server, just keep the data connection ON, although your data will not be used, only your PC internet will be used on android.

Related

Android 6.0.1 unable to resolve IP using DNS.

I've have an android 6.0.1 navigation system. The idea is to connect 4G/3G USB modem to have an internet on it constantly.
Found an article how to setup auto installation and configuration of USB modem.
basic idea is to call
pppd call conf-pppd
where conf-pppd
ttyUSB1
460800
defaultroute
noauth
noipdefault
user ""
password ""
connect "/system/bin/chat -f /etc/ppp/peers/conf-chat"
where conf-chat
is set of AT commands
TIMEOUT 3
ABORT 'BUSY'
ABORT 'ERROR'
ABORT '+CME ERROR:'
TIMEOUT 3
'' 'AT'
OK 'ATZ'
OK 'AT+CGDCONT=1,"IP","fp.com.attz"'
OK 'ATDT*99#'
CONNECT ''
After all problems it almost works, I mean modem connects to 4G network and I even can ping any IP from terminal.
But chrome says some DNS error though I've set
setprop net.dns1 8.8.8.8
setprop net.dns2 8.8.4.4
setprop net.ppp0.dns1 8.8.8.8
setprop net.ppp0.dns2 8.8.4.4
here is some android state info which I was able to gather:
DNS info
IP route info
ifconfig
Wasn't able to google anything useful, would appreciate any help, what to check or maybe where to post this question if it isn't appropriate forum.
Thanks.
Android 8.0
////////////////////////////////////////////////////////////
ifconfig usb0 192.168.225.3 netmask 255.255.255.0
ndc network create 9792
ndc network interface add 9792 usb0
ndc network route add 9792 usb0 0.0.0.0/0 192.168.225.1
ndc resolver setnetdns 9792 8.8.8.8 8.8.4.4
ndc network default set 9792
///////////////////////////////////////////////////////////

RPI3 PIXEL Jessie - usb0 interface

Greetings to everyone!
I have a project on RPI but I have 1 problem.
Project description: RPI (server, connected to LAN DHCP with internet access) + Android Tablet (connects on USB0 static interface on RPI via USB Tethering).
Android App: Made an android APP to connect to server and manage RPI as client via sockets and ajax requests.
Problem: I have made five examples of same thing with 5 tablets and 5 RPI-i and USB0 is being seen by LAN Router and the problem is that I want nobody from LAN (not even another tablet) can connect to USB0 but that tablet connected to RPI with USB Tethering. Now how 5 devices is connected to LAN sometimes happens that tablet from RPI1 connects via LAN to RPI2 beacuse USB0 can be seen on LAN.
I want that USB0 is not seen on LAN but can give internet to tablet via eth0.
Currently I'm giving USB0 internet like this:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE && sudo iptables -A FORWARD -i eth0 -o usb0 -m state --state RELATED,ESTABLISHED -j ACCEPT && sudo iptables -A FORWARD -i usb0 -o eth0 -j ACCEPT
I would really be glad if somebody could help me I'm not so good in configuring network interfaces
Check out this project. parts of it are probably quite useful for you.
https://github.com/samyk/poisontap/blob/master/pi_startup.sh

Reverse tethering of several Android devices via USB

I'm trying to setup a testing environment for my android app where the separate devices need an Internet connection, but don't have wireless capabilities.
So I decided on using usb reverse tethering. My host machine is running Ubuntu. I already managed to setup reverse tethering for one device, the connection is working and I can ping google.com from this device's adb shell.
When I connect a second device, the first tethering stops working.
Both devices have the same IP adress configured on their internal usb0 interface.
Here's what I have so far:
Port forwarding on host is activated
echo 1 > /proc/sys/net/ipv4/ip_forward
Iptables rule on host to route traffic:
iptables -t nat -A POSTROUTING -s 169.254.255.2/24 -j MASQUERADE
Plugin first device:
ifconfig shows the device on usb0 # ip 169.254.255.2/30
On first device (with adb shell)
> route add default gw 169.254.255.2 dev usb0
> setprop net.dns1 8.8.8.8
> ping google.com --> is giving results
Plugin second device
ifconfig shows this device on usb1 # ip 169.254.255.2/30
On second device
Add gw, set DNS like above
Now the second device can ping google.com, but the first one not.
When I change the internal IP or the IPs assigned to the hosts usb0, usb1 interfaces I am not able to connect to the devices via adb anymore.
I suspect this to be a networking problem, rather than a problem with ADB? Any Ideas?
After a lot of googling and trial and error I finally found the solution for my particular setup.
What I did in the end, and what I missed in my first attempts, was to put each connected usb device into a separate subnet (see this answer on serverfault).
To put it clearly, the setup is now like following:
iptables contains the following rule
iptables -t nat -A POSTROUTING -j MASQUERADE
the host's usb0 and usb1 interface, now in separate subnets
usb0: inet addr:169.254.0.1 Bcast:169.254.15.255 Mask:255.255.240.0
usb1: inet addr:169.254.16.1 Bcast:169.254.31.255 Mask:255.255.240.0
internal usb0 iface of Android device connected on host's usb0:
- usb0 169.254.0.2/20
- default gw 169.254.0.1 (so the host's usb0 iface)
internal usb0 iface of Android device connected on host's usb1:
- usb0 169.254.16.2/20
- default gw 169.254.16.1 (so the host's usb1 iface)
That way I now have Internet access (after adb shell setprop net.dns1 8.8.8.8) from each android device connected to the usb interfaces on my host.
You need a linux system with root access, rooted android phone and usb cable.
Steps
Install adb and fastboot in your linux system.
sudo apt-get install android-tools-adb android-tools-fastboot
Connect your android phone to your PC via USB and enable USB tethering from the settings on your phone.
Open terminal in your PC and type the commands given below.
Find out the new network interface that was created on your PC.
ifconfig
Generally the new network interface will be usb0 or usb1. Let us consider usb0.
Now make some static IP address for this new interface usb0.
sudo ifconfig usb0 10.42.0.1 netmask 255.255.255.0
Now make this new interface usb0 as shared connection.
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
Now make some changes iptables firewall.
sudo iptables -t nat -F
sudo iptables -t nat -A POSTROUTING -j MASQUERADE
Now we have to enter some commands in the android phone. We can use either adb or directly typing the commands in the android phone through a terminal emulator installed in the phone. I am using the adb way.
Find the network interface in the android phone.
adb shell busybox ifconfig
Mine was rndis0.
Set the static IP, netmask and gateway.
adb shell ifconfig rndis0 10.42.0.2 netmask 255.255.255.0
adb shell route add default gw 10.42.0.1 dev rndis0
Verify Internet connectivity on your phone.
adb shell ping 8.8.8.8
If it is pinging, then the Internet in your mobile is working.
This Internet connection will not work with the apps like opera mini and paytm, but works well with whatsapp.

Set IP Address for Android Emulator

I have a scenario where I need to start Android Emulator with a specific IP Address?
Can I start the emulator like that?
I do not want to do IP forwarding or other stuff, because there is an Android program running in the Emulator which on boot will configure itself with Android Emulators IP address present during boot time.
As by default the ip address of emulator is 10.0.2.15 which I need to change.
Also, this Ip is set in init.goldfish.rc and init.goldfish.sh.
If I change them, still the ip of android is 10.0.2.15.
I made work by this way:
In Android Emulator if you do ifconfig then you will see bridge, eth0 & eth1 as network devices. Where bridge has the 10.0.2.15 as ip and eth0 is up but without any ip and eth1 is down without any ip.
Now create a TAP and Bridge devices on you host machine and bridge your TAP device with any of the working ethernet cards on you host machine.
The TAP device (tap1) and bridging (br1) it with eth0 can be created following below steps:
$sudo ip tuntap add dev tap1 mode tap
$sudo ip link show dev tap1
$sudo brctl addbr br1
$sudo brctl addif br1 tap1
$sudo brctl addif br1 eth0
$sudo ip link set eth0 up
$sudo ip link set br1 up
$sudo brctl show
So now once your TAP is up and if your eth1 is connect to any dhcp server, start the dhcp server.
Once the dhcp server is started, run the emulator with below command:
$sudo ./emulator -avd <avd_name> -qemu -net nic,vlan=1 -net user,vlan=1,hostname=<hostname_you_want> -net nic,vlan=2,macaddr=<mac_id_of_eth1_of_android_emulator> -net tap,ifname=tap1,script=no,vlan=2
In your android emulator shell run below command:
$netcfg
You should be able to see eth1 down with ip 0.0.0.0, now run below command to bring up the eth1:
$netcfg eth1 dhcp
And voila!!! you have the eth1 with ip address assigned from dhcp server.
Let me know if it works!!!
Now if you have any program in android emulator opening port on external server ip address it would go through eth0 of host machine to the external server.

How to set up ADB for remote machine development and local device deployment

My scenario is this: I telework from home and log into my work machine via Windows Remote Desktop. I use Eclipse as my development environment for Android apps on my work computer.
Using ADB, I would like to be able to deploy apps from my work computer to a device on my home network, for scenarios where the emulator doesn't do the app justice.
I found this post, which discuss a very similar scenario, with the exception of deploying to an emulator running on a local PC, instead of deploying to a local device:
http://www.41post.com/5003/programming/android-adb-remote-emulator-access
I'm trying to take the same steps, but figure out how to target a local device on my home WiFi network & tethered to my local home PC, instead of the local emulator.
Right now, I have the remote PC set up to try and connect to my public router IP on port 5585 - but in my router, what IP/port do I forward this to to connect to the local device?
In the example using the emulator, they forward to the local PC address where the emulator is running and port 5555, and adb is not running on the local PC. I have configured my router to forward to my device IP, with the device on WiFi, as well as my local PC IP where the device is tethered.
However in both scenarios, when I try adb connect <routerIP>:5585 on my remote PC, it gives me an error unable to connect to <routerIP>:5585:5585. I get the same response when trying to forward to/listen to other ports. I'm not getting any security errors in the router log, so it appears the port forwarding is working.
Questions:
What local IP/port number should I forward to when configuring port forwarding on my local network to connect to the local device using the remote adb instance?
Should I be targeting the local PC IP that the device is tethered to, or the local device IP?
If I target the local device IP, what port number should I forward to?
Do I need adb running on my local PC?
I had a similar situation. I work on a remote desktop for development but my android device is connected to my local laptop. I wanted to be able to use adb and the android plugin in eclipse on the remote desktop and connect to the device attached to my laptop. After searching on the internet and not finding anything that really helped, I decided to write a port forwarder that would do the trick. You can find it here. I hope it will be helpful to other people as well.
Beginning Android 4.3 you can:
Make adb server listen on all interfaces. You have two options:
Make gListen=1 and recompile adb (I have compiled it on Linux-x64 machine for you and put it here)
Start adb server with -a parameter: adb -a -P 5037 fork-server server&
Use adb on your remote machine with extra parameter, e.g. adb -H <remote_host> shell
Another setup for remote host + local device testing. This will be useful for lots of people working from home on a laptop, connected to their development host machine still in the office. Note that I assume both devhost/laptop are both running Unix, but other OSes will be able to run the commands on the command prompt/shell.
# Kill old adb server.
devhost$ adb kill-server
# Activate adb server on client
laptop$ adb start-server
# Start ssh tunnel. Hide/minimize this window not to close it by accident
laptop$ ssh -XC -R 5037:localhost:5037 <your devhost machine>
# Should work by now with the local device connected to the laptop
devhost$ adb logcat
You can solve the issue by port forwarding.
Download Secure Shell app from the Chrome app store
Connect to your machine (step-by-step setup)
In this connection, disable adb server: adb kill-server
Create a new port forwarding connection (same as a regular connection, but set the SSH Arguments field to: -N -R 5037:localhost:5037)
On your laptop, open up a terminal and enable adb server: adb start-server
Probably there is a simpler solution, providing the device, the local and remote machine belong to the same network.
Let's say your device has a certain IP over the network and let's say you decide to use your preferred PORT: well, you can do the following steps.
On the machine where the device is plugged please run:
adb devices
adb tcpip <PORT>
Example of PORT is 5555.
On the remote machine you need to deactivate 'Discover USB devices', 'Discover network targets' and 'Port forwarding' and then run:
adb connect IP:PORT
*IP is your android device IP(not the first machine IP) which can get from adb shell ip -f inet addr
And you are ready to debug on remote machine.
This is how I made it work from host macOS with emulator to macOS client.
A: One line command
On host of emulator
socat tcp-l:5560 tcp:localhost:5559
On client
adb connect <IP>:5560
B: With a tunnel
on host
host$ adb kill-server
host$ adb -a nodaemon server
on client
client$ adb kill-server
client$ ssh -L 5037:localhost:5037 <host-IP>
open second shell on client
client$ adb kill-server # I observe first it kills client adb
client$ adb kill-server # then it kills server adb, do it maybe once more
client$ adb devices # show devices on server now
Now I see host emulator in Android Studio as well
My situation required using a VM that is on a different network, but that I rmd into (an Azure VM). The VM and my local laptop are both running Windows 10. First, I had to install USB Redirector RDP Edition on my local machine (costs $80, but there might be free alternatives), then install the Google Android USB driver on the VM and the Universal Adb Driver on the VM. I'm now able to load an Android Studio App the project in Android Studio on the VM, connect an Android device on my laptop, and debug the app on the device.

Categories

Resources