The way dnsmasq choses its favor forward destination

How does dnsmasq "favours" servers? Does it periodically send queries to all DNS servers and sees which one responds first?

You can find details about the algorithms scattered over the dnsmasq-discuss mailing list.

Thank you. I came across this response from Simon, although it's from 2009. In case anyone else is interested.

It may be worth quoting this:

The algorithm for determining which server to use goes like this.
In the start state, dnsmasq sends the query to all the servers. When the
first server replies, it becomes the preferred server and dnsmasq moves
into a state where only the preferred server is used. It remains in that
state until one of three conditions occur, when dnsmasq moves back to
the initial state and a query is again sent to all the servers. The
conditions are.

  1. A SERVFAIL or REFUSED return code is received.
  2. More than 50 queries or 10 seconds have elapsed
  3. No reply is received and a client times-out and retries a query.

I think the limits set by (2) are way too restrictive. The redetermination of the fastest responder might also happen only every 10 minutes in my opinion, but that is a subjective feeling, only.

2 Likes

As of now, the DNS forward destination determination algorithm in FTLDNS's is modified to be much less restrictive. We keep using the fastest responding server now for 1000 queries or 10 minutes (whatever happens earlier) instead of 50 queries or 10 seconds.
We keep the exceptions, i.e., we try all possible forward destinations if SERVFAIL or REFUSED is received or if a timeout occurs.

Let's see how this works out.
I have tested this now for a few days and it seems to work nicely. I'd be happy to get your feedback here.

Overall, this change should reduce the number of actually performed queries notably and may even be preferential in terms of privacy (as we send queries much less often to all servers). I plan to submit my modifications (in a user modifiable manner) to the upstream version of dnsmasq if this is confirmed to be an improvement.

2 Likes

A huge difference :open_mouth: but sounds good in regard to reduced queries.
On the other side, a server can "track" the user for 10 minutes.

I'm not very knowledgable about this, but the proposal seems fine to me. Every 1000 queries or every 10 minutes is a reasonable time to do a check. Is it available on FTLDNS beta branch now?

Yes.

But if one of your servers is always faster than it will always again be selected, hence you have the same situation. Only difference is that the check (sending it to all servers) is then running 60 times more often.

You're right, that is an argument.
Thanks for the improvment :+1: