How to change 3g dns setting on Android? - android

I want to change 3G dns setting on Android 2.1 device. I managed to install busybox on my device, i can also get dns information by using adb shell getprop | grep dns. The only problem is that it shows me net.pdp0.dns1 and net.pdp0.dns2, not net.rmnet0.dns1 and net.rmnet0.dns1 so i can't change the setting.
I know that net.rmnet0.dns1 is for 3G connection, so what about net.pdp0.dns1? How can i change to net.rmnet0.dns1?
Thanks

Android DSN file contains in following directory:
In android file system
system/etc/dhcpcd/dhcpcd-hooks/20-dns.conf
20-dns.conf file contains dns setting, you can modify this file by following way:
# Set net.<iface>.dnsN properties that contain the
# DNS server addresses given by the DHCP server.
set_dns_props()
{
case "${new_domain_name_servers}" in
"") return 0;;
esac
count=1
for i in 1 2 3 4; do
setprop dhcp.${interface}.dns${i} ""
done
count=1
for dnsaddr in ${new_domain_name_servers}; do
setprop dhcp.${interface}.dns${count} ${dnsaddr}
count=$(($count + 1))
done
setprop dhcp.eth0.dns1 8.8.8.8
setprop dhcp.eth0.dns2 8.8.8.4
}
unset_dns_props()
{
for i in 1 2 3 4; do
setprop dhcp.${interface}.dns${i} ""
done
}
case "${reason}" in
BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) set_dns_props;;
EXPIRE|FAIL|IPV4LL|RELEASE|STOP) unset_dns_props;;
esac
(Note:Please take backup of origin file , if you need origin file)
set your dns in following line
setprop dhcp.eth0.dns1 8.8.8.8
setprop dhcp.eth0.dns2 8.8.8.4

It may help if you state the kind of device you have. From what I've read online, Samsung devices use the pdp0 interface names (it may be that this is the way Samsung refers to the 3G connections). Personally I have been using all HTC devices and the 3G interface is always rmnet0.
Is your phone rooted? You may not be able to set properties in the "net" category without root permissions.
If you are root, have you tried "setprop net.pdp0.dns1 "? Also, does "adb shell getprop | grep dns" give you "net.dns1"? I believe this is the default way Android looks up DNS servers. You may want to set this property as well.
You can test if it is working by running nslookup, it will show you the server it is querying.
Good luck,
B-Rad

Related

How can I run additional commands after an alias in Powershell?

In my job, I work a lot with different android devices and interface with them using adb. Rather than remembering or needing to copy their serial numbers or IP addresses to refer to them, I've been trying to use aliases, but I'm running into issues. I'm currently using a combination of functions and profiles to refer to the devices. This is my current Profile.ps1 file:
function googletv_func ($params){
if ($params -eq "connect"){
adb connect 192.168.0.14
}
else{
adb -s 192.168.0.14 $params
}
}
function firehd_func ($params){
adb -s G0W1EW0 $params
}
Set-Alias googletv "googletv_func"
Set-Alias firehd "firehd_func"
If I enter the command "googletv connect", it will successfully connect to the google tv. But if I try something with more than one parameter following the alias (e.g. "googletv install example.apk" or "firehd shell pm list packages") it only executes the single parameter following the alias. Wondering what I'm missing and I appreciate anyone's help.

How to obtain the last factory reset time for an Android device?

I am developing a security related app and would like to know when was the device previously factory reset? Is there any way to obtain this information?
I tried getting the last modified time for many files using the adb shell but some show 1970/1971/current date which is not consistent or accurate.
adb shell "stat /cache | grep Modify"
I know you said you tried getting modification time for some files, but the specific one you need to query is /cache.
The /cache folder is wiped when you factory reset your phone.
The command you would use is adb shell "stat /cache | grep Modify". Which produces something like: Modify: 2016-01-27 15:57:38.000000000

Get device information (such as product, model) from adb command

One way to achieve this is as follows:
adb devices -l
example output:
123abc12 device product:<id> model:<id> device:<id>
456abc45 device product:<id> model:<id> device:<id>
But this list's out all devices connected, but I want to get the information for a specific device.I want information only about "123abc12". The output should be:
123abc12 device product:<id> model:<id> device:<id>
The second device should not be shown.
I have the device name i.e 123abc12, and it can be used to get the required information, but I don't know how.
Thanks.
The correct way to do it would be:
adb -s 123abc12 shell getprop
Which will give you a list of all available properties and their values. Once you know which property you want, you can give the name as an argument to getprop to access its value directly, like this:
adb -s 123abc12 shell getprop ro.product.model
The details in adb devices -l consist of the following three properties: ro.product.name, ro.product.model and ro.product.device.
Note that ADB shell ends lines with \r\n, which depending on your platform might or might not make it more difficult to access the exact value (e.g. instead of Nexus 7 you might get Nexus 7\r).
Why don't you try to grep the return of your command ?
Something like :
adb devices -l | grep 123abc12
It should return only the line you want to.

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

Is there a way to change android phone's mtu size?

My phone is having problem with sending data to the network. I think I have to change its MTU size to make it work.
To change MTU settings you need a to root your phone. Search in foruns how to do it.
After that your need to install a terminal emulator and check what is your network interface
Run the command:
netcfg
and look at the IP address what is your desired device (wlan0, tiwlan0, etc)
then use this command
ifconfig $DEVICE mtu $MTU_VALUE
and substitute $DEVICE with device name and the desired MTU value in $MTU_VALUE
You can also see the value at this file:
cat /sys/class/net/$DEVICE/mtu

Categories

Resources