Differences

This shows you the differences between two versions of the page.

Link to this comparison view

instalacao_configuracao_dhcp_bind_dlz_samba4_pt_br [2019/08/08 15:23] (current)
Line 1: Line 1:
 +====== Configuração do dhcp trabalhando com o Bind DLZ no Samba 4  ======
 +
 +
 +Vamos instalar o dhcpd
 +<sxh bash>
 +aptitude install dhcp3-server -y
 +</sxh>
 +
 +Vamos criar um usuário para o dhcp
 +<sxh bash>
 +samba-tool user create dhcp dhcp@134* --description="Unprivileged user for DNS updates via DHCP server"
 +</sxh>
 +
 +Agora vamos inserir o dhcp no grupo do bind
 +<sxh bash>
 +samba-tool group addmembers DnsAdmins dhcp
 +</sxh>
 +
 +Agora vamos tirar a opção da senha expirar
 +<sxh bash>
 +samba-tool user setexpiry dhcp --noexpiry
 +</sxh>
 +
 +Agora vamos criar o script que vai passar os dados para ser criado o registro no dns
 +<sxh bash>
 +vim /etc/dhcp/update.sh
 +#!/bin/bash
 +# Variables
 +DOMAIN="douglasqsantos.com.br"
 +NAMESERVER="pdc.${DOMAIN}"
 +ZONE="${DOMAIN}"
 +USER="dhcp"
 +PASS="dhcp@134*"
 +REV="1.168.192.in-addr.arpa"
 +SAMBA_TOOL="/usr/local/samba/bin/samba-tool"
 +LOGGER="/usr/bin/logger"
 +ACTION=$1
 +IP=$2
 +HNAME=$3
 +IP_REV=$(echo ${IP} | cut -d '.' -f 4)
 +
 +
 +#Function for manipulate the hosts on dns server
 +add_host(){
 +${LOGGER} -s -p daemon.info -t dhcpd "Adding A record for host $HNAME with IP $IP to zone $ZONE on server $NAMESERVER"
 +${LOGGER} -s -p daemon.info -t dhcpd "Adding PTR record for ${IP_REV} with hostname $HNAME  to zone $REV on server $NAMESERVER"
 +${SAMBA_TOOL} dns add ${NAMESERVER} ${ZONE} ${HNAME} A ${IP} -U${USER} --password=${PASS}
 +${SAMBA_TOOL} dns add ${NAMESERVER} ${REV} ${IP_REV} PTR ${HNAME}.${DOMAIN} -U${USER} --password=${PASS}
 +}
 +
 +del_host(){
 +${LOGGER} -s -p daemon.info -t dhcpd "Removing A record for host $HNAME with IP $IP to zone $ZONE on server $NAMESERVER"
 +${LOGGER} -s -p daemon.info -t dhcpd "Removing PTR record for ${IP_REV} with hostname $HNAME  to zone $REV on server $NAMESERVER"
 +${SAMBA_TOOL} dns delete ${NAMESERVER} ${ZONE} ${HNAME} A ${IP} -U${USER} --password=${PASS}
 +${SAMBA_TOOL} dns delete ${NAMESERVER} ${REV} ${IP_REV} PTR ${HNAME}.${DOMAIN} -U${USER} --password=${PASS}
 +}
 +
 +update_host(){
 +del_host
 +add_host
 +}
 +
 +case "$1" in
 +add)
 +add_host
 +;;
 +delete)
 +del_host
 +;;
 +*)
 +echo "opcao validas: (add|del)"
 +;;
 +esac
 +</sxh>
 +
 +Agora vamos ajustar as permissões do script
 +<sxh bash>
 +chmod 755 /etc/dhcp/update.sh
 +</sxh>
 +
 +Agora vamos criar o arquivo de controle do dhcpd
 +<sxh bash>
 +vim /etc/dhcp/dhcpd.conf
 +# Internal subnet
 +subnet 192.168.1.0 netmask 255.255.255.0 {
 +  range 192.168.1.100 192.168.1.199;
 +  option subnet-mask 255.255.255.0;
 +  option routers 192.168.1.40;
 +  option domain-name "douglasqsantos.com.br";
 +  option domain-name-servers 192.168.1.49;
 +  option broadcast-address 192.168.1.255;
 +  default-lease-time 28800;
 +  max-lease-time 43200;
 +  authoritative;
 +
 +  on commit {
 +    set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
 +    set ClientName = pick-first-value(option host-name, host-decl-name);
 +    execute("/etc/dhcp/update.sh", "add", ClientIP, ClientName);
 +  }
 +
 +  on release {
 +    set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
 +    set ClientName = pick-first-value(option host-name, host-decl-name);
 +    execute("/etc/dhcp/update.sh", "delete", ClientIP, ClientName);
 +  }
 +
 +    on expiry {
 +    set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
 +    set ClientName = pick-first-value(option host-name, host-decl-name);
 +    execute("/etc/dhcp/update.sh", "delete", ClientIP, ClientName);
 +  }
 +}
 +</sxh>
 +
 +Agora vamos ajustar por qual interface o dhcp vai responder
 +<sxh bash>
 +vim /etc/default/isc-dhcp-server
 +[...]
 +INTERFACES="eth0"
 +</sxh>
 +
 +Agora precisamos reiniciar o dhcpd
 +<sxh bash>
 +/etc/init.d/isc-dhcp-server restart
 +</sxh>
  
Print/export
QR Code
QR Code instalacao_configuracao_dhcp_bind_dlz_samba4_pt_br (generated for current page)