Linux - Server DNS locale 1/2


Promemoria di come settare i DNS di un generico Server Centos:

1) vim /etc/sysconfig/network


2) vim /etc/hosts               localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6

3) vim /etc/host.conf

order hosts,bind

4) cd /etc/resolv.conf

5) system-config-network-tui

hostname = server01.localdomain

dns = IP

Search = localdomain

Di seguito gli step da eseguire per settare un DNS locale in una rete

vim /etc/sysconfig/network

=== file: /etc/sysconfig/network ===


vim /etc/hosts

=== file: /etc/hosts ===   localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6 server01.instyle.locale server01 server01.instyle.locale relay

vim /etc/host.conf

=== file: /etc/host.conf ===

order bind, hosts

vim /etc/resolv.conf

=== file: resolv.conf ===

nameserver #DNS scelto esterno
search localdomain
domain instyle.locale


Seguire passo passo la seguente guida

1) yum install bind-chroot system-config-bind

Aprire le porte del firewall TCP e UDP 53 ( system-config-network-tui)

2) Riavviare il server in modalità grafica init 5

Lanciare il programma ed andare su properties ed aggiungere la seguente opzione:

allow-query { localhost;; };

3) Modificare utilizzando il seguente file

# define name server
IN       NS       ns. instyle.locale.
# internal IP address of name server
IN       A
# define Mail exchanger
IN       MX 10 server01. instyle.locale.
# define IP address and hostname
            server01        IN       A
            www.instyle.locale. IN A
            mail.instyle.locale. IN A
            instyle.locale. IN NS server01.instyle.locale
            instyle.locale. IN MX 10 mail 

4) Avviamo il servizio

/etc/rc.d/init.d/named start

chkconfig named on

N.B.  se appare l'errore /var/log/messages

named[1284]: starting BIND 9.4.3-P1 -t /var/named -u bind
named[1284]: command channel listening on
named[1284]: the working directory is not writable
named[1284]: running

E' sufficiente dare il comando

chown -R bind /var/named

5) Usare i comandi seguenti per vedere se funziona tutto:

dig server01.instyle.locale.

dig –x

dig @localhost acme.local ANY

host www.instyle.locale localhost 

host -t mx instyle.locale localhost

6) Per settare un cname:


# update serial
2007041501 ;Serial

# aliase IN CNAME server's name

ftp        IN       CNAME          ns.instyle.locale.

Per ricaricare le impostazioni:

rndc reload

8) Se uno invece vuole settare un DNS secondario è necessario sul server DNS master:

vim /var/named/instyle.locale.lan

$TTL 86400

@         IN       SOA ns.instyle.locale. root. instyle.locale. (
2007041501   ;Serial
3601                                ;Refresh
1801                                 ;Retry
604800           ;Expire
            86400             ;Minimum TTL
# define name server
IN       NS       ns. instyle.locale.

#si aggiunge qui la riga per il dns secondario

IN       NS       ns.instyle2.locale.
# internal IP address of name server
IN       A
# define Mail exchanger
IN       MX      10        ns. instyle.locale.
# define IP address and hostname
Ns        IN       A

rndc reload

Sul DNS secondario aggiungere la seguente riga:

vi /etc/named.conf

# add these lines below
zone "instyle.locale" IN {
type slave;
masters {; };
file "slaves/instyle.locale.lan";

rndc reload
server reload successful

ls /var/named/slaves

  • A Records

An A record is probably the most common and easiest of all records to understand. Quite
simply, whatever is placed on the left will resolve to the IP address provided on the right.
Here’s an example of an A record:

www IN A

Here, www (expanded to include the full domain name) would resolve to
If this were the zone file for, www would be expanded to You could choose to be specific in your zone file and use something like this: IN A

The final period (or dot) after .org is very important. If you left this out, the record
would be expanded to create

www IN A


Cname collega due voci dns.

ftp IN CNAME www

The benefit with using CNAME is that if you change the IP address of the server (perhaps
you’re running this particular machine on an Internet connection that has a dynamic
IP address), you have to update only one IP address instead of two.

  • MX Records IN A IN MX 10 mailserver

Remember, though, that the MX record must point to an existing hostname; in other words, it requires an A record. This doesn’t have to be in the same domain, as we’ll see in one of the following examples.

Se uno avesse due mail Server: IN A IN A IN MX 10 mailserver IN MX 20 mailserver2

  • NS Records
An NS record looks like this: IN NS

the authoritative name servers for our domain by creating to NS records.
Generally speaking, you should have at least two DNS servers. This is good practice
because if your DNS server goes down, people won’t be able to find your web site or your
e-mail servers. Because many people host their web sites in the same place they host their
DNS, this won’t help much, but it will ensure that e-mail is properly routed to the backup
e-mail server. Multiple NS records look like this: IN NS IN NS

  • Esempio di configurazione DNS IN A IN CNAME www IN A IN A IN NS IN NS IN MX 10 mail IN MX 20 mail