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
///////////////////////////////////////////////////////////
Related
I connected my android device(on a board) to internet through Ethernet cable but not able to browse anything on device.
Using adb shell, Ping to 8.8.8.8 is working but to www.google.com or other url is failing. Same through browser.
Can you please let me know how to solve this issue.
Try this:
For Lollipop:
ndc resolver setnetdns eth0 "" 8.8.8.8 8.8.4.4
For Kitkat:
ndc resolver setifdns eth0 "" 8.8.8.8 8.8.4.4
ndc resolver setdefaultif eth0
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.
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.
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.
I am trying to enable / disable the wifi device in my android device in a bash script. I am using the terminal emulator and the program Script Manager to execute bash scripts on the phone (which is a rooted Nexus One).
The normal way to do this in linux would be something like
ifconfig eth0 up
That gives me
"eth0: no such device"
Trying
iwconfig eth0
gives the same, and
iwconfig
gives a list of devices with no eth0 on it. Now if I turn on wifi (manually from the GUI) and type
iwconfig
it shows eth0 with a lot of info.
My question is: How can I use the command line to turn on / off wifi? And why is eth0 disappearing from the device list when wifi is disabled?
thanks.
While it doesn't work in my non-rooted phone for obvious reasons, the results I'm obtaining are completely different while wifi is connected:
$ ifconfig eth0
eth0: ip 192.168.0.102 mask 255.255.255.0 flags [up broadcast running multicast]
$ ifconfig eth0 up
error: SIOCSIFFLAGS (Permission denied)
If you just want to turn wifi on or off you should use:
# svc wifi enable
or
# svc wifi disable
to see the help message
# svc wifi
Control the Wi-Fi manager
usage: svc wifi [enable|disable]
Turn Wi-Fi on or off.
svc wifi prefer
Set Wi-Fi as the preferred data network