Blog

CNAME no siempre requiere una petición adicional

CNAME no siempre requiere una petición adicional

Siempre había pensado que un registro CNAME implica una petición DNS adicional, pero resulta que no:

It’s the job of the upstream servers to recognise that the queried domain name has a CNAME entry in it, and then look up and return the target result. In this case both the CNAME record and the required result are returned in the Answer Section of the DNS response (and not in the Additional Section as someone else answered).

For optimum performance it’s best that the target of the CNAME be hosted on the same authoritative DNS server as the domain name that contains the CNAME so that the CNAME resolution can be done without further DNS requests.

https://stackoverflow.com/a/748731

If the target of the CNAME is on the same authoritative DNS server it will already include the resolved A in the answer as well.

So it can also be handled in a single query with no performance hit, but this depends on the DNS setup you are using.

https://serverfault.com/a/460479

Preguntando al servidor autoritativo para www.riru.re, vemos que efectivamente aparece tanto CNAME como el A para ese CNAME en el Answer Section, evitando una petición adicional para éste último:

j@bt ~ % dig www.riru.re @ns-121-b.gandi.net

; <<>> DiG 9.16.21 <<>> www.riru.re @ns-121-b.gandi.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56544
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1220
; COOKIE: fddae470631ba872202d511261eaa62b7dfd73cb7038fcc8 (good)
;; QUESTION SECTION:
;www.riru.re.			IN	A

;; ANSWER SECTION:
www.riru.re.		3534	IN	CNAME	webacc0.sd3.ghst.net.
webacc0.sd3.ghst.net.	1134	IN	A	155.133.132.2

;; Query time: 10 msec
;; SERVER: 213.167.230.122#53(213.167.230.122)
;; WHEN: Fri Jan 21 13:25:14 CET 2022
;; MSG SIZE  rcvd: 118