5,595,000 Members 39,045 Now Online
XDA Developers Android and Mobile Development Forum

[Think Tank] Cache DNS Requests on Android to speedup browsing

Tip us?
 
MrBlueEyez
Old
#1  
MrBlueEyez's Avatar
Member - OP
Thanks Meter 0
Posts: 67
Join Date: Jul 2009
Location: Rotterdam
Default [Think Tank] Cache DNS Requests on Android to speedup browsing

I was wondering if there is a method to cache DNS requests? I use CM latest and was browsing around in the system folder, when i came by /system/etc/resolv.conf. Here you find the nameservers used by android to resolve DNS.

This got me thinking, because I use a DNS cache on my Ubuntu Box. Might there be a way to do this on Android, to speed up browsing regularly visited websites? Does anyone have any idea how to use a local DNS cache to speed up browsing?

Here's the deal:

- In /system/etc/resolv.conf you find 4 nameservers (4.2.2.5 - 4.2.2.2)
- Doing a ping test (count = 1000) to those, i find big differences in latency. Average was 800 on my test on 3G (I live in the Netherlands). I found this number rather large.
- On IRC, when asking this question, they mentioned porting dnsmasq to android and change nameserver to localhost

A ported version of dnsmasq is found here: http://code.google.com/p/android-wif...c=svn120&r=120

Copied the file to /system/bin, chmod +x the file, and this one works.

Now here's the thing:

- dnsmasq --help mentions a configurationfile: /data/local/dnsmasq.conf. This one have to be made for android
- how to configure dnsmasq so it uses the DNS servers and create a cache, thus speeding up browsing (in my humble belief)
- how to start dnsmasq on booting android (and making sure it stays alive)

And finally, does it make sense to use this kind of method? Like to apply for a think tank to make this work
Phone: Samsung Galaxy S Plus // Mod: BroodROM RC4 {edit}
 
the_fish
Old
#2  
Senior Member
Thanks Meter 4
Posts: 605
Join Date: May 2008
That does sound like a good idea. For me it isn't just 800ms to find out the DNS but on edge rather something like about 3 seconds! this would seriously speed the whole thing up! However, how are you gonna find the IP adresses for the first time?
Touch Dual - 16 key version (mda touch plus) Android 2.2
Universal - VPA IV Radio 1.08.00, Cotullas Q3 ROM
Dream - Black
Haykuro's SPL, latest Radio, CM7
Galaxy Nexus
Android Revolution latest
 
MrBlueEyez
Old
#3  
MrBlueEyez's Avatar
Member - OP
Thanks Meter 0
Posts: 67
Join Date: Jul 2009
Location: Rotterdam
Well dnsmasq creates a cache, using nameservers found in the config file, if i am correct. I am looking into the dnsmasq.conf examples to see what workaround i need.. Should be pretty straightforward

resolv.conf should have nameserver 127.0.0.1, and dnsmasq should use configured nameservers like 4.2.2.5 and create a cache. Therefore apps use the dnsmasq as DNS server.

Furthermore, i am trying to find out what nameservers are the fastest. 4.2.2.2-5 are Verizon, while i am in the Netherlands. OpenDNS has a datacenter in Amsterdam, so i figured changing nameservers to OpenDNS would speed things up some more..
Phone: Samsung Galaxy S Plus // Mod: BroodROM RC4 {edit}
 
olearyp
Old
(Last edited by olearyp; 2nd February 2010 at 02:00 PM.)
#4  
olearyp's Avatar
Senior Member
Thanks Meter 151
Posts: 1,155
Join Date: Sep 2009
Even better would be unbound, though the stated overhead of ~11 MB might be too much for G1/mT3G v1.

Also, do you have to do any tricks to prevent resolv.conf from being overwritten when you switch networks? I know that usually dhclient will rewrite the file, and there's a couple of workarounds, but I have no idea which ones would work on Android.
Patrick O'Leary
Reporting a bug in a ROM, MOD, or App?

LG Nexus 4/CM 10.1
Asus Nexus 7/CM 10
Old: mT3G+TheOfficial 2.14.x; HTC G2+Andromadus
 
cyanogen
Old
#5  
cyanogen's Avatar
Recognized Developer
Thanks Meter 5660
Posts: 2,485
Join Date: Jan 2009
Location: Seattle

 
DONATE TO ME
CM builds already have a dnsmasq binary in /system/bin. It's used for tethering. You could launch it with a different config file if needed (there's a dnsmasq.conf in /system/etc already for tethering). Also, the values in resolv.conf aren't really used by much anymore unless you have stuff linked with uclibc. The resolver in Bionic uses the values of the net.dns* system properties.
 
MrBlueEyez
Old
(Last edited by MrBlueEyez; 2nd February 2010 at 03:46 PM.)
#6  
MrBlueEyez's Avatar
Member - OP
Thanks Meter 0
Posts: 67
Join Date: Jul 2009
Location: Rotterdam
Quote:
Originally Posted by cyanogen View Post
CM builds already have a dnsmasq binary in /system/bin. It's used for tethering. You could launch it with a different config file if needed (there's a dnsmasq.conf in /system/etc already for tethering). Also, the values in resolv.conf aren't really used by much anymore unless you have stuff linked with uclibc. The resolver in Bionic uses the values of the net.dns* system properties.
Thanks for the reaction... You are right indeed, i found the dnsmasq.conf:
Code:
no-resolv
no-poll
server=4.2.2.2
server=4.2.2.3
interface=usb0
dhcp-authoritative 
dhcp-range=192.168.77.100,192.168.77.105,12h
dhcp-leasefile=/data/misc/dnsmasq.leases
pid-file=/data/misc/dnsmasq.pid
user=dhcp
no-negcache
What you're saying is that i should create another one, but i am wondering what values i should use..

interface=?

Also, regarding your remark on DNS, how to see the values of net.dns* and how to change them? sysctl -n doesn't show these values, I must be looking in the wrong direction...
Phone: Samsung Galaxy S Plus // Mod: BroodROM RC4 {edit}
 
zrubi
Old
(Last edited by zrubi; 2nd February 2010 at 03:53 PM.)
#7  
Member
Thanks Meter 0
Posts: 41
Join Date: Dec 2008
Hey,

You don't have to set an interface at all.
The interface delcaretion limit dnsmasq to listen only on a specific interface (for both DHCP and DNS requests).
As far as I know dnsmasq is caching dns by default you can limit the cache size and set not to cache negative queries but it will cache by default so no special settings is needed.

In addition, Dnsmasq is also function as dhcp server and if you don't want it to try removing all lines that declaring on dhcp settings.
 
MrBlueEyez
Old
(Last edited by MrBlueEyez; 2nd February 2010 at 03:51 PM.)
#8  
MrBlueEyez's Avatar
Member - OP
Thanks Meter 0
Posts: 67
Join Date: Jul 2009
Location: Rotterdam
True on that one, i want to use dnsmasq mainly on 3G

On my remark about the dns properties, already found out to use getprop and setprop

getprop shows different values on DNS compared to resolv.conf:

[net.dns1.195]: [84.241.226.140]
[net.dns2.195]: [84.241.226.9]
[net.dns1]: [84.241.226.140]
[net.dns2]: [84.241.226.9]
Phone: Samsung Galaxy S Plus // Mod: BroodROM RC4 {edit}
 
lbcoder
Old
#9  
Account currently disabled
Thanks Meter 92
Posts: 2,645
Join Date: Jan 2009
You need to be aware of one thing with regards to the resolv.conf file.
It is NOT USED BY ANDROID.

If you use the command "getprop", you will see several dns entries in there -- none of which matches the static dns servers set in resolv.conf. The resolv.conf is used by TERMINAL BINARIES.
 
Firerat
Old
#10  
Account currently disabled
Thanks Meter 193
Posts: 3,848
Join Date: Feb 2009

 
DONATE TO ME
Quote:
Originally Posted by zrubi View Post
Hey,

You don't have to set an interface at all.
The interface delcaretion limit dnsmasq to listen only on a specific interface (for both DHCP and DNS requests).
As far as I know dnsmasq is caching dns by default you can limit the cache size and set not to cache negative queries but it will cache by default so no special settings is needed.

In addition, Dnsmasq is also function as dhcp server and if you don't want it to try removing all lines that declaring on dhcp settings.
might as well restrict it to the local interface
Code:
interface=lo
you can then turn off dhcp with
Code:
no-dhcp-interface=lo

Tags
cache, dns, dnsmasq
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


TRENDING IN THEMER...