Preferred Anycast Paths for DNS with Quagga BGP

anycastbgpdnsquagga

Background and goal

Am setting up high availability DNS servers based on Unbound. Both DNS servers has in reality twelve BGP sessions against different routers but to make this easier only one router is showed below.

Both DNS servers are configured with the same two addresses on localhost (10.100.0.1, 10.100.0.2) and they both advertise these addresses with BGP. Problem is that if the DNS server that is preferred by other routers hangs, there is a timeout before BGP switches over to the second DNS server for both addresses. My goal is to have each DNS server have a primary responsibility for one of these two addresses so DNS clients do not have to wait for BGP timeout but instead handle failover as they know best. I do not want to add configurations to other routers, only on the DNS servers.

                    +------------+
                    |            |
                +---+  Router 1  +---+
                |   |            |   |
                |   +------------+   |
                |                    |
          +-----+----+          +----+-----+
          |          |          |          |
          |  DNS 1   |          |  DNS 2   |
          |          |          |          |
          +----------+          +----------+

(primary) 10.100.0.1          10.100.0.1
          10.100.0.2          10.100.0.2 (primary)

Problem and question

In the configuration below, how can I make DNS 1 announce 10.100.0.1 with a higher local preference so other routers choose this server instead of DNS 2 that is also announcing this IP but with lower priority?

router bgp 65002
    bgp router-id 10.0.0.1
    bgp confederation identifier 42xxx
    bgp confederation peers 65001 65002

    network 10.100.0.1/32
    network 10.100.0.2/32

    neighbor 10.0.0.10 remote-as 65001
    neighbor 10.0.0.10 route-map only-local-ASes out
!
ip as-path access-list only-local-ASes permit ^$
!
route-map only-local-ASes permit 10
match as-path only-local-ASes

Should I create a route-map that adds local preference 200 for only matched prefix 10.100.0.1? Problem am having is that this makes the router only announce 10.100.0.1 prefix and not both (also 10.100.0.2) at the same time with different preference.

Software

Linux kernel 4.4.0
Ubuntu 16.04 server
Quagga 0.99.24.1

Best Answer

What you have described is not the way anycast works. For anycast, you have all the DNS servers configured with the same address (usually on the loopback interface), they then participate in the routing protocols and advertise that address from each DNS server. Then the router hears the advertisement from each running server (and, of course, not from any dead ones providing robustness) and is configured to do round-robin on equal cost routes. Since DNS uses UDP (at least preferably) and is idempotent, this spreading out of the requests (and ultimately the load) does not impact the service.

As an additional fine tuning, you should have rules in the router for DNS over TCP where all packets in a connection need to go to the same server. There are a number of ways to achieve this, one I have seen used is to have another server with that common address configured, but which does not advertise it into the routing and you send all TCP to that one (so it ends up getting all AXFR requests, for example).

Much more elaborate setups are also possible. I've done some fairly complex ones...