# UNBOUND – ESTATÍSTICAS

# UNBOUND – SERVIDOR DNS

Tutorial para monitorar o servidor DNS Unbound através do serviço de SNMP.

[![image-1740053252228.png](https://wiki.monsta.com.br/uploads/images/gallery/2025-02/scaled-1680-/image-1740053252228.png)](https://wiki.monsta.com.br/uploads/images/gallery/2025-02/image-1740053252228.png)

#### <span style="color: #000080;">Instalação do Unbound</span>

Para instalar o servidor DNS Unbound e configurá-lo para iniciar automaticamente, digite os comandos abaixo:

```shell
yum install unbound
systemctl enable unbound
systemctl start unbound
```

#### <span style="color: #000080;">Configuração do arquivo /etc/unbound/unbound.conf</span>

Edite o arquivo /etc/unbound/unbound.conf e habilite a opção para gerar estatísticas conforme abaixo:

`extended-statistics: yes`

O exemplo a seguir mostra uma configuração básica do servidor DNS Unbound com a opção para exibição de estatísticas extendidas habilitada.

<table border="1" id="bkmrk-server%3Averbosity%3A-1s" style="width: 100%; border-collapse: collapse; background-color: #000000;"><tbody><tr><td style="width: 100%; background-color: 111111;"><span style="color: #ffffff;">server:</span>  
<span style="color: #ffffff;"> verbosity: 1</span>  
<span style="color: #ffffff;"> satistics-interval: 0</span>  
<span style="color: #ffffff;"> statistics-cumulative: no</span>  
<span style="color: #ffffff;"> extended-statistics: yes</span>  
<span style="color: #ffffff;"> num-threads: 2</span>  
<span style="color: #ffffff;"> interface: 0.0.0.0</span>  
<span style="color: #ffffff;"> interface-automatic: yes</span>  
<span style="color: #ffffff;"> outgoing-range: 5000</span>  
<span style="color: #ffffff;"> so-rcvbuf: 4m</span>  
<span style="color: #ffffff;"> so-sndbuf: 4m</span>  
<span style="color: #ffffff;"> msg-cache-size: 25m</span>  
<span style="color: #ffffff;"> msg-cache-slabs: 2</span>  
<span style="color: #ffffff;"> num-queries-per-thread: 2500</span>  
<span style="color: #ffffff;"> rrset-cache-size: 50m</span>  
<span style="color: #ffffff;"> rrset-cache-slabs: 2</span>  
<span style="color: #ffffff;"> infra-cache-slabs: 2</span>  
<span style="color: #ffffff;"> access-control: 0.0.0.0/0 allow</span>  
<span style="color: #ffffff;"> chroot: ""</span>  
<span style="color: #ffffff;"> username: "unbound"</span>  
<span style="color: #ffffff;"> directory: "/etc/unbound"</span>  
<span style="color: #ffffff;"> log-time-ascii: yes</span>  
<span style="color: #ffffff;"> pidfile: "/var/run/unbound/unbound.pid"</span>  
<span style="color: #ffffff;"> harden-glue: yes</span>  
<span style="color: #ffffff;"> harden-dnssec-stripped: yes</span>  
<span style="color: #ffffff;"> harden-below-nxdomain: yes</span>  
<span style="color: #ffffff;"> harden-referral-path: yes</span>  
<span style="color: #ffffff;"> use-caps-for-id: no</span>  
<span style="color: #ffffff;"> unwanted-reply-threshold: 10000000</span>  
<span style="color: #ffffff;"> prefetch: yes</span>  
<span style="color: #ffffff;"> prefetch-key: yes</span>  
<span style="color: #ffffff;"> rrset-roundrobin: yes</span>  
<span style="color: #ffffff;"> minimal-responses: yes</span>  
<span style="color: #ffffff;"> trusted-keys-file: /etc/unbound/keys.d/\*.key</span>  
<span style="color: #ffffff;"> auto-trust-anchor-file: "/var/lib/unbound/root.key"</span>  
<span style="color: #ffffff;"> val-clean-additional: yes</span>  
<span style="color: #ffffff;"> val-permissive-mode: no</span>  
<span style="color: #ffffff;"> val-log-level: 1</span>  
<span style="color: #ffffff;"> key-cache-slabs: 2</span>  
<span style="color: #ffffff;"> include: /etc/unbound/local.d/\*.conf</span>  
<span style="color: #ffffff;">  
remote-control:</span>  
<span style="color: #ffffff;"> control-enable: yes</span>  
<span style="color: #ffffff;"> server-key-file: "/etc/unbound/unbound\_server.key"</span>  
<span style="color: #ffffff;"> server-cert-file: "/etc/unbound/unbound\_server.pem"</span>  
<span style="color: #ffffff;"> control-key-file: "/etc/unbound/unbound\_control.key"</span>  
<span style="color: #ffffff;"> control-cert-file: "/etc/unbound/unbound\_control.pem"</span>  
<span style="color: #ffffff;"> include: /etc/unbound/conf.d/\*.conf</span></td></tr></tbody></table>

#### <span style="color: #000080;">Reiniciando o serviço unbound</span>

Após, reinicie o serviço com o comando:

```shell
systemctl restart unbound
```

#### <span style="color: #000080;">Configurando o SNMP para enviar as estatísticas do Unbound</span>

<p class="callout info">Caso seu sistema não tenha o servidor SNMP configurado, leia o tutorial “Configurando o SNMP” disponível no site do Monsta.</p>

Faça um backup do arquivo /etc/snmpd.conf:

```shell
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.backup
```

Edite o arquivo /etc/snmp/snmpd.conf e configure-o conforme exemplo abaixo. Se desejar, altere o nome da comunidade.

`rocommunity public`  
`extend .1.3.6.1.3.1983.1.1 Unbound /usr/bin/cat /tmp/unbound_stats.txt`

#### <span style="color: #000080;">Reiniciando e habilitando o serviço SNMP</span>

Na tela de terminal, digite:

```shell
systemctl restart snmpd
```

#### <span style="color: #000080;">Adicionando as estatísticas na cron</span>

Na tela de terminal, digite o comando abaixo:

```shell
(crontab -l ; echo '*/1 * * * * /usr/sbin/unbound-control stats_noreset > /tmp/unbound_stats.txt' ) | crontab -
```

Após esses procedimentos, já é possível utilizar o Template “Unbound – DNS Server” para monitorar as estatísticas do seu servidor de DNS.

#### <span style="color: #000080;">Extra</span>

Em alguns sistemas o comando cat encontra-se em um diretório diferente do configurado no arquivo snmpd.conf. Para evitar problemas, você pode criar um link simbólico com o comando abaixo:

```shell
ln -s /usr/sbin/cat /bin
```

#### <span style="color: #000080;">Teste das configurações</span>

Para testar se as configurações feitas estão corretas, execute os passos abaixo:

```shell
yum install net-snmp-utils
snmpwalk -c public -v2c localhost .1.3.6.1.3.1983.1.1
```

O comando snmpwalk deverá retornar informações conforme o exemplo abaixo:

<table border="1" id="bkmrk-snmpv2-smi%3A%3Aexperime" style="width: 100%; border-collapse: collapse; background-color: #000000;"><tbody><tr><td style="width: 100%;"><span style="color: #ffffff;">SNMPv2-SMI::experimental.1983.1.1.1.0 = INTEGER: 1</span>  
<span style="color: #ffffff;">SNMPv2-SMI::experimental.1983.1.1.2.1.2.7.85.110.98.111.117.110.100 = STRING: "/usr/bin/cat"</span>  
<span style="color: #ffffff;">SNMPv2-SMI::experimental.1983.1.1.2.1.3.7.85.110.98.111.117.110.100 = STRING: "/tmp/unbound\_stats.txt"</span>  
<span style="color: #ffffff;">SNMPv2-SMI::experimental.1983.1.1.2.1.4.7.85.110.98.111.117.110.100 = ""</span>  
<span style="color: #ffffff;">SNMPv2-SMI::experimental.1983.1.1.2.1.5.7.85.110.98.111.117.110.100 = INTEGER: 5</span>  
<span style="color: #ffffff;">SNMPv2-SMI::experimental.1983.1.1.2.1.6.7.85.110.98.111.117.110.100 = INTEGER: 1</span>  
<span style="color: #ffffff;">SNMPv2-SMI::experimental.1983.1.1.2.1.7.7.85.110.98.111.117.110.100 = INTEGER: 1</span>  
<span style="color: #ffffff;">SNMPv2-SMI::experimental.1983.1.1.2.1.20.7.85.110.98.111.117.110.100 = INTEGER: 4</span>  
<span style="color: #ffffff;">SNMPv2-SMI::experimental.1983.1.1.2.1.21.7.85.110.98.111.117.110.100 = INTEGER: 1</span>  
<span style="color: #ffffff;">..</span></td></tr></tbody></table>

- - - - - -

#### <span style="color: #003366;">Contato</span>

<span style="color: #003366;">**Monsta Tecnologia Ltda**</span>  
Site: [http://www.monsta.com.br](http://www.monsta.com.br)  
Downloads: [http://www.monsta.com.br/download.html](http://www.monsta.com.br/download.html)  
E-mail: <contato@monsta.com.br>

- - - - - -

[![image-1645214142023.png](https://wiki.monsta.com.br/uploads/images/gallery/2022-02/scaled-1680-/image-1645214142023.png)](https://wiki.monsta.com.br/uploads/images/gallery/2022-02/image-1645214142023.png)