Este projeto resolve um dos maiores desafios para ISPs e administradores de rede na transição IPv6: a geração dinâmica de Registros AAAA (Forward) e PTR (DNS Reverso) sem a necessidade de popular bancos de dados massivos. Ideal para redes ADSL, Laboratórios e Provedores que buscam automação real e baixo consumo de recursos.
This project addresses one of the biggest challenges for ISPs and network administrators during the IPv6 transition: the dynamic generation of AAAA Records (Forward) and PTR (Reverse DNS) without the need for massive databases. Perfect for ADSL networks, Labs, and ISPs seeking true automation and resource efficiency.
Para que o PowerDNS execute o script Python corretamente e evite erros de cache ou segurança que interrompem o serviço, edite seu arquivo /etc/powerdns/pdns.conf e adicione ou ajuste as diretivas abaixo:
To ensure PowerDNS executes the Python script correctly and avoids cache or security-related errors, edit your /etc/powerdns/pdns.conf file and add or adjust the following directives:
# Desativa a checagem de segurança que vimos no log
security-poll-suffix=
# Desativa o cache de zona que causou o erro fatal
zone-cache-refresh-interval=0
# Garante que ele continue rodando mesmo com erros de backend
distributor-threads=3
receiver-threads=1
# Backend Pipe Configuration
launch=pipe
pipe-command=/etc/powerdns/backend.py
pipe-timeout=2000
local-address=0.0.0.0, ::
Copie o código abaixo e salve-o em /etc/powerdns/backend.py. Este script gerencia as respostas dinâmicas via Pipe. Lembre-se de ajustar as variáveis de rede no início do código.
Copy the code below and save it to /etc/powerdns/backend.py. This script handles dynamic responses via Pipe. Make sure to adjust the network variables at the beginning of the code.
#!/usr/bin/python3
import sys
def log(msg):
sys.stdout.write(msg + "\n")
sys.stdout.flush()
# Handshake inicial
log("OK\tDynamic IPv6 Backend")
while True:
line = sys.stdin.readline()
if not line: break
parts = line.strip().split('\t')
if parts[0] == 'PING':
log("PONG")
continue
if parts[0] == 'Q' and len(parts) >= 4:
qname = parts[1].lower().rstrip('.')
qtype = parts[3]
# --- CONFIGURAÇÃO DAS ZONAS (ALTERE COM SEUS DADOS) ---
# ZONA 1: Exemplo ADSL (Prefix: 2001:db8:1101::/64)
PTR_ADSL = "1.0.1.1.8.b.d.0.1.0.0.2.ip6.arpa"
DOM_ADSL = "adsl.dominio.com.br"
PFX_ADSL = "2001:db8:1101"
# ZONA 2: Exemplo LAB (Prefix: 2001:db8:2002::/64)
PTR_LAB = "2.0.0.2.8.b.d.0.1.0.0.2.ip6.arpa"
DOM_LAB = "lab.dominio.com.br"
PFX_LAB = "2001:db8:2002"
# 1. TRATAMENTO DE SOA E NS (Aceitação do PowerDNS)
if qtype == 'SOA':
log(f"DATA\t{parts[1]}\tIN\tSOA\t3600\t-1\tns.{DOM_ADSL}. admin.dominio.com.br. 2026041201 28800 7200 604800 3600")
elif qtype == 'NS':
log(f"DATA\t{parts[1]}\tIN\tNS\t3600\t-1\tns.{DOM_ADSL}")
# 2. LÓGICA DE DADOS (PTR / AAAA)
else:
if PTR_ADSL in qname:
bits = qname.split('.')
host = "".join(reversed(bits[:16]))
log(f"DATA\t{parts[1]}\tIN\tPTR\t3600\t-1\t{host}.{DOM_ADSL}")
elif qname.endswith(DOM_ADSL):
host = qname.split('.')[0]
if len(host) == 16:
p = [host[i:i+4] for i in range(0, 16, 4)]
log(f"DATA\t{parts[1]}\tIN\tAAAA\t3600\t-1\t{PFX_ADSL}:{p[0]}:{p[1]}:{p[2]}:{p[3]}")
elif host in ['ns', 'adsl']:
log(f"DATA\t{parts[1]}\tIN\tAAAA\t3600\t-1\t{PFX_ADSL}::1")
elif PTR_LAB in qname:
bits = qname.split('.')
host = "".join(reversed(bits[:16]))
log(f"DATA\t{parts[1]}\tIN\tPTR\t3600\t-1\t{host}.{DOM_LAB}")
elif qname.endswith(DOM_LAB):
host = qname.split('.')[0]
if len(host) == 16:
p = [host[i:i+4] for i in range(0, 16, 4)]
log(f"DATA\t{parts[1]}\tIN\tAAAA\t3600\t-1\t{PFX_LAB}:{p[0]}:{p[1]}:{p[2]}:{p[3]}")
elif host == 'lab':
log(f"DATA\t{parts[1]}\tIN\tAAAA\t3600\t-1\t{PFX_LAB}::1")
log("END")
Muitos administradores sempre sonharam com um script para resolução de nomes e PTR dinâmico em suas redes, principalmente ISPs. Para que funcione:
Delegação: Realize a delegação da zona ip6.arpa no seu Registro apontando para o IP deste servidor.
Entradas NS: Declare a entrada NS no seu domínio ou subdomínio apontando para este servidor.
Permissões: O script deve ser executável: chmod +x /etc/powerdns/backend.py.
Propriedade: Garanta que o usuário pdns tenha acesso ao diretório do script.
Many admins have always dreamed of a script for dynamic name resolution and PTR. To make it work:
Delegation: Perform the ip6.arpa zone delegation at your Registry pointing to this server IP.
NS Records: Declare the NS entry in your domain or subdomain pointing to this server.
Permissions: The script must be executable: chmod +x /etc/powerdns/backend.py.
Ownership: Ensure the pdns user has access to the script directory.
Este é um projeto aberto para a comunidade. Sinta-se à vontade para enviar melhorias! This is an open project for the community. Feel free to submit improvements!