Post Reply

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

OP MrBlueEyez

2nd February 2010, 01:27 PM   |  #1  
MrBlueEyez's Avatar
OP Member
Flag Rotterdam
Thanks Meter: 0
 
67 posts
Join Date:Joined: Jul 2009
More
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
2nd February 2010, 01:33 PM   |  #2  
Senior Member
Thanks Meter: 4
 
605 posts
Join Date:Joined: May 2008
More
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?
2nd February 2010, 01:38 PM   |  #3  
MrBlueEyez's Avatar
OP Member
Flag Rotterdam
Thanks Meter: 0
 
67 posts
Join Date:Joined: Jul 2009
More
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..
2nd February 2010, 01:57 PM   |  #4  
olearyp's Avatar
Senior Member
Thanks Meter: 151
 
1,156 posts
Join Date:Joined: Sep 2009
More
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.
Last edited by olearyp; 2nd February 2010 at 02:00 PM.
2nd February 2010, 02:28 PM   |  #5  
cyanogen's Avatar
Retired Recognized Developer
Flag Seattle
Thanks Meter: 5,709
 
2,485 posts
Join Date:Joined: Jan 2009
Donate to Me
More
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.
2nd February 2010, 03:28 PM   |  #6  
MrBlueEyez's Avatar
OP Member
Flag Rotterdam
Thanks Meter: 0
 
67 posts
Join Date:Joined: Jul 2009
More
Quote:
Originally Posted by cyanogen

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...
Last edited by MrBlueEyez; 2nd February 2010 at 03:46 PM.
2nd February 2010, 03:45 PM   |  #7  
Member
Thanks Meter: 0
 
41 posts
Join Date:Joined: 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.
Last edited by zrubi; 2nd February 2010 at 03:53 PM.
2nd February 2010, 03:49 PM   |  #8  
MrBlueEyez's Avatar
OP Member
Flag Rotterdam
Thanks Meter: 0
 
67 posts
Join Date:Joined: Jul 2009
More
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]
Last edited by MrBlueEyez; 2nd February 2010 at 03:51 PM.
2nd February 2010, 03:56 PM   |  #9  
Account currently disabled
Thanks Meter: 96
 
2,645 posts
Join Date:Joined: 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.
2nd February 2010, 04:05 PM   |  #10  
Account currently disabled
Thanks Meter: 193
 
3,848 posts
Join Date:Joined: Feb 2009
Donate to Me
More
Quote:
Originally Posted by zrubi

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

Post Reply Subscribe to Thread

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

Advanced Search
Display Modes