[Android Apps and Games] esgie:
Hi,

First of all, I am an absolute newbie to networking stuff... And maybe my question (and my far-from-professional lagnuage...) is silly, but... i'll give it a try :)

Let's assume such a scenario (it's about individual device ONLY, nothing about thethering or something), which I need to combine with DNS caching.

- i am redirecting some alphanumerical domains addresses (known, finite amout of domains, which shall be considered as predefined...) to IPs which are different than the ones given by DNS servers (there are more IPs than domains - see below... we may assume that the destination IPs are not predefined and dnsmasq can't access the list, as well as it can't predict it in any way, as they are generated from external source);

- i am doing it by the hosts file, ie. by adding the entries concerning domains and new, "fake" IPs, which I want them to be redirected (in a manner similiar to one that AdAway works...)

- here comes the difficulty: I have a script running in the background, which periodically (within a few minutes) modifies hosts script entries, so the same domains are being redirected to new IPs (which are achieved from external source and, again, cannot be passed to dnsqache before starting whole thing as a predefined list...);

- in result: if the user is connecting the address x - then he is redirected to an IP no. 1 every time within some time limit, ie. 5 mins. But if he connects again after 5 minutes, he will be redirected to other IP, no. 2. Another 5 mins - another IP 3, etc etc etc

Again: the domain names is known and predefined at the beginning. The destination IPs can't be predicted in any way before starting the whole stuff. Also, please assume that above infrastructure and a way it works cannot be modified.

Hope you got it.

And now the problem: with dnmasq on, when I connect to a domain from the list, it correctly connects me with an IP associated by entry in the hosts file. BUT since the hosts file changes on-the-fly for the first time, dnsmasq still connects me to the first IP address (which has been cached), ignoring the new redirection in the hosts file.

The point is to:

1) exclude a finite numbers of domains from caching with dnsqache at all, so they will be resolved in a regular manner, ie. by the hosts file in the first step, or external DNS server in the second step, OR....

2) configure dnsmasq to resolve redirections from hosts file BEFORE resolving address from cache (if there is a host entry related to the domain, forward it to the hosts IP; otherwise, query cache; otherwise, query DNS serever)

I'd prefer to implement above mechanism as an exception for predefined domain names, however, I may also accept if it will work for every domain...

Btw masqed conqueror - the concurrent dnsmasq app available at GooglePlay - works well out-of-the-box; not sure about the crossbreeder, as I don't want to flash it.*

How can I define such a rules with dnsmasq, ie. using Terminal shell, init script or any other way?

Thank you.

*well, it seems its actually not good that it is "working" in the other app, as it is expected to lookup domain in cache in the first step - so dnsqache is behaving well and in a more optimal way when it comes to general internet browsing, however, specific conditions described above requires the other approach. Well in result my question may be reduced to simple: "how to set up exceptions, ie. declare a blacklist of domains, which i might want to be still resolved without referring to dns caching".

I am not familiar with all this binaries like iptables that are used in the caching process, but i guess the answer might be as simple as just one single terminal command - badly, i failed to figure it out myself. Please help ;)