Delegación de subdominios con bind9 en Debian 12
¿Que es una delegación de subdominios?
La delegación de subdominios es un proceso que sirve para asignar la responsabilidad de la administración de un subdominio a otro servidor DNS.
Requisitos
- Debian 12 instalado.
- Acceso a internet.
- privilegios de sudo o root.
- 2 Servidores DNS bind9 instalados.
Configuración de la delegación
Configuración del servidor DNS principal
En el servidor DNS principal, tenemos definida la zona “example.local” en el fichero /etc/bind/named.conf.local
:
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
zone "example.local" {
type master;
file "/etc/bind/db.example.local";
};
Y en el fichero /etc/bind/db.example.local
tenemos definidos los registros de la zona:
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA dns1.example.local. root.example.local. (
3 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS dns1.example.local.
$ORIGIN example.local.
dns1 IN A 192.168.50.17
www IN A 192.168.50.32
Para delegar el subdominio “sub.example.local” a otro servidor DNS, añadimos las siguientes líneas al fichero /etc/bind/db.example.local
:
$ORIGIN sub.example.local.
@ IN NS dns2
dns2 IN A 192.168.50.39
Quedaría de la siguiente forma:
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA dns1.example.local. root.example.local. (
3 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS dns1.example.local.
$ORIGIN example.local.
dns1 IN A 192.168.50.17
www IN A 192.168.50.32
$ORIGIN sub.example.local.
@ IN NS dns2
dns2 IN A 192.168.50.39
Una vez añadidas las líneas, reiniciamos el servicio bind9:
root@bind9-domain:~# systemctl restart bind9
Configuración del servidor DNS secundario
En el servidor DNS secundario, añadimos la zona “sub.example.local” al fichero /etc/bind/named.conf.local
:
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
zone "sub.example.local" {
type master;
file "/etc/bind/db.sub.example.local";
};
Y en el fichero /etc/bind/db.sub.example.local
definimos los registros de la zona:
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA dns2.sub.example.local. root.sub.example.local. (
3 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS dns2.sub.example.local.
$ORIGIN sub.example.local.
dns2 IN A 192.168.50.39
www IN A 192.168.50.45
Una vez definidos los registros, reiniciamos el servicio bind9:
root@bind9-subdomain:~# systemctl restart bind9
Prueba de funcionamiento
Si la delegación se ha realizado correctamente, al hacer una consulta al servidor DNS principal sobre algún registro de la zona “sub.example.local”, debería devolver la IP del registro correspondiente sin tener que hacer una consulta al servidor DNS secundario:
Consulta al dominio principal
root@debian12:~# dig @192.168.50.17 www.example.local
; <<>> DiG 9.18.24-1-Debian <<>> @192.168.50.17 www.example.local
; (1 server found)
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58067
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: ebc716531c4e64a501000000662f9eccf8154f4213727595 (good)
;; QUESTION SECTION:
;www.example.local. IN A
;; ANSWER SECTION:
www.example.local. 604800 IN A 192.168.50.32
;; Query time: 3 msec
;; SERVER: 192.168.50.17#53(192.168.50.17) (UDP)
;; WHEN: Mon Apr 29 13:21:16 UTC 2024
;; MSG SIZE rcvd: 90
Consulta al subdominio delegado
root@debian12:~# dig @192.168.50.17 www.sub.example.local
; <<>> DiG 9.18.24-1-Debian <<>> @192.168.50.17 www.sub.example.local
; (1 server found)
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45000
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: cb1ca88df1eef62a01000000662f9ee25ba1157d3105fa10 (good)
;; QUESTION SECTION:
;www.sub.example.local. IN A
;; ANSWER SECTION:
www.sub.example.local. 604607 IN A 192.168.50.45
;; Query time: 0 msec
;; SERVER: 192.168.50.17#53(192.168.50.17) (UDP)
;; WHEN: Mon Apr 29 13:21:38 UTC 2024
;; MSG SIZE rcvd: 94
Como podemos ver, al hacer la consultas al dominio principal y al subdominio delegado, ambas consultas son respondidas por el servidor DNS principal sin problemas.
Con esto hemos terminado la configuración de la delegación de subdominios con bind9 en Debian 12.