INSTALANDO E CONFIGURANDO UM SERVIDOR DNS  
Autor: Fabio Biancardi | Publicado: 2017-04-12T11:13:00-03:00


BIND



BIND (Berkeley Internet Name Domain ou, como chamado previamente, Berkeley Internet Name Daemon) é o servidor para o protocolo DNS mais utilizado na Internet, especialmente em sistemas do tipo Unix,





INICIANDO A INSTALAÇÃO DO BIND



Instale o Pacote bind9





# apt-get install bind9




CONFIGURANDO O BIND

Após ter instalado o pacote do BIND é hora de configurar um domínio (meudominio.com.br)&nbsp;


O primeiro deles é o /etc/named.conf, caso esse arquivo já exista, faça um backup dele e crie um novo com o conteúdo abaixo.&nbsp;

__________________________________________________
options {
&nbsp; &nbsp; &nbsp; &nbsp; directory "/var/named";
&nbsp; &nbsp; &nbsp; &nbsp; /*
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* If there is a firewall between you and nameservers you want
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* to talk to, you might need to uncomment the query-source
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* directive below. &nbsp;Previous versions of BIND always asked
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* questions using port 53, but BIND 8.1 uses an unprivileged
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* port by default.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/
&nbsp; &nbsp; &nbsp; &nbsp; // query-source address * port 53;

&nbsp; &nbsp; &nbsp; &nbsp; transfer-format many-answers;

};

controls {
&nbsp; &nbsp; &nbsp; &nbsp; inet * port 953 allow { 127.0.0.1; }; // Para usar o rndc apenas em localhost
};


//
// a caching only nameserver config
//
zone "." IN {
&nbsp; &nbsp; &nbsp; &nbsp; type hint;
&nbsp; &nbsp; &nbsp; &nbsp; file "caching-example/named.ca";
};

zone "localhost" IN {
&nbsp; &nbsp; &nbsp; &nbsp; type master;
&nbsp; &nbsp; &nbsp; &nbsp; file "caching-example/localhost.zone";
&nbsp; &nbsp; &nbsp; &nbsp; allow-update { none; };
};

zone "meudominio.com.br" IN {
&nbsp; &nbsp; &nbsp; &nbsp; type master;
&nbsp; &nbsp; &nbsp; &nbsp; file "meudominio.com.br.domain";
&nbsp; &nbsp; &nbsp; &nbsp; allow-update { none; };

};



__________________________________________________



Agora vamos criar o /var/named/caching-example/named.ca. necessario a criação dos diretorios named e caching-example e tambem o arquivo named.ca





&nbsp;__________________________________________________


; &nbsp; &nbsp; &nbsp; This file holds the information on root name servers needed to

; &nbsp; &nbsp; &nbsp; initialize cache of Internet domain name servers

; &nbsp; &nbsp; &nbsp; (e.g. reference this file in the "cache &nbsp;. &nbsp;&lt;file&gt;"

; &nbsp; &nbsp; &nbsp; configuration file of BIND domain name servers).

;

; &nbsp; &nbsp; &nbsp; This file is made available by InterNIC registration services

; &nbsp; &nbsp; &nbsp; under anonymous FTP as

; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;domain/named.root

; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on server &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FTP.RS.INTERNIC.NET

; &nbsp; &nbsp; &nbsp; -OR- under Gopher at &nbsp; &nbsp;RS.INTERNIC.NET

; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; under menu &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;InterNIC Registration Services (NSI)

; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;submenu &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;InterNIC Registration Archives

; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;named.root

;

; &nbsp; &nbsp; &nbsp; last update: &nbsp; &nbsp;Aug 22, 1997

; &nbsp; &nbsp; &nbsp; related version of root zone: &nbsp; 1997082200

;&nbsp;

;

; formerly NS.INTERNIC.NET

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp;IN &nbsp;NS &nbsp; &nbsp;A.ROOT-SERVERS.NET.

A.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 198.41.0.4

;

; formerly NS1.ISI.EDU

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp;B.ROOT-SERVERS.NET.

B.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 128.9.0.107

;

; formerly C.PSI.NET

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp;C.ROOT-SERVERS.NET.

C.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 192.33.4.12

;

; formerly TERP.UMD.EDU

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp;D.ROOT-SERVERS.NET.

D.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 128.8.10.90

;

; formerly NS.NASA.GOV

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp;E.ROOT-SERVERS.NET.

E.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 192.203.230.10

;

; formerly NS.ISC.ORG

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp;F.ROOT-SERVERS.NET.

F.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 192.5.5.241

;

; formerly NS.NIC.DDN.MIL

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp;G.ROOT-SERVERS.NET.

G.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 192.112.36.4

;

; formerly AOS.ARL.ARMY.MIL

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp;H.ROOT-SERVERS.NET.

H.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 128.63.2.53

;

; formerly NIC.NORDU.NET

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp;I.ROOT-SERVERS.NET.

I.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 192.36.148.17

;

; temporarily housed at NSI (InterNIC)

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp;J.ROOT-SERVERS.NET.

J.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 198.41.0.10

;

; housed in LINX, operated by RIPE NCC

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp;K.ROOT-SERVERS.NET.

K.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 193.0.14.129

;

; temporarily housed at ISI (IANA)

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp;L.ROOT-SERVERS.NET.

L.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 198.32.64.12

;

; housed in Japan, operated by WIDE

;

. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;NS &nbsp; &nbsp;M.ROOT-SERVERS.NET.

M.ROOT-SERVERS.NET. &nbsp; &nbsp; &nbsp;3600000 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; 202.12.27.33

; End of File

__________________________________________________




Agora vamos criar o /var/named/caching-example/localhost.zone&nbsp;





__________________________________________________






$TTL &nbsp; &nbsp;86400

$ORIGIN localhost.

@ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1D IN SOA &nbsp; &nbsp; &nbsp; @ root (

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;42 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; serial (d. adams)

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3H &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; refresh

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15M &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; retry

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1W &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; expiry

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1D ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; minimum



&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1D IN NS &nbsp; &nbsp; &nbsp; &nbsp;@

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1D IN A &nbsp; &nbsp; &nbsp; &nbsp; 127.0.0.1






__________________________________________________







Vamos criar o arquivo referente ao seu domínio /var/named/meudominio.com.br.domain:&nbsp;





__________________________________________________


$TTL &nbsp; &nbsp;86400

; Authoritative data for meudominio.com.br

;

@ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IN &nbsp; &nbsp; &nbsp; SOA localhost. root.meudominio.com.br. (

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2004102897 &nbsp; &nbsp; &nbsp;; Serial (yymmddxx)

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 10800 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; Refresh 3 hours

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3600 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; Retry &nbsp; 1 hour

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 36000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; Expire &nbsp;10 hours

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 86400 ) &nbsp; &nbsp; &nbsp; &nbsp; ; Minimum 24 hours

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IN &nbsp; &nbsp; &nbsp; NS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ns1.meudominio.com.br.

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IN &nbsp; &nbsp; &nbsp; NS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ns2.meudominio.com.br.



;

;Recebimento de mensagens de mail

;



meudominio.com.br. &nbsp; &nbsp; &nbsp; &nbsp;IN &nbsp; &nbsp; &nbsp;MX &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; mx

meudominio.com.br. &nbsp; &nbsp; &nbsp; &nbsp;IN &nbsp; &nbsp; &nbsp;MX &nbsp; &nbsp; 10 &nbsp; &nbsp; &nbsp; mx



;

; Hosts

;



localhost &nbsp; &nbsp; IN &nbsp; &nbsp; &nbsp; A &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 127.0.0.1

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IN &nbsp; &nbsp; &nbsp; HINFO &nbsp; &nbsp; &nbsp; &nbsp; INTEL/110 &nbsp; &nbsp; &nbsp; LINUX

www &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IN &nbsp; &nbsp; &nbsp; A &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 192.168.0.17 &nbsp; ; o ip da sua maquina

ns1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IN &nbsp; &nbsp; &nbsp; A &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 192.168.0.17 &nbsp; ; o ip da sua maquina

ns2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IN &nbsp; &nbsp; &nbsp; A &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 192.168.0.17 &nbsp; ; o ip da sua maquina

maquina-1 &nbsp; &nbsp; IN &nbsp; &nbsp; &nbsp; A &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 192.168.0.18 ; ip qualquer da rede

maquina-2 &nbsp; &nbsp; IN &nbsp; &nbsp; &nbsp; A &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 192.168.0.19 ; ip qualquer da rede

__________________________________________________





Iniciando o Bind



Caso você não tenha o arquivo /etc/rc.d/rc.bind crie-o com o seguinte conteúdo:






#!/bin/sh

# Start/stop/restart the BIND name server daemon (named).



# Start bind. In the past it was more secure to run BIND

# as a non-root user (for example, with '-u daemon'), but

# the modern version of BIND knows how uses to use the

# kernel's capability mechanism to drop all root privileges

# except the ability to bind() to a privileged port and set

# process resource limits, so -u should not be needed. If

# you wish to use it anyway, chown the /var/run/named

# directory to the non-root user.

#

# You might also consider running BIND in a "chroot jail",

# a discussion of which may be found in

# /usr/doc/Linux-HOWTOs/Chroot-BIND-HOWTO.



bind_start() {

&nbsp; if [ -x /usr/sbin/named ]; then

&nbsp; &nbsp; echo "Starting BIND: &nbsp;/usr/sbin/named"

&nbsp; &nbsp; /usr/sbin/named

&nbsp; fi

}



# Stop bind:

bind_stop() {

&nbsp; killall named

}



# Restart bind:

bind_restart() {

&nbsp; bind_stop

&nbsp; sleep 1

&nbsp; bind_start

}



case "$1" in

'start')

&nbsp; bind_start

&nbsp; ;;

'stop')

&nbsp; bind_stop

&nbsp; ;;

'restart')

;;

*)

&nbsp; echo "usage $0 start|stop|restart"

esac







Depois de salvo o arquivo com o conteúdo acima e dê permissão ao arquivo:&nbsp;



# chmod +x /etc/rc.d/rc.bind&nbsp;



Para iniciar o BIND basta digitar o seguinte comando:&nbsp;



# /etc/rc.d/rc.bind start&nbsp;






INICIANDO O BIND AUTOMATICAMENTE



Coloque a linha abaixo dentro do /etc/rc.d/rc.local:&nbsp;



/etc/rc.d/rc.bind start



Ou se preferir instale o pacote rcconf




# apt-get install rcconf





Digite no prompt de comando rcconf



# rcconf



Ira abrir a tela abaixo só marcar o serviço que ira iniciar&nbsp;









CONFIGURANDO SEU SERVIDOR



Após tudo feito vamos colocar o nosso servidor para usar o seu próprio DNS para navegar.&nbsp;




Edite o arquivo /etc/resolv.conf e coloque o seguinte conteúdo:&nbsp;



search meudominio.com.br

nameserver 192.168.0.17



OBS: altere o 192.168.0.17 para o seu IP.





TESTANDO O SEU SERVIDOR DNS



Depois de tudo pronto e configurado vamos testar.&nbsp;




Vamos efetuar um Ping no site do Google





Se a resposta for parecida com essa é por que esta funcionando perfeitamente




root@web:~# ping www.google.com.br

PING www.google.com.br (216.58.202.3) 56(84) bytes of data.

64 bytes from gru06s26-in-f3.1e100.net (216.58.202.3): icmp_seq=1 ttl=52 time=15.3 ms

64 bytes from gru06s26-in-f3.1e100.net (216.58.202.3): icmp_seq=2 ttl=52 time=11.6 ms

64 bytes from gru06s26-in-f3.1e100.net (216.58.202.3): icmp_seq=3 ttl=52 time=8.33 ms

^C