+-------------------+ +-------------------+ | 172.16.200.80/24 | | 172.16.200.90/24 | | ns1.rascunhos.net |<----->| ns2.rascunhos.net | | Master | | Slave | +-------------------+ +-------------------+
# aptitude install bind9 bind9utils dnsutils
A fim de termos uma maior segurança em relação às mudanças do arquivo /etc/resolv.conf, adicione um atributo de proteção a ele, não permitindo qualquer tipo de alteração:
# echo "nameserver 127.0.0.1" > /etc/resolv.conf
# chattr +i /etc/resolv.conf
Vamos configurar as duas zonas de nossos domínios no arquivo /etc/bind/named.conf.local
# vim /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 "rascunhos.net" { type master; file "db.rascunhos"; allow-transfer { 172.16.200.90; }; notify yes; also-notify { 172.16.200.90; }; }; zone "200.16.172.in-addr.arpa" { type master; file "rev.rascunhos"; allow-transfer { 172.16.200.90; }; notify yes; also-notify { 172.16.200.90; }; };
Agora criaremos o banco de dados de registros de DNS direta e reversa
# vim /var/cache/bind/db.rascunhos $TTL 86400 @ IN SOA ns1.rascunhos.net. root.rascunhos.net. ( 2015052001 ;Serial 3600 ;Refresh 1800 ;Retry 604800 ;Expire 86400 ;Minimum TTL ) ; @ IN A 172.16.200.205 ;sitio: www.rascunhos.net ; @ IN NS ns1.rascunhos.net. @ IN NS ns2.rascunhos.net. @ IN MX 10 mail.rascunhos.net. ; ns1.rascunhos.net. IN A 172.16.200.80 ns2.rascunhos.net. IN A 172.16.200.90 ; mail.rascunhos.net. IN A 172.16.200.240 smtp.rascunhos.net. IN CNAME mail.rascunhos.net. pop.rascunhos.net. IN CNAME mail.rascunhos.net. imap.rascunhos.net. IN CNAME mail.rascunhos.net. ; www.rascunhos.net. IN CNAME @ ftp.rascunhos.net. IN CNAME @
# vim /var/cache/bind/rev.rascunhos $TTL 86400 @ IN SOA ns1.rascunhos.net. root.rascunhos.net. ( 2015052001 ;Serial 3600 ;Refresh 1800 ;Retry 604800 ;Expire 86400 ;Minimum TTL ) ; @ IN NS ns1.rascunhos.net. @ IN NS ns2.rascunhos.net. ; 80 IN PTR ns1.rascunhos.net. 90 IN PTR ns2.rascunhos.net. ; 240 IN PTR mail.rascunhos.net.
Agora vamos checar se tem algum erro em nossa configuração
# named-checkconf
# named-checkzone rascunhos.net /var/cache/bind/db.rascunhos zone rascunhos.net/IN: loaded serial 2015052001 OK
# named-checkzone 200.16.172.in-addr.arpa /var/cache/bind/rev.rascunhos zone 200.16.172.in-addr.arpa/IN: loaded serial 2015052001 OK
Reiniciando os serviços
# service bind9 restart [ ok ] Stopping domain name service...: bind9. [ ok ] Starting domain name service...: bind9.
Verificando as portas
# netstat -nat | grep 53 tcp 0 0 172.16.200.80:53 0.0.0.0:* OUÇA tcp 0 0 127.0.0.1:53 0.0.0.0:* OUÇA tcp 0 0 127.0.0.1:953 0.0.0.0:* OUÇA tcp6 0 0 :::53 :::* OUÇA tcp6 0 0 ::1:953 :::* OUÇA
Checando os processos do bind
# ps -ef | grep bind bind 2310 1 0 20:31 ? 00:00:00 /usr/sbin/named -u bind root 2347 2003 0 20:37 pts/0 00:00:00 grep bind
Agora vamos checar se o Bind já está resolvendo
# dig -t SOA rascunhos.net ; <<>> DiG 9.8.4-rpz2+rl005.12-P1 <<>> -t SOA rascunhos.net ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31649 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2 ;; QUESTION SECTION: ;rascunhos.net. IN SOA ;; ANSWER SECTION: rascunhos.net. 86400 IN SOA ns1.rascunhos.net. root.rascunhos.net. 2015052001 3600 1800 604800 86400 ;; AUTHORITY SECTION: rascunhos.net. 86400 IN NS ns2.rascunhos.net. rascunhos.net. 86400 IN NS ns1.rascunhos.net. ;; ADDITIONAL SECTION: ns1.rascunhos.net. 86400 IN A 172.16.200.80 ns2.rascunhos.net. 86400 IN A 172.16.200.90 ;; Query time: 4 msec ;; SERVER: 127.0.0.1#53(127.0.0.1) ;; WHEN: Wed May 20 20:35:24 2015 ;; MSG SIZE rcvd: 140
# dig -t MX rascunhos.net ; <<>> DiG 9.8.4-rpz2+rl005.12-P1 <<>> -t MX rascunhos.net ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21814 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3 ;; QUESTION SECTION: ;rascunhos.net. IN MX ;; ANSWER SECTION: rascunhos.net. 86400 IN MX 10 mail.rascunhos.net. ;; AUTHORITY SECTION: rascunhos.net. 86400 IN NS ns2.rascunhos.net. rascunhos.net. 86400 IN NS ns1.rascunhos.net. ;; ADDITIONAL SECTION: mail.rascunhos.net. 86400 IN A 172.16.200.240 ns1.rascunhos.net. 86400 IN A 172.16.200.80 ns2.rascunhos.net. 86400 IN A 172.16.200.90 ;; Query time: 3 msec ;; SERVER: 127.0.0.1#53(127.0.0.1) ;; WHEN: Wed May 20 20:36:03 2015 ;; MSG SIZE rcvd: 136
# dig +short -x 172.16.200.240
mail.rascunhos.net.
# aptitude install bind9 bind9utils dnsutils
A fim de termos uma maior segurança em relação às mudanças do arquivo /etc/resolv.conf, adicione um atributo de proteção a ele, não permitindo qualquer tipo de alteração:
# echo "nameserver 127.0.0.1" > /etc/resolv.conf
# chattr +i /etc/resolv.conf
Vamos configurar as duas zonas de nossos domínios no arquivo /etc/bind/named.conf.local do nosso Slave
# vim /etc/bind/named.conf.local zone "rascunhos.net" { type slave; file "db.rascunhos"; masters { 172.16.200.80; }; }; zone "200.16.172.in-addr.arpa" { type slave; file "rev.rascunhos"; masters { 172.16.200.80; }; };
Vamos reiniciar o Bind e checar os logs para acompanhar a tranferência de zona
# service bind9 restart [....] Stopping domain name service...: bind9waiting for pid 1903 to die . ok [ ok ] Starting domain name service...: bind9.
# tail /var/log/daemon.log May 20 20:46:12 ns2 named[2144]: zone 0.in-addr.arpa/IN: loaded serial 1 May 20 20:46:12 ns2 named[2144]: zone 127.in-addr.arpa/IN: loaded serial 1 May 20 20:46:12 ns2 named[2144]: zone 200.16.172.in-addr.arpa/IN: loaded serial 2015052001 May 20 20:46:12 ns2 named[2144]: zone 255.in-addr.arpa/IN: loaded serial 1 May 20 20:46:12 ns2 named[2144]: zone localhost/IN: loaded serial 2 May 20 20:46:12 ns2 named[2144]: zone rascunhos.net/IN: loaded serial 2015052001 May 20 20:46:12 ns2 named[2144]: managed-keys-zone ./IN: loaded serial 2 May 20 20:46:12 ns2 named[2144]: running May 20 20:46:12 ns2 named[2144]: zone 200.16.172.in-addr.arpa/IN: sending notifies (serial 2015052001) May 20 20:46:12 ns2 named[2144]: zone rascunhos.net/IN: sending notifies (serial 2015052001)
# ls -la /var/cache/bind/ total 24 drwxrwxr-x 2 root bind 4096 Mai 20 20:46 . drwxr-xr-x 9 root root 4096 Mai 20 19:54 .. -rw-r--r-- 1 bind bind 555 Mai 20 20:46 db.rascunhos -rw-r--r-- 1 bind bind 698 Mai 20 19:54 managed-keys.bind -rw-r--r-- 1 bind bind 512 Mai 20 19:54 managed-keys.bind.jnl -rw-r--r-- 1 bind bind 436 Mai 20 20:46 rev.rascunhos
# cat /var/cache/bind/db.rascunhos $ORIGIN . $TTL 86400 ; 1 day rascunhos.net IN SOA ns1.rascunhos.net. root.rascunhos.net. ( 2015052001 ; serial 3600 ; refresh (1 hour) 1800 ; retry (30 minutes) 604800 ; expire (1 week) 86400 ; minimum (1 day) ) NS ns1.rascunhos.net. NS ns2.rascunhos.net. A 172.16.200.205 MX 10 mail.rascunhos.net. $ORIGIN rascunhos.net. ftp CNAME rascunhos.net. imap CNAME mail mail A 172.16.200.240 ns1 A 172.16.200.80 ns2 A 172.16.200.90 pop CNAME mail smtp CNAME mail www CNAME rascunhos.net.
# cat /var/cache/bind/rev.rascunhos $ORIGIN . $TTL 86400 ; 1 day 200.16.172.in-addr.arpa IN SOA ns1.rascunhos.net. root.rascunhos.net. ( 2015052001 ; serial 3600 ; refresh (1 hour) 1800 ; retry (30 minutes) 604800 ; expire (1 week) 86400 ; minimum (1 day) ) NS ns1.rascunhos.net. NS ns2.rascunhos.net. $ORIGIN 200.16.172.in-addr.arpa. 240 PTR mail.rascunhos.net. 80 PTR ns1.rascunhos.net. 90 PTR ns2.rascunhos.net.
Como podemos ver, já houve a tranferência das zonas
Vamos para mas um teste para termos certeza da tranferência das zonas
Vamos fazer uma ateração no master, reiniciar os serviços e acompanhar com o tcpdump
# vim /var/cache/bind/db.rascunhos $TTL 86400 @ IN SOA ns1.rascunhos.net. root.rascunhos.net. ( 2015052002 ;Serial 3600 ;Refresh 1800 ;Retry 604800 ;Expire 86400 ;Minimum TTL ) ; @ IN A 172.16.200.205 ;sitio: www.rascunhos.net ; @ IN NS ns1.rascunhos.net. @ IN NS ns2.rascunhos.net. @ IN MX 10 mail.rascunhos.net. ; ns1.rascunhos.net. IN A 172.16.200.80 ns2.rascunhos.net. IN A 172.16.200.90 ; mail.rascunhos.net. IN A 172.16.200.240 smtp.rascunhos.net. IN CNAME mail.rascunhos.net. pop.rascunhos.net. IN CNAME mail.rascunhos.net. imap.rascunhos.net. IN CNAME mail.rascunhos.net. ; www.rascunhos.net. IN CNAME @ ftp.rascunhos.net. IN CNAME @ ; gateway.rascunhos.net. IN A 172.16.200.254
Observe que alterei o serial e adicionei o gateway na minha zona
No master
# aptitude install tcpdump
# service bind9 restart
No slave
# service bind9 restart
No master
# tcpdump -i eth0 -n port 53 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes 20:59:13.898759 IP 172.16.200.80.42715 > 172.16.200.90.53: 24504 notify [b2&3=0x2400] [1a] SOA? 200.16.172.in-addr.arpa. (99) 20:59:13.899299 IP 172.16.200.90.53 > 172.16.200.80.42715: 24504 notify* 0/0/0 (41) 20:59:14.400422 IP 172.16.200.80.27455 > 172.16.200.90.53: 60765 notify [b2&3=0x2400] [1a] SOA? rascunhos.net. (76) 20:59:14.401170 IP 172.16.200.90.53 > 172.16.200.80.27455: 60765 notify* 0/0/0 (31) 20:59:14.402509 IP 172.16.200.90.39997 > 172.16.200.80.53: 40814 [1au] SOA? rascunhos.net. (42) 20:59:14.403195 IP 172.16.200.80.53 > 172.16.200.90.39997: 40814* 1/2/3 SOA (151) 20:59:14.404314 IP 172.16.200.90.51003 > 172.16.200.80.53: Flags [S], seq 1595886008, win 14600, options [mss 1460,sackOK,TS val 660006 ecr 0,nop,wscale 3], length 0 20:59:14.404384 IP 172.16.200.80.53 > 172.16.200.90.51003: Flags [S.], seq 4210188617, ack 1595886009, win 14480, options [mss 1460,sackOK,TS val 687881 ecr 660006,nop,wscale 3], length 0 20:59:14.404900 IP 172.16.200.90.51003 > 172.16.200.80.53: Flags [.], ack 1, win 1825, options [nop,nop,TS val 660006 ecr 687881], length 0 20:59:14.405275 IP 172.16.200.90.51003 > 172.16.200.80.53: Flags [P.], seq 1:3, ack 1, win 1825, options [nop,nop,TS val 660006 ecr 687881], length 2 20:59:14.405298 IP 172.16.200.80.53 > 172.16.200.90.51003: Flags [.], ack 3, win 1810, options [nop,nop,TS val 687882 ecr 660006], length 0 20:59:14.406228 IP 172.16.200.90.51003 > 172.16.200.80.53: Flags [P.], seq 3:79, ack 1, win 1825, options [nop,nop,TS val 660006 ecr 687882], length 760 [b2&3=0x1] [1a] [0q] [2418au] (74) 20:59:14.406247 IP 172.16.200.80.53 > 172.16.200.90.51003: Flags [.], ack 79, win 1810, options [nop,nop,TS val 687882 ecr 660006], length 0 20:59:14.407748 IP 172.16.200.80.53 > 172.16.200.90.51003: Flags [P.], seq 1:348, ack 79, win 1810, options [nop,nop,TS val 687882 ecr 660006], length 34720072* 15/0/0 SOA, A 172.16.200.205, NS ns1.rascunhos.net., NS ns2.rascunhos.net., MX mail.rascunhos.net. 10, CNAME rascunhos.net., A 172.16.200.254, CNAME mail.rascunhos.net., A 172.16.200.240, A 172.16.200.80, A 172.16.200.90, CNAME mail.rascunhos.net., CNAME mail.rascunhos.net., CNAME rascunhos.net., SOA (345) 20:59:14.408419 IP 172.16.200.90.51003 > 172.16.200.80.53: Flags [.], ack 348, win 1959, options [nop,nop,TS val 660007 ecr 687882], length 0 20:59:14.409382 IP 172.16.200.90.51003 > 172.16.200.80.53: Flags [F.], seq 79, ack 348, win 1959, options [nop,nop,TS val 660007 ecr 687882], length 0 20:59:14.409673 IP 172.16.200.80.53 > 172.16.200.90.51003: Flags [F.], seq 348, ack 80, win 1810, options [nop,nop,TS val 687883 ecr 660007], length 0 20:59:14.410731 IP 172.16.200.90.51003 > 172.16.200.80.53: Flags [.], ack 349, win 1959, options [nop,nop,TS val 660007 ecr 687883], length 0
No slave
# cat /var/cache/bind/db.rascunhos $TTL 86400 @ IN SOA ns1.rascunhos.net. root.rascunhos.net. ( 2015052002 ;Serial 3600 ;Refresh 1800 ;Retry 604800 ;Expire 86400 ;Minimum TTL ) ; @ IN A 172.16.200.205 ;sitio: www.rascunhos.net ; @ IN NS ns1.rascunhos.net. @ IN NS ns2.rascunhos.net. @ IN MX 10 mail.rascunhos.net. ; ns1.rascunhos.net. IN A 172.16.200.80 ns2.rascunhos.net. IN A 172.16.200.90 ; mail.rascunhos.net. IN A 172.16.200.240 smtp.rascunhos.net. IN CNAME mail.rascunhos.net. pop.rascunhos.net. IN CNAME mail.rascunhos.net. imap.rascunhos.net. IN CNAME mail.rascunhos.net. ; www.rascunhos.net. IN CNAME @ ftp.rascunhos.net. IN CNAME @ ; gateway.rascunhos.net. IN A 172.16.200.254
Tudo certo…