0% found this document useful (0 votes)
2 views9 pages

DDNS PASO A PASO_

The document provides a step-by-step guide for setting up Dynamic DNS (DDNS) using BIND9 and ISC DHCP server. It includes configuration details for both server and client IP settings, as well as scripts for configuring DNS zones and DHCP options. The guide covers both master and slave configurations, along with instructions for setting up DDNS keys and DHCP server settings.

Uploaded by

lghugo884
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

DDNS PASO A PASO_

The document provides a step-by-step guide for setting up Dynamic DNS (DDNS) using BIND9 and ISC DHCP server. It includes configuration details for both server and client IP settings, as well as scripts for configuring DNS zones and DHCP options. The guide covers both master and slave configurations, along with instructions for setting up DDNS keys and DHCP server settings.

Uploaded by

lghugo884
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

DDNS PASO A PASO:

1- Tenemos el servidor con Ip:


​ auto enp0s3
iface enp0s3 inet static
address 172.26.0.1
netmask 255.255.0.0
network 172.26.0.0

Y el cliente con:
auto enp0s3
iface enp0s3 inet static
address 172.26.0.25
netmask 255.255.0.0
gateway 172.26.0.1

2- Antes de eso en adaptador puente descargamos dos paquetes en el servidor:

-​ bind9
-​ isc-dhcp-server

Luego de esto ponemos red interna y empezamos con el script:

#!/bin/bash
clear

# 1-Requirements
apt update
apt install bind9 bind9-utils

clear

directa() {

################ /etc/bind/named.conf.options
echo "### /etc/bind/named.conf.options ###"

read -p "Introduce la Ip red con el prefijo [ 172.26.0.0/16 ]: " network

echo "options {" > /etc/bind/named.conf.options


echo "​directory \"/var/cache/bind\";" >> /etc/bind/named.conf.options
echo "​// If there is a firewall between you and nameservers you want" >>
/etc/bind/named.conf.options
echo "​// to talk to, you may need to fix the firewall to allow multiple" >>
/etc/bind/named.conf.options
echo "​// ports to talk. See http://www.kb.cert.org/vuls/id/800113" >>
/etc/bind/named.conf.options
echo "​// If your ISP provided one or more IP addresses for stable " >>
/etc/bind/named.conf.options
echo "​// nameservers, you probably want to use them as forwarders. " >>
/etc/bind/named.conf.options
echo "​// Uncomment the following block, and insert the addresses replacing " >>
/etc/bind/named.conf.options
echo "​// the all-0's placeholder." >> /etc/bind/named.conf.options
echo "​ forwarders {" >> /etc/bind/named.conf.options
echo "​​ 8.8.8.8;" >> /etc/bind/named.conf.options
echo "​​ 8.8.4.4;" >> /etc/bind/named.conf.options
echo "​ };" >> /etc/bind/named.conf.options
echo "​allow-query { $network; };" >> /etc/bind/named.conf.options
echo "​
//=====================================================================
===" >> /etc/bind/named.conf.options
echo "​// If BIND logs error messages about the root key being expired," >>
/etc/bind/named.conf.options
echo "​// you will need to update your keys. See https://www.isc.org/bind-keys" >>
/etc/bind/named.conf.options
echo "​
//=====================================================================
===" >> /etc/bind/named.conf.options
echo "​dnssec-validation auto;" >> /etc/bind/named.conf.options
echo "​listen-on-v6 { any; };" >> /etc/bind/named.conf.options
echo "};" >> /etc/bind/named.conf.options
################

################ /etc/bind/db.local
clear
read -p "Introduce tu dominio [domain.com]: " domain
read -p "Introduce tu Ip [ 172.16.16.117 ]: " ip

echo "### /etc/bind/db.$domain ###"


octetos=$(echo "$ip" | awk -F '.' '{print $1 "." $2 "." $3}')

cat /etc/bind/db.local | head -11 > /etc/bind/db.$domain

sed -i -e "s/localhost/ns1.$domain/g" /etc/bind/db.$domain && sed -i -e


"s/root.localhost/admin.$domain/g" /etc/bind/db.$domain

echo "@​ IN​ NS​ ns1.$domain." >> /etc/bind/db.$domain


echo "ns1​ IN​ A​ $ip" >> /etc/bind/db.$domain
echo "www​ IN​ A​ $octetos.2" >> /etc/bind/db.$domain
echo "ftp​ IN​ A​ $octetos.3" >> /etc/bind/db.$domain

cp /etc/bind/db.$domain /var/cache/bind/

################ /etc/bind/named.conf.local
clear
echo "### /etc/bind/named.conf.local ###"

echo "zone \"$domain\" {" >> /etc/bind/named.conf.local


echo "​type master;" >> /etc/bind/named.conf.local
echo "​file \"/var/cache/bind/db.$domain\";" >> /etc/bind/named.conf.local
echo "​allow-query { any; };" >> /etc/bind/named.conf.local
echo "};" >> /etc/bind/named.conf.local

################ /etc/resolv.conf
clear
echo "nameserver $ip "> /etc/resolv.conf

systemctl restart bind9

intensa() {

################ /etc/bind/db.ip
clear
echo "### /etc/bind/named.conf.local ###"

read -p "Introduce tu dominio [domain.com] : " domain0

read -p "Introduce tu propia Ip [ 192.168.1.18 ]: " netip


case "$netip" in
192.*)
ipa=$(echo "$netip" | awk -F. '{print $3"."$2"."$1}')
lastipa=$(echo "$netip" | awk -F. '{print $4}')
ipac=$(echo "$netip" | awk -F. '{print $1"."$2"."$3}')
cat /etc/bind/db.127 | head -12 > /etc/bind/db.$ipac
sed -i -e "s/localhost/ns1.$domain0/g" /etc/bind/db.$ipac && sed -i -e
"s/root.localhost/admin.$domain0/g" /etc/bind/db.$ipac
echo "2​ IN​ PTR​ www.$domain0." >> /etc/bind/db.$ipac
echo "3​ IN​ PTR​ ftp.$domain0." >> /etc/bind/db.$ipac
echo "$lastipa​ IN​ PTR ns1.$domain0." >> /etc/bind/db.$ipac

;;
172.*)
ipa=$(echo "$netip" | awk -F. '{print $2"."$1}')
ipac=$(echo "$netip" | awk -F. '{print $1"."$2}')
lastoctect=$(echo "$netip" | awk -F. '{print $4"."$3}')
lastipa0=$(echo "$netip" | awk -F. '{print $3}')
cat /etc/bind/db.127 | head -12 > /etc/bind/db.$ipac
sed -i -e "s/localhost/ns1.$domain0/g" /etc/bind/db.$ipac && sed -i -e
"s/root.localhost/admin.$domain0/g" /etc/bind/db.$ipac
echo "2.$lastipa0​ IN​ PTR​ www.$domain0." >> /etc/bind/db.$ipac
echo "3.$lastipa0​ IN​ PTR​ ftp.$domain0." >> /etc/bind/db.$ipac
echo "$lastoctect​ IN​ PTR ns1.$domain0." >> /etc/bind/db.$ipac

;;
esac

cp /etc/bind/db.$ipac /var/cache/bind/

######################################################################

echo "zone \"$ipa.IN-ADDR.ARPA\" {" >> /etc/bind/named.conf.local


echo "​type master;" >> /etc/bind/named.conf.local
echo "​file \"/var/cache/bind/db.$ipac\";" >> /etc/bind/named.conf.local
echo " allow-query { any; };" >> /etc/bind/named.conf.local
echo "};" >> /etc/bind/named.conf.local

systemctl restart bind9

master() {
clear
read -p "Introduce La IP de la máquina Esclava: " ipslave

sed -i "/any; };/i allow-transfer { $ipslave; };" /etc/bind/named.conf.local

systemctl restart bind9

slave(){

apt update
apt install bind9 bind9-utils
clear

read -p "Introduce el DOminio [domain.com] : " domain9


read -p "Introduce la Ip del master: " ip9

echo "zone \"$domain9\" {" >> /etc/bind/named.conf.local


echo "​type slave;" >> /etc/bind/named.conf.local
echo " masters { $ip9; };" >> /etc/bind/named.conf.local
echo "​file \"/etc/bind/db.$domain9\";" >> /etc/bind/named.conf.local
echo "};" >> /etc/bind/named.conf.local

#####################################
case "$ip9" in
192.*)
ipa9=$(echo "$ip9" | awk -F. '{print $3"."$2"."$1}')
ipac9=$(echo "$ip9" | awk -F. '{print $1"."$2"."$3}')

;;
172.*)
ipa9=$(echo "$ip9" | awk -F. '{print $2"."$1}')
ipac9=$(echo "$ip9" | awk -F. '{print $1"."$2}')
;;
esac

echo "zone \"$ipa9\" {" >> /etc/bind/named.conf.local


echo "​type slave;" >> /etc/bind/named.conf.local
echo " masters { $ip9; };" >> /etc/bind/named.conf.local
echo "​file \"/etc/bind/db.$ipac9\";" >> /etc/bind/named.conf.local
echo "};" >> /etc/bind/named.conf.local

chown bind:bind /etc/bind


chmod 755 /etc/bind
systemctl restart bind9

esclavo() {
clear
echo "1- Configurar la Maquina MAESTRO."
echo "2- Configurar la Maquina Esclavo."
read -p "Elige que maquina estas usando" maes

case $maes in

1) master;;

2) slave;;

esac
}

ddns() {

read -p "Introduce su Ip : " ipdhcp


read -p "Introduce su Dominio : " domaindhcp
read -p "Introduce Nombre de tu Clave DDNS : " dnskey

ddns-confgen -qk $dnskey > /etc/bind/ddns.key

cp /etc/bind/ddns.key /etc/dhcp/

chown root:bind /etc/bind/ddns.key


chown root:root /etc/dhcp/ddns.key
chmod 740 /etc/bind/ddns.key
chmod 740 /etc/dhcp/ddns.key

DHCP_CONF="/etc/dhcp/dhcpd.conf"

sed -i.bak '/^option domain-name "example.org";/s/^/#/' "$DHCP_CONF"


sed -i.bak '/^option domain-name-servers ns1.example.org, ns2.example.org;/s/^/#/'
"$DHCP_CONF"
sed -i.bak '/^default-lease-time 600;/s/^/#/' "$DHCP_CONF"
sed -i.bak '/^max-lease-time 7200;/s/^/#/' "$DHCP_CONF"
sed -i.bak '/^ddns-update-style none;/s/^/#/' "$DHCP_CONF"

echo "option domain-name \"$domaindhcp\";" >> /etc/dhcp/dhcpd.conf


echo "option domain-name-servers $ipdhcp;" >> /etc/dhcp/dhcpd.conf
echo "default-lease-time 600;" >> /etc/dhcp/dhcpd.conf
echo "max-lease-time 7200;" >> /etc/dhcp/dhcpd.conf
echo "ddns-updates on;" >> /etc/dhcp/dhcpd.conf
echo "ddns-update-style interim;" >> /etc/dhcp/dhcpd.conf
echo "ignore client-updates;" >> /etc/dhcp/dhcpd.conf
echo "update-static-leases on;" >> /etc/dhcp/dhcpd.conf
echo "log-facility local7;" >> /etc/dhcp/dhcpd.conf
echo "include \"/etc/dhcp/ddns.key\";" >> /etc/dhcp/dhcpd.conf
echo "zone $domaindhcp {" >> /etc/dhcp/dhcpd.conf
echo "​primary $ipdhcp;" >> /etc/dhcp/dhcpd.conf
echo "​key $dnskey;" >> /etc/dhcp/dhcpd.conf
echo "}" >> /etc/dhcp/dhcpd.conf

case "$ipdhcp" in
192.*)
ipdhcp0=$(echo "$ipdhcp" | awk -F. '{print $3"."$2"."$1}')
echo "zone $ipdhcp0.IN-ADDR.ARPA {" >> /etc/dhcp/dhcpd.conf
echo "primary $ipdhcp;" >> /etc/dhcp/dhcpd.conf
echo "key $dnskey;" >> /etc/dhcp/dhcpd.conf
echo "}" >> /etc/dhcp/dhcpd.conf
;;
172.*)
ipdhcp1=$(echo "$ipdhcp" | awk -F. '{print $2"."$1}')
echo "zone $ipdhcp1.IN-ADDR.ARPA {" >> /etc/dhcp/dhcpd.conf
echo "primary $ipdhcp;" >> /etc/dhcp/dhcpd.conf
echo "key $dnskey;" >> /etc/dhcp/dhcpd.conf
echo "}" >> /etc/dhcp/dhcpd.conf
;;
esac

case "$ipdhcp" in
192.*)
ipdhcp0=$(echo "$ipdhcp" | awk -F. '{print $3"."$2"."$1}')
dhcpnetwork=$(echo "$ipdhcp" | awk -F. '{print $1"."$2"."$3".0"}')
dhcpbroadcast=$(echo "$ipdhcp" | awk -F. '{print $1"."$2"."$3".255"}')
range1=$(echo "$ipdhcp" | awk -F. '{print $1"."$2"."$3".10"}')
range2=$(echo "$ipdhcp" | awk -F. '{print $1"."$2"."$3".252"}')

echo "subnet $dhcpnetwork netmask 255.255.255.0 {" >> /etc/dhcp/dhcpd.conf


echo "​ range $range1 $range2;" >> /etc/dhcp/dhcpd.conf
echo "​ option domain-name \"$domaindhcp\";" >> /etc/dhcp/dhcpd.conf
echo "​ option domain-name-servers $ipdhcp;" >> /etc/dhcp/dhcpd.conf
echo "​ option routers $ipdhcp;" >> /etc/dhcp/dhcpd.conf
echo "​ option broadcast-address $dhcpbroadcast;" >> /etc/dhcp/dhcpd.conf
echo "​ default-lease-time 600;" >> /etc/dhcp/dhcpd.conf
echo "}" >> /etc/dhcp/dhcpd.conf
;;
172.*)
ipdhcp1=$(echo "$ipdhcp" | awk -F. '{print $2"."$1}')
dhcpnetwork1=$(echo "$ipdhcp" | awk -F. '{print $1"."$2".0.0"}')
dhcpbroadcast1=$(echo "$ipdhcp" | awk -F. '{print $1"."$2".255.255"}')
range11=$(echo "$ipdhcp" | awk -F. '{print $1"."$2".0.10"}')
range21=$(echo "$ipdhcp" | awk -F. '{print $1"."$2".4.252"}')

echo "subnet $dhcpnetwork1 netmask 255.255.0.0 {" >> /etc/dhcp/dhcpd.conf


echo "​ range $range11 $range21;" >> /etc/dhcp/dhcpd.conf
echo "​ option domain-name \"$domaindhcp\";" >> /etc/dhcp/dhcpd.conf
echo "​ option domain-name-servers $ipdhcp;" >> /etc/dhcp/dhcpd.conf
echo "​ option routers $ipdhcp;" >> /etc/dhcp/dhcpd.conf
echo "​ option broadcast-address $dhcpbroadcast1;" >> /etc/dhcp/dhcpd.conf
echo "​ default-lease-time 600;" >> /etc/dhcp/dhcpd.conf
echo "}" >> /etc/dhcp/dhcpd.conf
;;

esac

sed -i '/organization/a include "\/etc\/bind\/ddns.key";' /etc/bind/named.conf.local


sed -i "/allow-query/i allow-update { key ${dnskey}; };" /etc/bind/named.conf.local
INTERFACE=$(ip route | grep '^default' | awk '{print $5}')

sed -i "s/^INTERFACESv4=\".*\"/INTERFACESv4=\"$INTERFACE\"/"
/etc/default/isc-dhcp-server
sed -i 's/^#authoritative;/authoritative;/' /etc/dhcp/dhcpd.conf

systemctl restart isc-dhcp-server

menu() {

echo "1- Zona Directa"


echo "2- Zona Intensa"
echo "3- COnfiguracion Escalvo"
echo "4- DDNS"
echo "5- Exit"
read -p "Introduce una opcion : " opcion

case $opcion in

1) directa;;

2) intensa;;

3) esclavo;;

4) ddns ;;

5) exit;;

esac

}
menu

Luego de esto en el menu ejecutamos el 1 y seguimos los pasos (CON LA BARRA)

3- Luego hacemos el dos siguiendo pasos(TODO EN EL SERVIDOR), pasamos al 4 y nos


dara un error, no hay problema, a continuación los dos errores:

-​ 1- nano /etc/default/isc-dhcp-server(AQUI LO QUE PONEMOS EN IPV4:”enp0s3”)


-​ 2- nano /etc/bind/db.172.26(EN EL FINAL VEREMOS EL FALLO DE TABULASIO)
-​ systemctl restart isc-dhcp-server
-​ systemctl status isc-dhcp-server

4- Ahora nos metemos en cliente y hacemos unas cuantas comprobaciones:

-​ dig @172.26.0.1 www.hugolg.es


-​ dig @172.26.0.1 -x 172.26.0.1
-​ dig @172.26.0.1 -x 172.26.0.2
-​ dig @172.26.0.1 -x 172.26.0.3
-​ ip a
-​ dhclient -r
-​ dhclient -v

5- Luego de todo esto hay que entregar varias carpetas de documentos:

-​ /var/cache/bind/
-​ /etc/bind/
-​ /etc/dhcp/

You might also like