Home Linux & Systems Cybersecurity Cloud & DevOps Networks & Infrastructure SIEM & Monitoring DFIR & Threat Intel Development & Other All categories Projects About Tools

Install DNS server in debian

Leer en espanol
Install DNS server in debian

Table of contents

It is the name resolution protocol for TCP/IP networks, such as the Internet. A DNS server hosts information that allows client computers to easily resolve alphanumeric DNS names. ===

What DNS?

It is the name resolution protocol for TCP/IP networks, such as the Internet. A DNS server hosts information that allows client computers to resolve easy-to-remember alphanumeric DNS names to the IP addresses that computers use to communicate with each other.

Servidor dns con bind9

DNS DOMAIN TYPE:

TOP LEVEL DOMAIN: A two- or three-letter name used to indicate a country, region, or the type of organization that uses a name: ( Example: “.com” )

SECOND LEVEL DOMAIN:Variable length registered name that an individual or organization uses and the Internet. These names are always based on an appropriate top-level domain, depending on the type of organization or geographic location where the name is used.(EXAMPLE: “NETWORK-ORBITA.”)

SUBDOMAIN: Additional names that an organization can create derived from the second-level registered domain name. These include names added to develop the DNS name tree into an organization and divide it into departments or geographic locations. (EXAMPLE: “ROKITOH.RED-ORBITA.COM”)

Tools:

Virtualbox (As always)

Debian Stable (No graphical interface)

Bind9 (Our DNS server)

Well, first of all, we are going to configure our IP addressing.

Bash
rokitoh@redorbita:~# nano /etc/network/interfaces
text
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
#iface eth0 inet dhcp
auto eth0
iface eth0 inet static
address 192.168.1.233
netmask 255.255.255.0
gateway 192.168.1.1

We start the new configuration

Bash
rokitoh@redorbita:~# /etc/init.d/networking restart

Deconfiguring network interfaces…done.

Install and configure Bind9

Bash
rokitoh@redorbita:~# apt-get install bind9

We stop bind9 services

Bash
rokitoh@redorbita:~# /etc/init.d/bind9 stop

Stopping domin name service…: bind9

We edit the file /etc/default/bind9 . We want the bind daemon to run with the unprivileged bind user, “chrooted” to the /var/lib/named directory. To do this, we look for where it says <<OPTIONS=”-u bind”>> and we replace it with <var/lib/named”>

Bash
rokitoh@redorbita:~# nano /etc/default/bind9
BASH
text


 





#run resolvconf?

RESOLVCONF=yes

 #startup options for the server
OPTIONS="-u bind -t /var/lib/named"
 
Bash

 

 

We create the directory tree



rokitoh@redorbita:~# mkdir -p /var/lib/named/etc

rokitoh@redorbita:~# mkdir /var/lib/named/dev

rokitoh@redorbita:~# mkdir -p /var/lib/named/var/cache/bind

rokitoh@redorbita:~# mkdir -p /var/lib/named/var/run/bind/run
Next we move all the bind9 configuration to /var/lib/named/etc
Bash
rokitoh@redorbita:~# mv /etc/bind /var/lib/named/etc
We create a symbolic link of /etc/bind to /var/lib/named/etc/bind
Bash
rokitoh@redorbita:~# ln -s /var/lib/named/etc/bind /etc/bind
We create the devices "null" and "random" and we give them read and write permissions
Bash
rokitoh@redorbita:~# mknod /var/lib/named/dev/null c 1 3

rokitoh@redorbita:~# mknod /var/lib/named/dev/random c 1 8

rokitoh@redorbita:~# chmod 666 /var/lib/named/dev/null /var/lib/named/dev/random

rokitoh@redorbita:~# chown -R bind:bind /var/lib/named/var/*

rokitoh@redorbita:~# chown -R bind:bind /var/lib/named/etc/bind
We will only change who will be in charge of the chroot tree.
Bash
rokitoh@redorbita:~# chown ­R bind:bind /var/lib/named/var/*

rokitoh@redorbita:~# chown ­R bind:bind /var/lib/named/etc/bind
We need to modify the rsyslogd configuration file, in order to have the log of the logs from our DNS service.
Bash
rokitoh@redorbita:~# nano /etc/default/rsyslogd
text
# Options for rsyslogd
# -m 0 disables 'MARK' messages (deprecated, only used in compat mode < 3)
# -r enables logging from remote machines (deprecated, only used in compat mode < 3)
# -x disables DNS lookups on messages received with -r
# -c compatibility mode
# See rsyslogd(8) for more details
RSYSLOGD_OPTIONS="-a /var/lib/named/dev/log"

We start Bind9

 
Bash
rokitoh@redorbita:~# /etc/init.d/bind9 start
To check for errors that may occur on the DNS server
 
Bash
rokitoh@redorbita:~ less /var/log/syslog

Configure DNS zones

 
In the DNS zones is where we configure all the domains that our server will have, they are
 
You must create file by file for each domain you have.

TYPES OF ZONE REGISTRATION

 
TO = Address (Address) This record is used to translate host names to IPv4 addresses.
AAAA = Address(Address) This record is used to translate host names to IPv6 addresses.
CNAME = Canonical Nameand (Canonical Name) Used to create additional host names, or aliases, for the hosts in a domain. It is used when multiple services (such as ftp and web server) are running on a server with a single IP address. Each service has its own DNS entry (such as ftp.example.com. and www.example.com.). This is also used when you run multiple http servers, with different names, on the same host.
N.S. = NameServer(Name Server) Defines the association that exists between a domain name and the name servers that store the information for said domain. Each domain can be associated with any number of name servers.
MX (record) = Mail Exchange(Mail Exchange Registry) Associates a domain name with a list of mail exchange servers for that domain.
PTR = Pointer – (Indicator) Also known as 'reverse registration', it works in reverse of the A record, translating IPs into domain names.
 
SOA = Start of authority(Zone authority) Provides information about the area.
HINFO = Host INFOrmation (Computer system information) Host Description allows people to know the type of machine and operating system that a domain corresponds to.
TXT = TeXT - (Textual information) Allows domains to identify themselves in arbitrary ways.
LOC = Location - Allows you to indicate the coordinates of the domain.
WKS - Generalization of the MX record to indicate the services offered by the domain. Obsolete in favor of SRV.
SRV = Services - Allows you to indicate the services offered by the domain. RFC2782
SPF = Sender Policy Frameworkk - Helps combat Spam. This record specifies which host(s) are authorized to send mail from the given domain. The receiving server consults the SPF to compare the IP from which it arrives with the data in this record.

Configure the zone file

 
We go to the folder
 
Bash
rokitoh@redorbita:~# cd /etc/bind/
We copy to the file
 
Bash
rokitoh@redorbita:/etc/bind~# cp db.255 redorbita.com
We access redorbita.com
 
Bash
rokitoh@redorbita:/etc/bind~# nano redorbita.com
Where does it say "localhost" There we must put the name of our domain.
and below everything "TO" We will put our IP address.
text
$TTL    1W
@       IN      SOA     redorbita.com. root.redorbita.com (
2               ; Serial Number
1W            ; Time To Refresh
1D             ; Time To Retry
28D           ; Time To Expire
1W )         ; Negative Cache TTL
;
@       IN      NS      redorbita.com.
@       IN      A       192.168.1.233
Bash
Ahora nos toca configurar la zona infeversa
rokitoh@redorbita:/etc/bind~# cp db.125 1.168.192.in.addr.arpa
We access 1.168.192.in.addr.arpa
 
Bash
rokitoh@redorbita:/etc/bind~# nano 1.168.192.in.addr.arpa
Here the same procedure. in "localhost" we put our domain name
 
and "1.0.0" We replace it with our IP address
text
$TTL    1W
@       IN      SOA     redorbita.com. admin.redorbita.com. (
2                     ; Serial Number
1W                  ; Time To Refresh
1D                   ; Time To Retry
28D                  ; Time To Expire
1W )                ; Negative Cache TTL
;
@       IN      NS      redorbita.com.
233.1.168       IN      PTR     redorbita.com.

Configure named.conf.

  It is the configuration file of our DNS server, inside it we will have to add some parameters to call the files we have created.
Bash
rokitoh@redorbita:/etc/bind~# nano named.conf
We only modify "redorbita.com" that you will have to replace it with the name of your domain and the routes of the direct and inverse zone (What is in red)
Bash
zone "255.in­addr.arpa" {

type master;

file "/etc/bind/db.255";

};

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

#### Agregado por el Administrador #####

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

zone "redorbita.com" { 

type master;

 file "/etc/bind/zones/redorbita.com"; 

};

zone "1.168.192.in­addr.arpa" { 

type master;

 file "/etc/bind/zones/1.168.192.in-addr.arpa"; 

};

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

include "/etc/bind/named.conf.local";

Modify /etc/resolv.conf

 
Using the /etc/resolv.conf file we can indicate the DNS resolvers that a certain computer will use. Today we will see how it works by default with a set of resolvers and how to configure it in round-robin.
 
Bash
rokitoh@redorbita:/etc/bind~# nano /etc/resolv.conf
Here we must enter the IP address of our server and the domain name
text
domain  redorbita.com

nameserver 192.168.1.233

Checks

  Now let's check that our server is working correctly.
Bash
rokitoh@redorbita:~# host redorbita.com 192.168.1.233

Using domain server:

Name: 192.168.1.233

Address: 192.168.1.233#53

Aliases:

Using Netstat

 
Bash
rokitoh@redorbita:~# netstat ­tanp | grep named
tcp   0  0 192.168.1.233:53  0.0.0.0:*   LISTEN
tcp   0  0 127.0.0.1:53      0.0.0.0:*   LISTEN
tcp   0  0 127.0.0.1:953     0.0.0.0:*   LISTEN
rokitoh@redorbita:~#

Comments