why the gateway to be bogon? - android

I connect my Android phone with my PC through USB. And open the usb tether option on the phone.
So, there is a new remote NDIS network adapter displayed in the PC's network connections, and there is a rnndis0 IFface on the android.
I do the following configurations:
PC: ip: 192.168.42.1 netmask: 255.255.255.0
Phone: ip 192.168.42.2 netmask: 255.255.255.0
And when ping each other, both work ok.
But when I configure the default gateway of my phone to be the address of the PC, it failed.
busybox route add default gw 192.168.42.1
busybox route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default bogon 0.0.0.0 UG 0 0 0 rndis0
192.168.42.0 * 255.255.255.0 U 0 0 0 rndis0
can anyone tell me the reason?

I believe it's marked as bogon as it is an address which should not appear in a routing table, ie a bogon route.
This is because it is a private network address. It's only a warning though.
see http://packetlife.net/blog/2009/jan/21/whats-bogon/

What is the output of
$ ip route
on Android?
SivlerZhao
Yesterday, I was unable to reproduce the problem.
Now, it reproduced.
busybox route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default bogon 0.0.0.0 UG 0 0 0 rndis0
192.168.137.0 * 255.255.255.0 U 0 0 0 rndis0
And the output of ip route is:
busybox ip route
default via 192.168.137.1 dev rndis0
192.168.137.0/24 dev rndis0 src 192.168.137.2
Actually, it works ok, but the "bogon" word apears

Related

Server(AndroidWebServer) not reachable from pc

I have created AndroidWebServer on my android phone.
When I try to access 192.168.1.150:8000 (phone address) I have good response from the server. But when I try to access the same url from the pc (connected via WiFi on the same network) nothing happens.
When the server is active if I run this
adb shell netstat -at
tcp 0 0 ::ffff:127.0.0.1:8000 :::* LISTEN
That is weird because other services got foreign address
tcp 0 0 ::ffff:192.168.1.150:54 ::ffff:173.194.76.188:5 ESTABLISHED
tcp 0 0 ::ffff:192.168.1.150:36 ::ffff:31.13.92.33:http ESTABLISHED
for my service the foring address is :::*
I am not sure what I do wrong
https://github.com/lopspower/AndroidWebServer
AndroidWebServer androidWebServer = new AndroidWebServer(8000);
androidWebServer.start();
What should I change in order my phone to be accessible from my pc connected to the same WiFi network?
Thanks
Looks like your server is listening on localhost. That means it will only accept connections that originate on the local machine. Try listening on 0.0.0.0 instead; that means you accept connections from all origins.
EDIT
Change this line:
AndroidWebServer androidWebServer = new AndroidWebServer("0.0.0.0", 8000);

How to get the default interface and its inet address?

"Default interface" refers to ppp0:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 ppp0
0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 wlp3s0
172.30.0.1 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 wlp3s0
Which one is used by default when I access WAN instead of LAN.
I need to run it on Android,so I can't use getifaddrs,because ifaddrs.h is NOT in the Android NDK.
Uhh, I don't know if an interface can be marked as "default", but there are plenty way to retrieve interface list without getifaddrs.
You can execute "ip link show" command and parse the result (or "ifconfig").
you can go to "/sys/class/net" where each directory reprensent an interface (and there is file under those directory that can help you).
I don't know if Android work like Debian, and I recommand you to find a way through Android NDK or system command (like "ip" or "ifconfig") because directory like /net or /proc are subject to change between different OS version (even if it's not really common, I can't recall to have see that).

Set static ip to ethernet in android

I have ethernet connected to my android board.
I want to manually set IP from code. I was able to set IP address for WIFI.
I have looked into following links for ethernet
Assign static IP to ethernet card from OTG
So far I have not found how to set static IP to ethernet via android code.
You may need to create /data/misc/ethernet/ipconfig.txt file to configure static IP address.
As you successfully configured static IP address for WiFi already,
I think /data/misc/wifi/ipconfig.txt was also created and it will be valid for Ethernet config, too.
Please refer to following links for file path and data format.
EthernetConfigStore.java
IpConfigStore.java
I was able to set Ip to Ethernet connection as follows.
I was using Allwinner A31s android board.
String command1 = "su -c ifconfig eth0 "
+ terminalIpAddressString+" netmask "
+ subnetMaskAddressString
+" up";
String command2 = "route add default gw "
+ gatewayAddressString+" dev eth0";
String command3 = "mount -o remount,rw /system";
String command4 = "echo \"su -c ifconfig eth0 "
+terminalIpAddressString+" netmask "
+subnetMaskAddressString+" up;" +
"route add default gw "
+gatewayAddressString
+" dev eth0\" > /system/bin/preinstall.sh";
String command5 = "busybox sed -i 's/su -c ifconfig eth0 "
+terminalIpAddressString
+" netmask "+subnetMaskAddressString+" up;"
+"route add default gw 172.19.10.2 dev eth0"
+ "/su -c ifconfig eth0 "+terminalIpAddressString
+" netmask "+subnetMaskAddressString+" up;"
+"route add default gw "+gatewayAddressString
+" dev eth0/g' /system/bin/preinstall.sh";
The steps will vary with different versions of android.
Go to Settings, click on Connections then WiFi.
Tap and hold on the network you wish to adjust and click Manage Network Settings.
Mark the Show Advanced Options check box.
Click on the bottom checkbox to show advanced options
Under IP Settings, change it from DHCP to Static.
Change DHCP to Static
When using static IP addresses on home and other private networks, they should be chosen from within the standard private IP address ranges listed:
10.0.0.0 through 10.255.255.255
172.16.0.0 through 172.31.255.255
192.168.0.0 through 192.168.255.255
Now enter the IP address. This step is specific to each network. Ex: 192.168.1.128
The Gateway should fill in automatically based on the IP address. If not, copy the IP address and replace the last number with a 1. (Based on previous example: 192.168.1.1)
Tap Save and let the network reconnect.
If you intend to convert a wifi connection to ethernet or vice-versa check this.

Android VpnService. Why does all traffic go through the TUN device?

I created a TUN device using VpnService. Why does the TUN interface have the highest priority among other network interfaces of my device?
Update #1
This is how I configured the TUN device:
mInterface = new Builder().setSession(getString(R.string.app_name))
.addAddress("10.0.1.1", 24)
.addRoute("0.0.0.0", 1)
.addRoute("128.0.0.0", 1)
.establish();
Update #2
This is the output of route -n without the TUN device:
shell#m0:/ $ busybox route -n
busybox route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.197.55.0 0.0.0.0 255.255.255.0 U 0 0 0 rmnet0
This is the output of route -n with the TUN device:
shell#m0:/ $ busybox route -n
busybox route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 tun0
10.197.55.0 0.0.0.0 255.255.255.0 U 0 0 0 rmnet0
shell#m0:/ $
If VpnService is enabled on Android, it does not mean that all traffic goes through VpnTunnel. This depends on IP route and allow/disable application proxy settings.
mInterface = new Builder().setSession(getString(R.string.app_name))
.addAddress("10.0.1.1", 24)
.addRoute("0.0.0.0", 1)
.addRoute("128.0.0.0", 1)
.establish();
The above code is obviously global routing, equivalent to 0.0.0.0/0, as you probably know from OpenVPN settings.
If the default gateway is tun, all IP traffic passes through the tun device.
In this case, if you don't want a socket traffic to pass through tun, you need to call VpnService::p rotect function for socket-fd to protect fd.
But that's not enough, you'll also need to find a valid network (not a VPN), call its Network::bindSocket function, and have a Socket go over that network and out.
If you don't want to protect the socket with the Network::bindSocket function! Then you can set the default network, but it is only valid for the android-process of opening the VPN service.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
try {
ConnectivityManager cm = PppVpnNetworkListener.getConnectivityManager(this._service);
if (cm != null) {
cm.bindProcessToNetwork(network);
}
} catch (Throwable ignored) {
}
}
try {
ConnectivityManager.setProcessDefaultNetwork(network);
} catch (Throwable ignored) {
}

How to know the MTU size of Android Smartphone

Any command to know the MTU size of Android?
You should use the NetworkInterface class to query and obtain the network interfaces, then call getMTU().
Today, looking into the code of netcfg I saw that the configuration of the interfaces is located into /sys/class/net.. and then I thought of you! (I read your question yesterday)
If you have root access, open a terminal and run
cat /sys/class/net/<interface>/mtu
Methods to know the MTU size of Android:
from terminal: ifconfig $DEVICE | egrep addr\|MTU
through Android Debug Bridge (adb):
adb shell netcfg | grep UP to find the desired address and
adb shell ip addr show rmnet0 in case of rmnet0 or
adb shell cat /sys/class/net/rmnet0/mtu in case of rmnet0 (as described by #patedit)
Without ROOTING your phone, you may use a ping command from a Windows/Mac/Unix system. Though, the syntax of ping-options is very different for different OS.
For Windows
try this:
ping /l 1473 /f 10.68.34.75
/l <Size> — Specifies the length, in bytes, of the Data field in the echo Request messages sent. The default is 32.
/f — Specifies that echo Request messages are sent with the Do not Fragment flag in the IP header set to 1 (available on IPv4 only).
Adjust the payload using the -l command-line option. When you reach the higher limit, you will see this message and you will find the MTU size :
> The packet needs to be fragmented but DF set.
More details: https://kb.netgear.com/19863/Ping-Test-to-determine-Optimal-MTU-Size-on-Router
1480, I believe, but you can check by using ifconfig $DEVICE with a rooted device, and checking the MTU there.
For most network access, MTU could be resolved by MTU Discovery. You can use Ping command with different payload size and don't fragment to find aChrysler value. Good luck
Without ROOTING your phone, you may use a ping command from a Windows/Mac/Unix system. Though, the syntax of ping-options is very different for different OS.
From most Unix/Linux/Mac systems (Without ROOTING the phone)
You might share the internet connection from your phone, and then from any PC connected to your android-phone run ping commands:
ping www.yahoo.com -s 1413 -M do
man ping says:
-s <packetsize> — Specifies the number of data bytes to be sent. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data.
-M <pmtudisc_opt> — Select Path MTU Discovery strategy. <pmtudisc_option> may be either do (prohibit fragmentation, even local one), want (do PMTU discovery, fragment locally when packet size is large), or dont (do not set DF flag).
Adjust the payload using the -s command-line option (for example: 1200, 1300, 1400, 1500, 1450, 1425, 1440, ...). When you reach the higher limit, you will see a message like this and you will find the MTU size :
> From 192.168.1.1 icmp_seq=1 Frag needed and DF set (mtu = 1500)
ping: local error: Message too long, mtu=1500
My answer is based on this one for windows: answer #25165641

Categories

Resources