Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,740,298 Members 43,009 Now Online
XDA Developers Android and Mobile Development Forum

[APP][2.3.5+] DnsQache: Custom DNS settings (optional cache) & HTTP(S) Proxy 0.84

Tip us?
 
tdhite
Old
(Last edited by tdhite; 31st May 2014 at 12:04 AM.) Reason: version bump in title
#1  
Senior Member - OP
Thanks Meter 1932
Posts: 987
Join Date: Dec 2012
Location: DFW

 
DONATE TO ME
Default [APP][2.3.5+] DnsQache: Custom DNS settings (optional cache) & HTTP(S) Proxy 0.84

* DnsQache DNS and HTTP/HTTPS Proxy for Tether Root Users
--------------------------

DNS and HTTP/HTTPS Proxy caching for Tether Root Users
Download links are below in the second post, which will be kept up to date and includes the legal necessities with distributing an application.

Recent Updates -- see Changelog post below (third post).

** Source Code **
The sources for the application are available on GitHub -- feel free to fork it and send pull requests as you see fit.

Trying to figure out what to set for the maximum DNS cache size?
I think a nice rule of thumb is try 200 or 300 on JB and above, see how that works for you. On older Android (less than Jelly Bean), give it some room, like 1000, and see how that works, tune if necessary. The cache data is not all that much, so you're not stealing all that much RAM. Read more about that in this post if you're interested.

FIRST AND FOREMOST NOTICE:

*** Use this application at your own risk. It is possible that use of this program may violate your carrier's Terms of Use/Terms of Service. Read the DISCLAIMER file before committing to the use of this application.***


Second, the author of this program would like to thank Harry Mue and Sofia Lemons for the fantastic Android Wifi Tether application for its use in both using that application and and in learning Android. Some of the code in DnsQache borrow from ideas and indeed implementation from Harry's and Sofia's code base, therefore this body of code carries his license and Copyright (duly noted in the DISCLAIMER.txt and the code, where appropriate).

** Application State **
This application is in Beta stage at this time. Under testing, it has no currently known bugs, but they always are a possibility. Surely requests for user interface upgrades (say, maybe an actual icon that isn't a generic droid icon?) and other such requests, which will get serious consideration and updates as fast as reasonable without harming stability.

If, after installing, you don't know what "allowed CIDRs" is, please read this post.


** PREREQUISITES **

1) A rooted Android phone with busybox -- you should know how to, and have already, rooted your phone and get busybox operational on the same phone;

2) Your phone's kernel must be netfilter-enabled (most stock kernels support netfilter (IPTABLES), but it's a good idea to check to be sure);

3) If using Harry Mue's and Sofia Lemons' wifi tether application, assure you use a version released after July 18, 2013.


** General Description and Use **
This program enables the use of custom DNS name servers and caching as well as HTTP/HTTPS proxy and caching for Android Rooted phones.


Custom DNS Provider and Query Caching

To use the program for just DNS caching and redirection, install and start the program. Thereafter, check the options in the "System|Settings: DNS" menu and tune to your liking.

The DNS cache is implemented via dnsmasq and is always active when DnsQache is active. For Android versions lower than Jelly Bean, the application manages the network settings (e.g., system properties and /etc/resolv.conf) so that all DNS requests resolve via the local dnsmasq server.

For Android versions Jelly Bean and higher, the application sets rules via IPTABLES (http://www.netfilter.org/projects/iptables/) to redirect all DNS requests to the local dnsmasq server. In that way, DNS caching is always active when DnsQache is active. This is true whether or not the phone is being used for tethering.

For users of the fantastic Android Wifi Tether application (https://code.google.com/p/android-wifi-tether), the authors of that application, on Jul 18, 2013, merged in code fixes submitted by the author of this program that prevents the wifi-tether application from listening on the
localhost interface, which is required for DNS caching and not used by wifi-tether. To assure you are using the version of code in which that 'fix'
exists, you should be using wifi_tether_v3_4-experimental1.apk or higher (see https://code.google.com/p/android-wi...downloads/list). Tethered users gain the benefit of dns caching as well as proxy services provided by DnsQache.

At first, it may be a good idea to turn on 'Log Queries' in the DNS settings. That will allow you to view all DNS queries made by your phone and the endpoint to which the queries were redirected. To see those, you can use logcat (or an application that displays the same) or use the "System|View Log" menu, the latter of which will take a snapshot of the existing logcat log as it relates to dnsmasq and present the information. If no log shows (e.g., the log says the log file is not available), then it means you did not turn on Log Queries and restart the service, or the service failed due to bad settings. The most common issue there is if you use custom IP addresses for the DNS name servers and dnsmasq ultimately fails to start due to such configuration error.


Using the HTTP/HTTPS Proxy

Generally, for proxy use, clients (your laptop for example) can connect via wifi to your phone, when tethering, and get access to the internet using the mobile connection (4G, 3G, 2G) of your phone. That may occur through custom ROMs as native hotspot or via the wifi-tether application. When DnsQache is active, custom DNS name servers and caching is automatically enabled for tethered users as well as the phone.

To use proxy services, chech the values in the "System|Settings: Proxy" menu. Once saved, the options will take effect only after the service is (re)started. To restart, simply 'stop' and 'start' the DnsQache service. To do that, return to the main page of the app and the big 'DQ' will be either green or grey. If grey, it means the service is not currently running, so just touch the DQ to start it. If green (and you need to restart), just touch the DQ and give it time to shut down (goes grey) and touch it again (start).

The Proxy settings allow for the use of either polipo (http://www.pps.univ-paris-diderot.fr...ftware/polipo/) or tinyproxy (https://banu.com/tinyproxy/). Tinyproxy does not perform page caching, as does polipo, so the general preference ends up use of polipo.

The settings require that you to specify one or more CIDR ranges for client addresses allowed to connect to the proxy. The CIDRs of interest generally are the network addresses (e.g., 172.20.21.0/24) of your mobile hotspot (tether) network. You can view that in your phone settings, or the settings of your wifi-tether application. DnsQache sets the proxy connection port to 3128, so any client you want to proxy *must* set the proxy port to 3128. A later release will allow changing the port.

To have tethered users go through the proxy instead of directly NATed connection through the phone, the tethered user must set their device (computer, et al) to use a proxy. Set the proxy settings to use the IP address of your tethering gateway (the IP address of your wifi when tethering -- usually that is the ".1" address of the CIDR you specified for your client addresses for tethering or mobile hotspot application). As noted, when using the polipo proxy, proxy caching of content takes place on the phone, though secured pages (HTTPS) should not end up cached.


** Some Credits: **
The front page, and indeed the service layer code was inspired by, and to some extent, borrows from the venerable android-wifi-tether project originally authored by Harry Mue (harald.mue@gmail.com) and Sofia Lemons. While so inspired, obviously DnsQache is different in its nature and thus the code is quite different as a whole. Still -- reading and contributing to Harry's and Sofia's code was what got things rolling, so that body of work deserves significant mention, and that exists also in the sources.
The Following 26 Users Say Thank You to tdhite For This Useful Post: [ Click to Expand ]
 
tdhite
Old
(Last edited by tdhite; 18th June 2014 at 01:26 PM.)
#2  
Senior Member - OP
Thanks Meter 1932
Posts: 987
Join Date: Dec 2012
Location: DFW

 
DONATE TO ME
Default Disclaimer and Download Link

*** Legal Disclaimer -- READ ALL OF THE FOLLOWING ***

The Download Link Is After This Disclaimer Information


If you use the software, or convey it to someone else, you and all subsequent
conveyees are bound by the following:

# This work is partially based on the work by Harry Mue and Sofia Lemons
# (mailto: harald.mue@gmail.com) as it relates to Service management
# Though only a minor basis, DnsQache none the less acknowledges that
# body of work, and carries all of the disclaimers also inherent therein.
# See https://code.google.com/p/android-wifi-tether/ for more.

# LEGAL DISCLAIMERS AND ASSUMPTION OF THE RISK BY THE USER OF THIS PROGRAM

# Assumption of the Risk of Use
# YOU ASSUME, AND AGREE TO ASSUME, ALL THE RISK OF HARM BY USING THIS
# PROGRAM. THIS PROGRAM MAY VOID YOUR WARRANTY WITH A THIRD PARTY,
# IT MAY IMPROPERLY OPERATE AND DAMAGE YOUR DEVICE, IT MAY CAUSE ANY
# MYRIAD OF HARMFUL OUTCOMES REGARDING YOUR DEVICE OR THE USE OF THE DEVICE
# ON WHICH IT GETS INSTALLED. YOU ACKNOWLEDGE THAT YOU ARE AWARE OF THOSE
# RISKS, UNDERSTAND THOSE RISKS, AND VOLUNTARILY AND INTELLIGENTLY ELECT
# TO ENGAGE THOSE RISKS BY USING THE PROGRAM.

#Disclaimer of Warranty.
# THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
# LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
# OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
# THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH
# YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME ALL LIABILITY AND
# AGREE THAT IN NO EVENT WILL YOU SEEK ANY FORM OF RECOMPENSE, WHETHER LEGAL OR
# EQUITABLE, INCLUDING BUT NOT LIMITED TO NECESSARY SERVICING, REPAIR,
# CORRECTION OR OTHERWISE.

#Limitation of Liability.
# IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
# ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE
# PROGRAM, PERMITTED OR NOT, BE LIABLE TO YOU FOR LEGAL DAMAGES OR EQUITABLE
# RELIEF, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
# ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
# LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED
# BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
# PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGES.


DOWNLOAD LINKS:
DnsQache 1.0 Beta (RC7)
MD5 Checksum provided by Goo.IM

Version 0.85 (for pre-Android 3.0 users): dnsqache.apk
MD5 Checksum: f05161d291ec47ca1fbed95a10356908 dnsqache.apk
The Following 10 Users Say Thank You to tdhite For This Useful Post: [ Click to Expand ]
 
tdhite
Old
(Last edited by tdhite; 18th June 2014 at 01:27 PM.) Reason: typo fix.
#3  
Senior Member - OP
Thanks Meter 1932
Posts: 987
Join Date: Dec 2012
Location: DFW

 
DONATE TO ME
Default Change Logs

DnsQache 1.0 Beta

Disclaimer (always read disclaimers):
http://forum.xda-developers.com/show...56&postcount=2

ChangLog:
Version: 1.0 Beta (RC7)
  • Includes all enhancements/fixes to date.
  • Added custom DNS Provider option.
  • Fixed DNS log display.

Version: 1.0 Beta (RC5)
  • Includes all enhancements/fixes from RC4.
  • Fixed cache size resetting to 200.

Version: 1.0 Beta (RC4)
  • Includes all enhancements/fixes from RC2 (RC3 was a bust!).
  • Fixed failures in setting DNS providers when changed.
  • Fixed text not syncing with status on main UI page.

Version: 1.0 Beta (RC2)
  • New version -- beta 1.0, release candidate 2.
  • Fixed failures to start on boot.
  • New UI (requires Android 3.x or above).
  • *Many* settings surfaced to tightly control Polipo and TinyProxy

Version: 0.81
  • Fixed polipo not starting with default settings.
  • Changed keyboard on proxy settings page when editing the allowed CIDRS. Now allows multiple CIDRS as comma separated. For example: 172.20.21.0/24, 192.168.1.0/24
  • Slipstreamed in a fix for the version bump (download link updated)

Version 0.82
  • Fixed bug where the DNS cache size was resetting to 0 (disabled cache)
  • Note: The reparation of this fix will likely cause a single reset of your cache size setting to change to 200 when you start the DnsQache service. Just reset the value to your liking, and stop/start the DnsQache service. After that initial 'reset' the program should operate normally in this regard.
  • Before sending a bug post on this issue, please assure you verify you have version 0.82 of the program, and also that you've cycled through the initial reset mentioned above.

Version 0.83
  • Modified IPTABLES and process model due to some ROMs killing dnsmasq processes other than the ROMs own, or otherwise refusing to start if another program is listening on port 53. DnsQache now listens on port 5353 for DNS requests and redirects all network interface requests destined for port 53 to DnsQache port 5353. DnsQache, of course, allows itself to send requests out port 53 to the custom DNS entries.
  • Before sending a bug post on this issue, please assure you verify you have version 0.83 of the program, and also that you've cycled through the initial reset mentioned above.

Version 0.84
  • Added About and Donate Views;
  • Fixed DNS cache size resetting to default on reboot of phone;
  • Note: Due to the nature of the cache resetting, in rare cases, the configuration files for the underlying dnsmasq may contain an invalid value, which can cause dnsmasq to fail to start. If you experience connection failures after updating, please do the following: stop the DnsQache service; clear the DnsQache applications data (to do that, go to your application manager and select "Clear Data." Another method is to simply uninstall the old version of DnsQache prior to installing this upgrade); run DnsQache and configure the settings to your liking; start the DnsQache service (hit that big DQ and make it go Green!).

Note: When upgrading with new dnsqache.apk files, you should (really, really should) stop the DnsQache service (the big DQ turns grey when the service is off); install the dnsqache.apk; then check settings (installs may overwrite some settings); finally restart the service.
The Following 4 Users Say Thank You to tdhite For This Useful Post: [ Click to Expand ]
 
android404
Old
#4  
android404's Avatar
Senior Member
Thanks Meter 466
Posts: 745
Join Date: Jan 2013
Location: Oslo
whow!
sent from naked browser
 
tdhite
Old
#5  
Senior Member - OP
Thanks Meter 1932
Posts: 987
Join Date: Dec 2012
Location: DFW

 
DONATE TO ME
Quote:
Originally Posted by android404 View Post
whow!
Hope you like it. Let me know how it goes.
 
killoid
Old
#6  
killoid's Avatar
Senior Member
Thanks Meter 239
Posts: 881
Join Date: Feb 2013
Location: 23.7000 N, 90.3750 E
@tdhite first of all,great work! there is only oneappsimilar to yours.

i was using crossbreeder until now,i've been testing your app on my samsung galaxy y duos running stock 2.3.6. i've faced one bug,when i click about it does nothing.i am using opendns & polipo under dns & proxy settings. also i dont know wheather your app is working or not,so i've attached the logs from data/data/com.tdhite.dnsqache. plz tell me if it works or not.

i will suggest you should work on the app UI & icon.a holo dark look will be better.& plz make this app an foreground application & hide the notification bar icon or include an option to do it.

p.s. when i type 'su getprop net.dns1' it shows 127.0.0.1. & for 'su getprop net.dns2' it shows 119.30.37.10.
Attached Files
File Type: txt dnsqache.log.txt - [Click for QR Code] (263 Bytes, 24 views)
File Type: txt polipo.log.txt - [Click for QR Code] (173 Bytes, 11 views)
File Type: txt scripter.log.txt - [Click for QR Code] (8.0 KB, 13 views)
Quote:
"I've never actually seen a mongoose or an antelope. My zoology may be inaccurate!"
My Thread:
[INDEX][XPOSED]List of Xposed Modules for Android 2.3.x


Samsung Galaxy Y Duos GT-S6102
Rom: Stock GB 2.3.6
Kernel: Kuro's Kernel
Status: Rooted,Deodexed


Nokia X2-00
 
tdhite
Old
#7  
Senior Member - OP
Thanks Meter 1932
Posts: 987
Join Date: Dec 2012
Location: DFW

 
DONATE TO ME
Quote:
Originally Posted by killoid View Post
@tdhite first of all,great work! there is only oneappsimilar to yours.

i was using crossbreeder until now,i've been testing your app on my samsung galaxy y duos running stock 2.3.6. i've faced one bug,when i click about it does nothing.i am using opendns & polipo under dns & proxy settings. also i dont know wheather your app is working or not,so i've attached the logs from data/data/com.tdhite.dnsqache. plz tell me if it works or not.

i will suggest you should work on the app UI & icon.a holo dark look will be better.& plz make this app an foreground application & hide the notification bar icon or include an option to do it.

p.s. when i type 'su getprop net.dns1' it shows 127.0.0.1. & for 'su getprop net.dns2' it shows 119.30.37.10.
Given the logs, it appears the DNS caching / redirection is working quite well. You can also watch the DNS operations using a command (terminal emulator or similar):

logcat -s dnsmasq:*

That will let you watch the DNS queries -- of course assuming you have 'Log Queries' turned on in the settings.

As for the 'net.dns?' property settings, DnsQache will set the phone to use localhost (dnsmasq) as the primary, but if it were to blow away the secondary setting, no network at all would work if dnsmasq failed for any reason. So in the event port 53 on localhost is not listening, the secondary dns server would get used by Android so at least you get network. As another point, Jelly Bean and above don't even use those properties, so not to worry if you're not on an older Android version.


Polipo, however, appears to have a bad value for the CIDR settings. I surmise this might be a bug, I'll fix it if so. The issue, as a bet, is that without at least *one* click of the 'Set Allowed CIDRs' button in the Proxy settings, the default value somehow is getting missed in the configuration manager. The key log was "can't parse network null" so polipo refused to start. I need to surface that kind of error better -- will work on that. You can see the error in /data/data/com.tdhite.dnsqache/conf/polipo.conf where the line:

allowedClients=127.0.0.1, null

probably appears. That's because, for whatever reason, the default is not taking so the configuration is wrong.

So, can you try going to the 'Settings|Settings:Proxy" menu and click the 'Set Allowed CIRDs' button it should properly set the configuration. Then restart the service (click the big DQ so it goes grey, give it a few secs to clear the messages that popup, then click the big DQ again to start it). That will then properly start polipo.

My apologies for the bug -- I have to attest I always set the CIDR differently than default because the tethering (native) usually is set differently for me. This is a bug and I'll fix it and re-upload a new version. I'll post here when it's fixed and uploaded (probably evening, I have work-work to do).

Finally -- polipo provides an internal status page (actually many). You can view that on your phone or on any device tethered (thus with an IP address in the allowed CIDR range). For instance, on your phone browser, go to http://localhost:3128/polipo/status? to see current status. See this page for more: http://www.pps.univ-paris-diderot.fr...po/polipo.html.
The Following 2 Users Say Thank You to tdhite For This Useful Post: [ Click to Expand ]
 
killoid
Old
#8  
killoid's Avatar
Senior Member
Thanks Meter 239
Posts: 881
Join Date: Feb 2013
Location: 23.7000 N, 90.3750 E
Quote:
Originally Posted by tdhite View Post
So, can you try going to the 'Settings|Settings:Proxy" menu and click the 'Set Allowed CIRDs' button it should properly set the configuration. Then restart the service (click the big DQ so it goes grey, give it a few secs to clear the messages that popup, then click the big DQ again to start it). That will then properly start polipo.
yes after trying your method polipo is seemed to be working ok.in the log now it says 'Established listening socket on port 3128.'

Quote:
My apologies for the bug -- I have to attest I always set the CIDR differently than default because the tethering (native) usually is set differently for me. This is a bug and I'll fix it and re-upload a new version. I'll post here when it's fixed and uploaded (probably evening, I have work-work to do).
when you find enough time,you do it.no hurry! we all have a life.

Quote:
Finally -- polipo provides an internal status page (actually many). You can view that on your phone or on any device tethered (thus with an IP address in the allowed CIDR range). For instance, on your phone browser, go to http://localhost:3128/polipo/status? to see current status. See this page for more: http://www.pps.univ-paris-diderot.fr...po/polipo.html.
i've tried to access to the address you mentioned with opera mini,but no success.it says in the page 'could not connect to remote server'.
Quote:
"I've never actually seen a mongoose or an antelope. My zoology may be inaccurate!"
My Thread:
[INDEX][XPOSED]List of Xposed Modules for Android 2.3.x


Samsung Galaxy Y Duos GT-S6102
Rom: Stock GB 2.3.6
Kernel: Kuro's Kernel
Status: Rooted,Deodexed


Nokia X2-00
 
tdhite
Old
#9  
Senior Member - OP
Thanks Meter 1932
Posts: 987
Join Date: Dec 2012
Location: DFW

 
DONATE TO ME
Quote:
Originally Posted by killoid View Post
yes after trying your method polipo is seemed to be working ok.in the log now it says 'Established listening socket on port 3128.'



when you find enough time,you do it.no hurry! we all have a life.



i've tried to access to the address you mentioned with opera mini,but no success.it says in the page 'could not connect to remote server'.

Check download link -- updated version with fixes. Attached is a screenshot of hitting localhost to see polipo status. As well, you can now enter multiple CIDRs by comma separating them. That way you can turn on your WiFi, include your WiFi CIDR in the 'allowed' settings, start DnsQache with polipo enables and then hit your device via the Wifi network (e.g., http://192.168.208.77:3128/polipo/status?).
Attached Thumbnails
Click image for larger version

Name:	Screenshot_2013-12-19-11-22-07.png
Views:	453
Size:	249.4 KB
ID:	2463985  
The Following User Says Thank You to tdhite For This Useful Post: [ Click to Expand ]
 
killoid
Old
#10  
killoid's Avatar
Senior Member
Thanks Meter 239
Posts: 881
Join Date: Feb 2013
Location: 23.7000 N, 90.3750 E
Quote:
Originally Posted by tdhite View Post
Check download link -- updated version with fixes. Attached is a screenshot of hitting localhost to see polipo status. As well, you can now enter multiple CIDRs by comma separating them. That way you can turn on your WiFi, include your WiFi CIDR in the 'allowed' settings, start DnsQache with polipo enables and then hit your device via the Wifi network (e.g., http://192.168.208.77:3128/polipo/status?).
download link is not working,giving 404 error.
Quote:
"I've never actually seen a mongoose or an antelope. My zoology may be inaccurate!"
My Thread:
[INDEX][XPOSED]List of Xposed Modules for Android 2.3.x


Samsung Galaxy Y Duos GT-S6102
Rom: Stock GB 2.3.6
Kernel: Kuro's Kernel
Status: Rooted,Deodexed


Nokia X2-00

Tags
cache, dns, proxy, root
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes