Tutorial Completo — SmartDNS no OpenWrt
Testado em: Acer Predator Connect W6x | OpenWrt 25.12.4 | aarch64_cortex-a53 | MediaTek Filogic
O que é o SmartDNS?
O SmartDNS é um servidor DNS local que consulta múltiplos servidores upstream ao mesmo tempo e retorna o IP com menor latência — diferente do dnsmasq padrão que retorna o primeiro que responder.
Resultado: navegação mais rápida, menor ping em jogos e bloqueio de anúncios para toda a rede.
1. Instalação
apk update
apk add smartdns luci-app-smartdns
Observação: O `smartdns-ui` (dashboard) ainda não tem `.apk` oficial no OpenWrt 25.12 — use o LuCI em Serviços → SmartDNS.
2. Configurações gerais
uci set smartdns.@smartdns[0].enabled='1'
uci set smartdns.@smartdns[0].port='53'
uci set smartdns.@smartdns[0].cache_size='32768'
uci set smartdns.@smartdns[0].prefetch_domain='1'
uci set smartdns.@smartdns[0].serve_expired='1'
uci set smartdns.@smartdns[0].speed_check_mode='ping,tcp:80,tcp:443'
uci commit smartdns
| Opção | Valor | Descrição |
|---|---|---|
| port | 53 | Porta principal do DNS |
| cache_size | 32768 | Cache de 32k entradas |
| prefetch_domain | 1 | Renova cache antes de expirar |
| serve_expired | 1 | Entrega cache antigo enquanto atualiza |
| speed_check_mode | ping,tcp:80,tcp:443 | Testa qual IP responde mais rápido |
3. Servidores upstream IPv4
uci add smartdns server
uci set smartdns.@server[-1].name='Cloudflare-1'
uci set smartdns.@server[-1].ip='1.1.1.1'
uci set smartdns.@server[-1].type='udp'
uci add smartdns server
uci set smartdns.@server[-1].name='Cloudflare-2'
uci set smartdns.@server[-1].ip='1.0.0.1'
uci set smartdns.@server[-1].type='udp'
uci add smartdns server
uci set smartdns.@server[-1].name='Google-1'
uci set smartdns.@server[-1].ip='8.8.8.8'
uci set smartdns.@server[-1].type='udp'
uci add smartdns server
uci set smartdns.@server[-1].name='Google-2'
uci set smartdns.@server[-1].ip='8.8.4.4'
uci set smartdns.@server[-1].type='udp'
uci add smartdns server
uci set smartdns.@server[-1].name='Quad9'
uci set smartdns.@server[-1].ip='9.9.9.9'
uci set smartdns.@server[-1].type='udp'
uci commit smartdns
4. Servidores upstream IPv6
uci add smartdns server
uci set smartdns.@server[-1].name='Cloudflare-IPv6'
uci set smartdns.@server[-1].ip='2606:4700:4700::1111'
uci set smartdns.@server[-1].type='udp'
uci add smartdns server
uci set smartdns.@server[-1].name='Google-IPv6'
uci set smartdns.@server[-1].ip='2001:4860:4860::8888'
uci set smartdns.@server[-1].type='udp'
uci add smartdns server
uci set smartdns.@server[-1].name='Quad9-IPv6'
uci set smartdns.@server[-1].ip='2620:fe::fe'
uci set smartdns.@server[-1].type='udp'
uci commit smartdns
5. Evitar conflito com dnsmasq na porta 53
O dnsmasq continua responsável pelo DHCP — só muda de porta:
uci set dhcp.@dnsmasq[0].port='5353'
uci commit dhcp
/etc/init.d/dnsmasq restart
/etc/init.d/smartdns restart
Resultado final:
- SmartDNS → porta 53 (DNS principal)
- dnsmasq → porta 5353 (DHCP e DNS local .lan)
6. Verificar funcionamento
# Verificar processos na porta 53
netstat -tulnp | grep :53
# Testar resolução IPv4
nslookup google.com 127.0.0.1
# Testar resolução IPv6
nslookup google.com ::1
7. Bloqueio de anúncios e rastreadores
O SmartDNS usa o arquivo /etc/smartdns/domain-block.list para bloquear domÃnios. As listas usadas são do projeto Hagezi — referência em qualidade e atualização diária.
Fonte: github.com/hagezi/dns-blocklists
NÃvel 1 — Básico
Para: roteadores com 64–128 MB de RAM (ex: TP-Link, D-Link básicos)
Lista: `hagezi:pro` — 233k domÃnios
Bloqueia: anúncios e rastreadores principais
# Criar diretório
mkdir -p /etc/smartdns/lists
# Baixar lista
wget -O /tmp/hagezi.txt \
"https://raw.githubusercontent.com/hagezi/dns-blocklists/main/dnsmasq/pro.txt"
# Converter para formato SmartDNS
grep -v "^#" /tmp/hagezi.txt | \
sed 's/local=\///;s/\/$//' | \
sort -u > /etc/smartdns/domain-block.list
rm /tmp/hagezi.txt
wc -l /etc/smartdns/domain-block.list
/etc/init.d/smartdns restart
NÃvel 2 — Médio ⭐ (recomendado)
Para: roteadores com 256–512 MB de RAM (ex: GL.iNet, Xiaomi AX3000)
Lista: `hagezi:pro.plus` — 270k domÃnios
Bloqueia: anúncios, rastreadores, telemetria e métricas
mkdir -p /etc/smartdns/lists
wget -O /tmp/hagezi.txt \
"https://raw.githubusercontent.com/hagezi/dns-blocklists/main/dnsmasq/pro.plus.txt"
grep -v "^#" /tmp/hagezi.txt | \
sed 's/local=\///;s/\/$//' | \
sort -u > /etc/smartdns/domain-block.list
rm /tmp/hagezi.txt
wc -l /etc/smartdns/domain-block.list
/etc/init.d/smartdns restart
NÃvel 3 — Hard 🔥
Para: roteadores com 512 MB+ de RAM (ex: Acer Predator W6x, Asus RT-AX88U)
Lista: `hagezi:pro.plus` + `hagezi:ultimate` — 500k+ domÃnios
Bloqueia: anúncios, rastreadores, telemetria, phishing, malware e scam
mkdir -p /etc/smartdns/lists
# Baixar pro.plus
wget -q -O /tmp/hagezi-proplus.txt \
"https://raw.githubusercontent.com/hagezi/dns-blocklists/main/dnsmasq/pro.plus.txt"
# Baixar ultimate
wget -q -O /tmp/hagezi-ultimate.txt \
"https://raw.githubusercontent.com/hagezi/dns-blocklists/main/dnsmasq/ultimate.txt"
# Combinar e converter
cat /tmp/hagezi-proplus.txt /tmp/hagezi-ultimate.txt | \
grep -v "^#" | \
sed 's/local=\///;s/\/$//' | \
sort -u > /etc/smartdns/domain-block.list
rm /tmp/hagezi-proplus.txt /tmp/hagezi-ultimate.txt
wc -l /etc/smartdns/domain-block.list
/etc/init.d/smartdns restart
⚠️ Não use a lista `tif` (1.6M domÃnios) — pode travar o SmartDNS mesmo com muita RAM.
8. Testar bloqueio
# Sites normais — devem RESOLVER
nslookup google.com 127.0.0.1
nslookup youtube.com 127.0.0.1
nslookup steampowered.com 127.0.0.1
# Anúncios — devem ser BLOQUEADOS (NXDOMAIN)
nslookup ads.google.com 127.0.0.1
nslookup doubleclick.net 127.0.0.1
nslookup adservice.google.com 127.0.0.1
# Rastreadores — devem ser BLOQUEADOS
nslookup pixel.facebook.com 127.0.0.1
nslookup metrics.apple.com 127.0.0.1
nslookup analytics.004gmbh.de 127.0.0.1
Resultado esperado:
- Sites normais → retornam IP ✅
- Anúncios/rastreadores → `NXDOMAIN` ✅
9. Atualização automática da lista
cat > /etc/smartdns/update-blocklist.sh << 'EOF'
#!/bin/sh
# Ajuste a URL conforme seu nÃvel (pro, pro.plus, ultimate)
wget -q -O /tmp/hagezi-proplus.txt \
"https://raw.githubusercontent.com/hagezi/dns-blocklists/main/dnsmasq/pro.plus.txt"
if [ $? -eq 0 ]; then
grep -v "^#" /tmp/hagezi-proplus.txt | \
sed 's/local=\///;s/\/$//' | \
sort -u > /etc/smartdns/domain-block.list
rm /tmp/hagezi-proplus.txt
/etc/init.d/smartdns restart
fi
EOF
chmod +x /etc/smartdns/update-blocklist.sh
# Agendar para todo dia às 4h da manhã
echo "0 4 * * * /etc/smartdns/update-blocklist.sh" >> /etc/crontabs/root
/etc/init.d/cron enable
/etc/init.d/cron restart
10. Resumo da arquitetura final
Dispositivos da rede
↓
SmartDNS :53
├── Consulta 5 upstreams IPv4 + 3 IPv6 simultaneamente
├── Retorna o IP com menor latência (speed_check)
├── Cache prefetch — sempre quente
└── 270k domÃnios bloqueados (pro.plus)
↓
dnsmasq :5353
└── DHCP + DNS local (.lan)
