EDNS client subnet support for BIND

Vincent Bernat

To pro­vide ge­olo­ca­tion-aware an­swers with BIND, a com­mon so­lu­tion is to use a patch adding GeoIP sup­port. A client can be di­rected to the clos­est (and hope­fully fastest) web server:

view "FRANCE" {
     match-clients { geoip_cityDB_country_FR; };
     zone "example.com" in {
         type master;
         file "france.example.com.dns";
     };
};
view "GERMANY" {
     match-clients { geoip_cityDB_country_DE; };
     zone "example.com" in {
         type master;
         file "germany.example.com.dns";
     };
};
/* […] */
view "DEFAULT" {
    zone "example.com" in {
        type master;
        file "example.com.dns";
    };
};

How­ever, an end user does not usu­ally talk di­rectly to au­thor­i­ta­tive servers. They proxy the query through a third-party re­cur­sor server which will query the au­thor­i­ta­tive server on their be­half. The re­cur­sor also caches the an­swer to be able to serve it di­rectly to other clients.

In most cases, we can still rely on the re­cur­sor GeoIP lo­ca­tion to for­ward the client to the clos­est web server be­cause it is lo­cated in the client’s ISP net­work, as shown on the fol­low­ing schema:

Query for www.example.com through an ISP recursor
Ideal case: the recursor is located close to the end user.
  1. Juan is lo­cated in China and wants to know the IP ad­dress of www.​example.​com. She queries her ISP resolver.
  2. The re­solver asks the au­thor­i­ta­tive server for the answer.
  3. Be­cause the IP ad­dress of the re­solver is lo­cated in China, the au­thor­i­ta­tive server de­cides to an­swer with the IP ad­dress of the web server lo­cated in Japan which is the closest one.
  4. Juan can now en­joy short round-trips with the web server.

How­ever, this is not the case when us­ing a pub­lic re­cur­sor as pro­vided by Google or OpenDNS. In this case, the IP ad­dress of the end client and the source IP ad­dress of the re­cur­sor may not share the same lo­cal­ity. For ex­am­ple, in the fol­low­ing schema, the au­thor­i­ta­tive server now thinks it is in re­la­tion with a Eu­ro­pean cus­tomer and an­swers with the IP ad­dress of the web server lo­cated in Europe:

Query for www.example.com through an open recursor
Worst case: the recursor queries the authoritative server through a remote node.

More­over, caching makes the prob­lem worse.

To solve this prob­lem, a new EDNS ex­ten­sion to ex­pose the client sub­net has been pro­posed. When us­ing this ex­ten­sion, the re­cur­sor will pro­vide the client sub­net to the au­thor­i­ta­tive server for it to build an op­ti­mized re­ply. The sub­net is vague enough to re­spect client’s pri­vacy but pre­cise enough to be able to lo­cate it. A patched ver­sion of dig al­lows one to make queries with this new ex­tension:

$ geoiplookup 138.231.136.0
GeoIP Country Edition: FR, France
$ ./bin/dig/dig @dns-02.dailymotion.com www.dailymotion.com \
>     +client=138.231.136.0/24

; <<>> DiG 9.8.1-P1-geoip-1.3 <<>> @dns-02.dailymotion.com www.dailymotion.com +client=138.231.136.0/24
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23312
;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; CLIENT-SUBNET: 138.231.136.0/24/24
;; QUESTION SECTION:
;www.dailymotion.com.           IN      A

;; ANSWER SECTION:
www.dailymotion.com.    600     IN      A       195.8.215.136
www.dailymotion.com.    600     IN      A       195.8.215.137

;; Query time: 20 msec
;; SERVER: 188.65.127.2#53(188.65.127.2)
;; WHEN: Sun Oct 20 15:44:47 2013
;; MSG SIZE  rcvd: 91

$ geoiplookup 195.8.215.136
GeoIP Country Edition: FR, France

In the above ex­am­ple, a client lo­cated in France gets a re­ply with two IP ad­dresses lo­cated in France. If we now are a US client, we will get IP ad­dresses lo­cated in the US:

$ geoiplookup 170.149.100.0
GeoIP Country Edition: US, United States
$ ./bin/dig/dig @dns-02.dailymotion.com www.dailymotion.com \
>     +client=170.149.100.0/24

; <<>> DiG 9.8.1-P1-geoip-1.3 <<>> @dns-02.dailymotion.com www.dailymotion.com +client=170.149.100.0/24
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23187
;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; CLIENT-SUBNET: 170.149.100.0/24/24
;; QUESTION SECTION:
;www.dailymotion.com.           IN      A

;; ANSWER SECTION:
www.dailymotion.com.    600     IN      A       188.65.120.135
www.dailymotion.com.    600     IN      A       188.65.120.136

;; Query time: 18 msec
;; SERVER: 188.65.127.2#53(188.65.127.2)
;; WHEN: Sun Oct 20 15:47:22 2013
;; MSG SIZE  rcvd: 91

$ geoiplookup 188.65.120.135
GeoIP Country Edition: US, United States

The re­cur­sor is ex­pected to cache the two dif­fer­ent an­swers and only serve them if the client matches the ap­pro­pri­ate sub­net (the one con­firmed in the an­swer from the au­thor­i­ta­tive server). With this new ex­ten­sion, the au­thor­i­ta­tive server knows that Juan is lo­cated in China and an­swers with the ap­pro­pri­ate IP address:

Query for www.example.com through an open recursor with client subnet
Corrected case: the recursor queries the authoritative server through a remote node but provides the client subnet.

Not many au­thor­i­ta­tive servers sup­port this ex­ten­sion (PowerDNS and gdnsd, as far as I know). At Dai­ly­mo­tion, we have built a patch for BIND.1 It only works when BIND is con­fig­ured as an au­thor­i­ta­tive server and it doesn’t ex­pose any con­fig­u­ra­tion knobs. Feel free to use it (at your own risk). Once in­stalled, you need to reg­is­ter your­self to OpenDNS and to Google to re­ceive queries with the ex­ten­sion enabled.