Configurando um servidor DNS
Por:
Flavio Torres - ftorres[@]ymail.com
Publicado em: 07/02/2006
Configurando um DNS CHROOTED Primário
e Reverso para o seu site.
Vários artigos existem sobre DNS, primário ou secundário,
este é apenas mais um.
Porém, aqui encontra apenas o necessário para subir um
DNS e hospedar um site em um servidor que tenha IP estático, não
estou abordando detalhes sobre cada opção do DNS, já
que, como disse, existem inúmeros pela internet.
Sobre o sistema:
- Debian 3.1 stable
- kernel 2.6.8.2
- bind-9.2.4
Apenas tradução das siglas:
| SOA |
Start of Authority |
| NS |
Name Server |
| PTR |
Address to name mapping |
| CNAME |
Cannonical name (aliases) |
| TXT |
Textual information |
| RP |
Responsible person |
| MX |
Mail exchange |
| HINFO |
Host information |
O que fazer no arquivo named.conf?
Note no final do arquivo, as linhas que contém "empresa.com.br",
a primeira trata-se do dns em sí, a segunda é o dns reverso:
linuxuser@proxy:~$ cat /etc/bind/named.conf
// This is the primary configuration file for the BIND DNS server
named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information
on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
//
// If you are just adding zones, please do that in /etc/bind/named.conf.local
include "/etc/bind/named.conf.options";
// prime the server with knowledge of the root servers
zone "." {
type hint;
file "/etc/bind/db.root";
};
// be authoritative for the localhost forward and reverse zones,
and for
// broadcast zones as per RFC 1912
zone "localhost" {
type master;
file "/etc/bind/db.local";
};
zone "127.in-addr.arpa" {
type master;
file "/etc/bind/db.127";
};
zone "0.in-addr.arpa" {
type master;
file "/etc/bind/db.0";
};
zone "255.in-addr.arpa" {
type master;
file "/etc/bind/db.255";
};
//dns primario
zone "empresa.com.br" {
notify no;
type master;
file "/etc/bind/empresa.com.br";
};
//dns reverso, ex para: 200.0.10.20 será: 20.10.0.200.in-addr.arpa
zone "XXX.XX.XXX.200.in-addr.arpa" {
notify no;
type master;
file "/etc/bind/empresa.com.br.rev";
};
// zone "com" { type delegation-only; };
// zone "net" { type delegation-only; };
// From the release notes:
// Because many of our users are uncomfortable receiving undelegated
answers
// from root or top level domains, other than a few for whom that
behaviour
// has been trusted and expected for quite some length of time,
we have now
// introduced the "root-delegations-only" feature which
applies delegation-only
// logic to all top level domains, and to the root domain. An exception
list
// should be specified, including "MUSEUM" and "DE",
and any other top level
// domains from whom undelegated responses are expected and trusted.
// root-delegation-only exclude { "DE"; "MUSEUM";
};
include "/etc/bind/named.conf.local";
|
Agora, o conteúdo do arquivo empresa.com.br:
linuxuser@proxy:~$ cat /etc/bind/empresa.com.br
;
; BIND data file for local loopback interface
;
$TTL 86400
@ IN SOA ns.empresa.com.br. root.empresa.com.br. (
1 ; Serial
3600 ; Refresh
900 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.empresa.com.br.
@ IN A 200.XXX.XX.XXX
www IN A 200.XXX.XX.XXX
ftp IN A 200.XXX.XX.XXX
ns IN A 200.XXX.XX.XXX
|
O arquivo empresa.com.br.rev:
linuxuser@proxy:~$ cat /etc/bind/empresa.com.br.rev
;
; BIND data file for local loopback interface
;
$TTL 86400
@ IN SOA ns.empresa.com.br. root.empresa.com.br. (
1 ; Serial
3600 ; Refresh
900 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
IN NS ns.empresa.com.br.
11 IN PTR www.empresa.com.br
|
E por fim, alterar o resolv.conf
linuxuser@proxy:~$ cat /etc/resolv.conf
search empresa.com.br
nameserver 192.168.0.1
Reinicie o bind, e depois é so testar:
linuxuser@proxy:~$ nslookup empresa.com.br
Server: 192.168.0.1
Address: 192.168.0.1#53
Name: empresa.com.br
Address: 200.XXX.XX.XXX
linuxuser@proxy:~$ dig ns empresa.com.br
; <<>> DiG 9.2.0 <<>> ns
empresa.com.br
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11701
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;empresa.com.br. IN NS
;; ANSWER SECTION:
empresa.com.br. 83645 IN NS ns.empresa.com.br.
;; ADDITIONAL SECTION:
ns.empresa.com.br. 75874 IN A 200.XXX.XX.XXX
;; Query time: 2 msec
;; SERVER: 192.168.0.1#53(192.168.0.1)
;; WHEN: Tue Feb 7 13:16:44 2006
;; MSG SIZE rcvd: 71
linuxuser@proxy:~$ nslookup ns.empresa.com.br
Note: nslookup is deprecated and may be removed
from future releases.
Consider using the `dig' or `host' programs instead. Run nslookup with
the `-sil[ent]' option to prevent this message from appearing.
Server: 192.168.0.2
Address: 192.168.0.2#53
Non-authoritative answer:
Name: ns.empresa.com.br
Address: 200.XXX.XX.XXX
linuxuser@proxy:~$ nslookup 200.XXX.XX.XXX
Server: 200.204.0.10
Address: 200.204.0.10#53
Non-authoritative answer:
XXX.XX.XXX.200.in-addr.arpa name = 200-XXX-XX-XXX.dsl.telesp.net.br.
Não esqueça de liberar no firewall a porta 53.
Pronto, agora é só instalar o apache, e mandar bala
no registro.br.
CHROOTED
Com um pouco mais de tempo, podemos usufruir de uma melhor segurança
configurando o DNS em modo "chroot", protegendo contra possíveis
invasões. O ideal é fazer com que o daemon
do BIND rode em um ambiente protegido, mais conhecido como "in
jail", e também como um usuário não privilegiado.
Caso um invasor consiga, durante um ataque, acesso à sua máquina,
ele não poderá navegar na estrutura de diretórios
acima do diretório no qual o bind foi "enjaulado".
Dentro do diretório onde o bind estiver "enjaulado"
existirão apenas os arquivos necessários para a utilização
do bind, não deixando brechas para a execução
de, por exemplo, um shell (/bin/sh) caso sua máquina seja atacada.
Presumindo que o seu dns já esteja corretamente configurado,
basta fazer:
mkdir -p /var/named/chroot/etc
mkdir -p /var/named/chroot/dev
mkdir -p /var/named/chroot/var/cache/bind
mkdir -p /var/named/chroot/var/run/bind/run
mv /etc/bind* /var/named/chroot/etc/
ln -s /var/named/chroot/etc/bind /etc/bind
mknod /var/named/chroot/dev/null c 1 3
mknod /var/named/chroot/dev/random c 1 8
chmod 666 /var/named/chroot/dev/null
chmod 666 /var/named/chroot/dev/random
chown -R nobody:nogroup /var/named/chroot/var/*
chown -R nobody:nogroup /var/named/chroot/etc/bind
Alterar o conteúdo do arquivo /etc/default/bind9 para
OPTIONS="-u nobody -t /var/named/chroot"
Pronto, reinicie o bind e confirme:
# ps -efwww | grep named
nobody 5618 1 0 22:40 ? 00:00:00 /usr/sbin/named -u
nobody -t /var/named/chroot
É isto! ;)
|