Bind9 slave em chroot no Debian Lenny
Instalação e configuração do Bind9 slave em chroot no Debian Lenny GNU/Linux utilizando um script pronto. Fácil, rápido e simples!
Parte 2: Script de instalação e configuração automática do Bind9
Usando seu editor de textos predileto, salve o conteúdo abaixo num arquivo e dê o nome de bind9.sh. Em seguida siga as instruções da página anterior.
Conteúdo do script:
Para facilitar sua vida, você pode fazer o download do script aqui.
Conteúdo do script:
#!/bin/sh
#############################################
#Autor:Douglas Q. dos Santos
#Data:03/03/2010
#Email:douglashx@gmail.com
#Preparação de servidor DNS Slave
#############################################
#-- COMANDOS ------------------------------------
APTITUDE=$(which aptitude)
CAT=$(which cat)
CHMOD=$(which chmod)
CHOWN=$(which chown)
DATA=$(which date)
LN=$(which ln)
MKDIR=$(which mkdir)
MKNOD=$(which mknod)
MV=$(which mv)
SLEEP=$(which sleep)
CUT=$(which cut)
#------------------------------------------------
#-- CAMINHOS ------------------------------------
PATH_BIND="/var/lib/named"
#------------------------------------------------
#-- VARIÁVEIS -----------------------------------
echo -n "Forneça o nome do domínio a ser configurado (dominio.com.br): "
read DOMAIN
echo -n "Forneça a faixa de IP da rede valida (ip/mask): "
read NETWOTK_RANGE
echo -n "Forneça o endereço IP do servidor Master (ip): "
read NS1_IP
echo
#------------------------------------------------
#-- INSTALAÇÃO DO PACOTE ------------------------
echo "A instalação será iniciada em 5 segundos"
${SLEEP} 5
${APTITUDE} update
${APTITUDE} install bind9 dnsutils -y
/etc/init.d/bind9 stop
#------------------------------------------------
#-- ARVORE DE DIRETÓRIOS ------------------------
${MKDIR} -p ${PATH_BIND}/etc
${MKDIR} -p ${PATH_BIND}/dev
${MKDIR} -p ${PATH_BIND}/var/cache/bind/slave
${MKDIR} -p ${PATH_BIND}/var/run/bind/run
${MKNOD} ${PATH_BIND}/dev/null c 1 3
${MKNOD} ${PATH_BIND}/dev/random c 1 8
#Ajustando permissões
${CHMOD} 666 ${PATH_BIND}/dev/null ${PATH_BIND}/dev/random
${CHOWN} -R bind:bind ${PATH_BIND}/var/*
${MV} /etc/bind ${PATH_BIND}/etc
${LN} -s ${PATH_BIND}/etc/bind /etc/bind
${CHOWN} -R bind:bind ${PATH_BIND}/etc/bind
#-- AJUSTANDO O ARQUIVO /etc/default/bind9 ------
${CAT} <<EOF > /etc/default/bind9
#/etc/default/bind9
RESOLVCONF=yes
# startup options for the server
#OPTIONS="-u bind"
OPTIONS="-u bind -t ${PATH_BIND}"
EOF
#------------------------------------------------
#-- AJUSTANDO O ARQUIVO /etc/resolv.conf --------
${CAT} <<EOF > /etc/resolv.conf
domain ${DOMAIN}
nameserver 127.0.0.1
EOF
#------------------------------------------------
#Extraindo o reverso do servidor Master
REV3=`echo ${NS1_IP} | cut -d '.' -f 3`
REV2=`echo ${NS1_IP} | cut -d '.' -f 2`
REV1=`echo ${NS1_IP} | cut -d '.' -f 1`
IP_REVERSE=${REV3}.${REV2}.${REV1}
#-- AJUSTANDO O ARQUIVO /srv/bind/etc/bind/named.conf.options ----
${MV} ${PATH_BIND}/etc/bind/named.conf.options ${PATH_BIND}/etc/bind/named.conf.options.orig
${CAT} <<EOF > ${PATH_BIND}/etc/bind/named.conf.options
options {
directory "/var/cache/bind";
// If there is a firewall between you and nameservers you want
// to talk to, you might need to uncomment the query-source
// directive below. Previous versions of BIND always asked
// questions using port 53, but BIND 8.1 and later use an unprivileged
// port by default.
// query-source address * port 53;
// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder.
// forwarders {
// 0.0.0.0;
// };
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
listen-on { 127.0.0.1/32; ${NETWOTK_RANGE}; };
allow-query { any; };
allow-recursion { 127.0.0.1/32; };
allow-transfer { none; };
version "Não Disponível";
};
EOF
#------------------------------------------------
#-- AJUSTANDO O ARQUIVO /srv/bind/etc/bind/named.conf.local -------------------
${MV} ${PATH_BIND}/etc/bind/named.conf ${PATH_BIND}/etc/bind/named.conf.orig
${CAT} <<EOF > ${PATH_BIND}/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";
};
zone "${DOMAIN}" {
type slave;
file "slave/db.${DOMAIN}";
masters { ${NS1_IP}; };
allow-transfer { none; };
allow-update { none; };
};
zone "${IP_REVERSE}.in-addr.arpa" {
type slave;
file "slave/db.${IP_REVERSE}";
masters { ${NS1_IP}; };
allow-transfer { none; };
allow-update { none; };
};
include "/etc/bind/named.conf.local";
EOF
#------------------------------------------------
#-- REINICIANDO OS SERVIÇOS ----------------------
/etc/init.d/bind9 stop
/etc/init.d/bind9 start
#------------------------------------------------
#-- MENSAGEM DE FINALIZAÇÃO ---------------------
echo
echo "INSTALAÇÃO FINALIZADA"
echo "Faca os ajustes necessários e reinicie o serviço *bind9*"
echo
#------------------------------------------------
exit 0
#############################################
#Autor:Douglas Q. dos Santos
#Data:03/03/2010
#Email:douglashx@gmail.com
#Preparação de servidor DNS Slave
#############################################
#-- COMANDOS ------------------------------------
APTITUDE=$(which aptitude)
CAT=$(which cat)
CHMOD=$(which chmod)
CHOWN=$(which chown)
DATA=$(which date)
LN=$(which ln)
MKDIR=$(which mkdir)
MKNOD=$(which mknod)
MV=$(which mv)
SLEEP=$(which sleep)
CUT=$(which cut)
#------------------------------------------------
#-- CAMINHOS ------------------------------------
PATH_BIND="/var/lib/named"
#------------------------------------------------
#-- VARIÁVEIS -----------------------------------
echo -n "Forneça o nome do domínio a ser configurado (dominio.com.br): "
read DOMAIN
echo -n "Forneça a faixa de IP da rede valida (ip/mask): "
read NETWOTK_RANGE
echo -n "Forneça o endereço IP do servidor Master (ip): "
read NS1_IP
echo
#------------------------------------------------
#-- INSTALAÇÃO DO PACOTE ------------------------
echo "A instalação será iniciada em 5 segundos"
${SLEEP} 5
${APTITUDE} update
${APTITUDE} install bind9 dnsutils -y
/etc/init.d/bind9 stop
#------------------------------------------------
#-- ARVORE DE DIRETÓRIOS ------------------------
${MKDIR} -p ${PATH_BIND}/etc
${MKDIR} -p ${PATH_BIND}/dev
${MKDIR} -p ${PATH_BIND}/var/cache/bind/slave
${MKDIR} -p ${PATH_BIND}/var/run/bind/run
${MKNOD} ${PATH_BIND}/dev/null c 1 3
${MKNOD} ${PATH_BIND}/dev/random c 1 8
#Ajustando permissões
${CHMOD} 666 ${PATH_BIND}/dev/null ${PATH_BIND}/dev/random
${CHOWN} -R bind:bind ${PATH_BIND}/var/*
${MV} /etc/bind ${PATH_BIND}/etc
${LN} -s ${PATH_BIND}/etc/bind /etc/bind
${CHOWN} -R bind:bind ${PATH_BIND}/etc/bind
#-- AJUSTANDO O ARQUIVO /etc/default/bind9 ------
${CAT} <<EOF > /etc/default/bind9
#/etc/default/bind9
RESOLVCONF=yes
# startup options for the server
#OPTIONS="-u bind"
OPTIONS="-u bind -t ${PATH_BIND}"
EOF
#------------------------------------------------
#-- AJUSTANDO O ARQUIVO /etc/resolv.conf --------
${CAT} <<EOF > /etc/resolv.conf
domain ${DOMAIN}
nameserver 127.0.0.1
EOF
#------------------------------------------------
#Extraindo o reverso do servidor Master
REV3=`echo ${NS1_IP} | cut -d '.' -f 3`
REV2=`echo ${NS1_IP} | cut -d '.' -f 2`
REV1=`echo ${NS1_IP} | cut -d '.' -f 1`
IP_REVERSE=${REV3}.${REV2}.${REV1}
#-- AJUSTANDO O ARQUIVO /srv/bind/etc/bind/named.conf.options ----
${MV} ${PATH_BIND}/etc/bind/named.conf.options ${PATH_BIND}/etc/bind/named.conf.options.orig
${CAT} <<EOF > ${PATH_BIND}/etc/bind/named.conf.options
options {
directory "/var/cache/bind";
// If there is a firewall between you and nameservers you want
// to talk to, you might need to uncomment the query-source
// directive below. Previous versions of BIND always asked
// questions using port 53, but BIND 8.1 and later use an unprivileged
// port by default.
// query-source address * port 53;
// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder.
// forwarders {
// 0.0.0.0;
// };
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
listen-on { 127.0.0.1/32; ${NETWOTK_RANGE}; };
allow-query { any; };
allow-recursion { 127.0.0.1/32; };
allow-transfer { none; };
version "Não Disponível";
};
EOF
#------------------------------------------------
#-- AJUSTANDO O ARQUIVO /srv/bind/etc/bind/named.conf.local -------------------
${MV} ${PATH_BIND}/etc/bind/named.conf ${PATH_BIND}/etc/bind/named.conf.orig
${CAT} <<EOF > ${PATH_BIND}/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";
};
zone "${DOMAIN}" {
type slave;
file "slave/db.${DOMAIN}";
masters { ${NS1_IP}; };
allow-transfer { none; };
allow-update { none; };
};
zone "${IP_REVERSE}.in-addr.arpa" {
type slave;
file "slave/db.${IP_REVERSE}";
masters { ${NS1_IP}; };
allow-transfer { none; };
allow-update { none; };
};
include "/etc/bind/named.conf.local";
EOF
#------------------------------------------------
#-- REINICIANDO OS SERVIÇOS ----------------------
/etc/init.d/bind9 stop
/etc/init.d/bind9 start
#------------------------------------------------
#-- MENSAGEM DE FINALIZAÇÃO ---------------------
echo
echo "INSTALAÇÃO FINALIZADA"
echo "Faca os ajustes necessários e reinicie o serviço *bind9*"
echo
#------------------------------------------------
exit 0
Para facilitar sua vida, você pode fazer o download do script aqui.
Muito interessante sua iniciativa do script! Muito obrigado. Isso com certeza vai ajudar muita gente!
Acabei de configurar meu primeiro bind (no Debian Lenny)... (Eu fiz na unha mesmo... até porque prefiro assim...)
peguei vários tutoriais (daqui do VOL e outros de fora).
Uma dúvida não relacionada ao seu artigo:
Seguindo a sugestão de
http://www.ubuntu-ac.org/archives/559/comment-page-1#comment-669
Adicionei o servidor DNS do Google.
Queria saber se para adicionar ainda outros servidores DNS, é no mesmo arquivo, da mesma forma...
E queria saber se você ou outro colega daqui do VOL tem outra sugestão de Servidor DNS...
Abraço,
Hideo