Try   HackMD

Creació d'un servidor DNS (bind9) (Pràctica en equips)

Pràctica feta per:


Teoria de l'activitat

Primer actualitzem el repositori d'Ubuntu amb:

sudo apt-get update

A continuació instal·larem el "bind9" i "bind9utils" que són eines extres per a bind9.

sudo apt-get install bind9 bind9utils

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Seguidament, modificarem el fitxer de configuració de bind9 amb la comanda:

sudo vim /etc/bind/named.conf.local

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

A continuació haurem d'escriure els següents camps a mà, on indicarem les zones del nostre servidor DNS.

Per indicar les zones haurem d'escriure a mà el següent:

Per la primera zona:

zone "EL_NOM_DEL_NOSTRE_DOMINI" {
type master;
file "/etc/bind/db.EL_NOM_DEL_NOSTRE_DOMINI";
};

Per la segona zona:

zone "LA_NOSTRE_IP_INVERTIDA.in-addr.arpa" {
type master;
file "/etc/bind/db.LA_NOSTRE_IP_INVERTIDA.in-addr.arpa";
};

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Fixeu-vos bé en la IP invertida, ja que no es col·loca tota la IP, només els 3 primers grups de nombres.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Perquè hi ha dues zones?

.

Per fer un servidor DNS hem de fer dos arxius, un que converteixi el nostre URL a IP i un a la inversa.

Localitza els fitxers:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Com es veu a la imatge de dalt declarem dues zones, la primera amb el nom del nostre domini.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
L'altra zona declara el seu nom, el tipus i el fitxer on està la configuració, aquesta zona és la inversa.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Com podem veure el allow transfer esta comentat i explicat, ja que no l'utilitzarem

Comanda opcional per comprovar si les configuracions estan ben fetes

sudo named-checkconf

Si no ens mostra res és que estarà correcta la configuració


A continuació crearem el fitxer de configuració de la primera zona

Per fer això necessitarem crear un fitxer que hem indicat abans:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Introduim la comanda:

sudo vim /etc/bind/db.yreyes.test

Aquesta comanda crearà un fitxer nou fitxer, ja que no hi ha ningun fitxer anomenat d'aquesta manera

En aquest document introduirem el següent, Explicat en el desplegable a baix

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Explicació

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Introduïm el nom del nostre servidor de dominis amb un punt al final, en aquest cas -> srv1.yreyes.test.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Introduirem el nom del nostre domini acompanya de root al començament i un . al final.-> root.yreyes.test.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
On està la IP, hem de col·locar la IP del nostre client, en el nostre cas la 10.21.64.31

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Aquí haurem de sustituir la IP per la IP del nostre servidor, en el nostre cas: 10.21.64.30

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Les paraules en groc són com el nostre grup ha decidit possarli de nom al servidor i al client, pero es poden canviar per cualsevol altre
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Tota la resta hem de copiar-ho tal com està


Anem a fer el fitxer invers

Per fer la part inversa del nostre servidor DNS creem un fitxer invers que hem declarat abans

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

sudo vim /etc/bind/EL_ARXIU_MENCIONAT_ABANS

En aquest fitxer escriurem el següent, tenint en compte eldesplegable a abaix:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Tingues en compte això

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Introduïm el nostre servidor de domini amb un punt al final-> srv1.yreyes.test.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Introduirem el nom del nostre domini acompanya de root al començament i un . al final. -> root.yreyes.test.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Recordes els noms que hem assignat abans amb groc
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
? Doncs ara hem de declarar-los aquí també amb: el_nom.EL_TEU_DOMINI -> client01.yreyes.test

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Indiquem el nom de domini que hem donat al nostre servidor amb un punt al final, en el meu cas -> srv1.yreyes.test.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
&
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Posem els últims nombres de la IP:

IP exeple Resultat
10.21.64.100 100

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Tota la resta hem de copiar-ho tal com està

Per comprovar que les zones estiguin correctament farem servir aquesta comanda opcional

sudo named-checkzone NOM_DE_LA_ZONA FITXER_DE_LA_ZONA

Recorda que tens dues zones i, per tant, ho hauràs de comprovar amb les ambdós

Explicació

.
Aquest és el nostre fitxer de zones

Per fer aquesta comanda haurem de substituir el següent de la comanda de dalt (sudo named-checkzone):

Indicat a la comanda Substituir per:
NOM_DE_LA ZONA
La nostra zona es diu: yreyes.test
FITXER_DE_LA_ZONA
El nostre fitxer és: /etc/bind/db.yreyes.test

PER FER LA COMANDA DEL FITXER INVERS ÉS EXACTAMENT IGUAL

Resultats correctes de la comprovació anterior

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Si apareix OK es que la zona esta correcte


Ara configurarem el fitxer named.conf.options

Per configurar aquest fitxer l'obrirem amb el vi amb la següent comanda:

sudo vim /etc/bind/named.conf.options

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

A l'apartat 'forwarders' el descomentarem traient les "//" i el deixarem tal com està en la imatge

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Recorda descomentar el ""};""
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Reiniciem el sistema amb la comanda:

sudo systemctl restart bind9

Si no ens apareix res, és que s'ha reiniciat correctament

Per mirar l'estat del servei farem servir la comanda:

sudo systemctl status bind9

Resultat correcte


Apartat del client

El client ha de tenir els següents requisits:

  • Tenir els dos ordinadors a la mateixa xarxa (mateix rang de IPs)
  • Que faci ping amb el servidor via IP ( que tingui connexió amb el servidor)

El primer que farem és apagar l'adaptador de xarxa 1, apareixerà com: enp1s0

O si preferiu podeu canviar també el servidor DNS (no recomenat)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

A continuació configurarem l'adapatador de xarxa 2 amb els següents passos:

  • Has de tenir una IP fixa ( mitjans DHCP o IP estàtica )
  • Configurar els DNS com manual i assignar la IP del teu servidor
  • Deixar la passarel·la en automàtic

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Després de fer les modificacions apagarem i encendrem l'adaptador de xarxa 2 ( enp2s0 )

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Podem comprobar si es conecta al domini utilitzant:

nslookup NOM_DEL_DOMINI.test


També podem fer ping directament al servidor

Amb el nom que hem definit abans:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

També podem connectarnos via SSH al servidor amb el nom

Com podem fer això?

Quan nosaltres substituïm la IP del nostre servidor per un nom el que realment estem fent és comunicar-nos amb el servidor DNS perquè ens digui la IP del domini.

Envia: srv1.yreyes.test
El server DNS ho procesa
Torna: 10.21.64.30


Fonts d'informació

sysdual.com
redeszone.net
digitalocean.com
zytrax.com

Informació adicinal de companys
Coneixements previs

Pràctica feta per: