Installing a DNS server Linux + Video

 ________________________________________

Follow us on Facebook

Follow us on Google+

________________________________________

Présentation:


 DNS (Domain Name System) is used to make the correspondence between the IP address and machine name, it is called name resolution (to resolve into English). More concretely without DNS you would have to directly type the IP addresses of machines on which you want to access (web, ftp, telnet and others). If you are connected to an internet service provider (ISP) intermittently by PPP, ADSL or other, it's usually your ISP's DNS servers that provide name resolution, they usually go in pairs, one finds a primary DNS server and a secondary that is there in case of failure of the first.Now why configuring a DNS server on an isolated post, even on a small network of machines, because it can be used to solve a number of very annoying problems mostly found in off-line mode (not connected to the ISP ) including:- Launch of endless netscape or blocking at boot (for a period of 3min)- Sending mails in the folder waiting for sendmail that lasts more than a minute.But also if you have enabled ipmasquerade to share your Internet connection for your client, a DNS server allows them to surf and use the network tools (telnet, ftp, ...). Assume that your Linux machine, is called myhost and has IP address 192.168.13.10 (your private domain and not assigned by ISP) and your privacy mondomaine.fr. Trees presented (especially in the autostart) are those of a Mandrake (a priori as a RedHat).I will not go into details of the configuration files that you have the DNS-HOWTO (linux section and HOW-TO) which is a good introduction. This page is not intended to substitute for that document, it produces a summary to install a DNS server quickly, for detailed explanations see the HOWTO. It is primarily intended to an isolated post or even a small network connected in a non-permanent Internet.Note: If you do not know the IP addresses of DNS servers of your ISP, if automatic assignment of these addresses, for example, just log in and read the addresses at the nameserver lines.



Installing and configuring the server :


has set up a DNS server requires the installation of two tools bind and named. It concerns a Mandrake packages bind, caching-nameserver and bind-utils.
Linux for a client it will only benefit from the latest package for the host or dig commands. The installation created a file
/ etc / named.conf which is as follows: // generated by named-bootconf.pl

// secret must be the same as in /etc/rndc.conf
key "key" {
        algorithm       hmac-md5;
        secret
"c3Ryb25nIGVub3VnaCBmb3IgYSBtYW4gYnV0IG1hZGUgZm9yIGEgd29tYW4K";
};
controls {
    inet 127.0.0.1 allow { any; } keys { "key"; };
};

options {
        pid-file "/var/run/named/named.pid";
        directory "/var/named";
        /*
         * If there is a firewall between you and nameservers you want
         * to talk to, you might need to uncomment the query-source
         * directive below.  Previous versions of BIND always asked
         * questions using port 53, but BIND 8.1 uses an unprivileged
         * port by default.
         */
        // query-source address * port 53;
};
//
// a caching only nameserver config
//
zone "." {
        type hint;
        file "named.ca";
};
zone "0.0.127.in-addr.arpa" {
        type master;
        file "named.local";
};
On va le modifier pour lire:
// secret must be the same as in /etc/rndc.conf
key "key" {
        algorithm       hmac-md5;
        secret
"c3Ryb25nIGVub3VnaCBmb3IgYSBtYW4gYnV0IG1hZGUgZm9yIGEgd29tYW4K";
};
controls {
    inet 127.0.0.1 allow { any; } keys { "key"; };
};
options {
        pid-file "/var/run/named/named.pid";
        directory "/var/named";
        /*
         * If there is a firewall between you and nameservers you want
         * to talk to, you might need to uncomment the query-source
         * directive below.  Previous versions of BIND always asked
         * questions using port 53, but BIND 8.1 uses an unprivileged
         * port by default.
         */
        // query-source address * port 53;
        // on va mettre ici l'adresses IP des serveurs DNS de vos FAI, votre serveur relaiera les requêtes à ceux-ci
        // s'il n'est pas capable de les résoudre
        forward first;
        forwarders {
                194.149.160.9;
                194.149.160.1;
        };
};
//
// a caching only nameserver config
//
zone "." {
        type hint;
        file "named.ca";
};
zone "0.0.127.in-addr.arpa" {
        type master;
        file "named.local";
};
zone "mondomaine.fr" {
        type master;
        file "mondomaine.fr";
};
 The installation created a directory / var / named containing named.local
@       IN      SOA     localhost. root.localhost.  (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum
              IN      NS      localhost.
1       IN      PTR     localhost.
On le modifiera pour lire:
@       IN      SOA     mamachine.mondomaine.fr. root.mamachine.mondomaine.fr.  (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum
              IN      NS      mamachine.mondomaine.fr.
1       IN      PTR     localhost.
On créera sous /var/named un fichier mondomaine.fr contenant:
@       IN      SOA     mamachine.mondomaine.fr. root.mondomaine.fr.  (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum
                                TXT             "mondomaine.fr mon ch'tit domaine"
                NS      mamachine
                                NS              mamachine.mondomaine.fr.
                                MX              10 mamachine
                                MX              20 mamachine.mondomaine.fr.

localhost               A               127.0.0.1
mamachine            A               192.168.13.10
Give this file named group named
chown named:named mondomaine.fr
FYI MX thus corresponds to the SMTP server to your machine if you are running sendmail.
Now in the / etc / nsswitch.conf must have it to the hosts line:

hosts: files dns
The DNS-HOWTO request the creation of a file / etc / host.conf containing
order hosts,bind
multi on

I do not know if it is absolutely necessary, it seems redundant with nsswitch.conf, but just in case.
To complete the / etc / resolv.conf:

search mondomaine.fr
nameserver 127.0.0.1
nameserver 194.149.160.9
nameserver 194.149.160.1
The last two IP addresses are obviously those of your favorite ISP. Note that in the case of an intermittent connection with ppp with automatic assignment of IP addresses of DNS servers, you can not change the last two lines, they are automatically populated when the connection.

Autostart of named

For a server installation on Mandrake, the configuration of the DNS server start automatic installation, you can skip this chapter. The default install of bind and named automatically generates startup files, just in case here are the details. You will find in / etc / rc.d / init.d named file has the following contents:
#!/bin/sh
#
# named           This shell script takes care of starting and stopping
#                 named (BIND DNS server).
#
# chkconfig: 345 55 45
# description: named (BIND) is a Domain Name Server (DNS) \
# that is used to resolve host names to IP addresses.
# probe: true
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /usr/sbin/named ] || exit 0
[ -f /etc/named.conf ] || exit 0
# See how we were called.
case "$1" in
  start)
        # Start daemons.
        echo -n "Starting named: "
        daemon named
        echo
        touch /var/lock/subsys/named
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down named: "
        killproc named
        rm -f /var/lock/subsys/named
        echo
        ;;
  status)
        /usr/sbin/ndc status
        exit $?
        ;;
  restart)
        /usr/sbin/ndc restart
        exit $?
        ;;
 reload)
        /usr/sbin/ndc reload
        exit $?
        ;;
  probe)
        # named knows how to reload intelligently; we don't want linuxconf
        # to offer to restart every time
        /usr/sbin/ndc reload >/dev/null 2>&1 || echo start
        exit 0
        ;;
  *)
        echo "Usage: named {start|stop|status|restart}"
        exit 1
esac
exit 0
The DNS server is automatically started at power-on state 3, 4 and 5. It will still run after the installation by typing

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

To restart named (after a file change), you would type:
/ etc / rc.d / init.d / named restart
The other arguments are start, stop, restart and status.

Client Configuration:


Linux for a client, just create an / etc / resolv.conf containing

domain mondomaine.fr
nameserver 192.168.13.10


You replace it by the address of your server.

Do the same for windows clients, at the Panel and then Network icon.



Function tests:

From a Linux client or server host type the command in a shell, controls typing appear in italics: host -a mamachine
Trying "mamachine.mondomaine.fr"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33741
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;mamachine.mondomaine.fr.             IN      ANY
;; ANSWER SECTION:
mamachine.mondomaine.fr.      86400   IN      A       192.168.25.75
;; AUTHORITY SECTION:
mondomaine.fr.              86400   IN      NS      mamachine.mondomaine.fr.
Received 65 bytes from 127.0.0.1#53 in 15 ms
Then type:
host -a mondomaine.fr
Trying "mondomaine.fr"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47095
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;mondomaine.fr.                     IN      ANY
;; ANSWER SECTION:
mondomaine.fr.              86400   IN      SOA     mamachine.mondomaine.fr. root.mondomaine.fr. 1997022700 28800 14400 3600000 86400
mondomaine.fr.              86400   IN      TXT     "mondomaine.fr mon ch'tit domaine"
mondomaine.fr.              86400   IN      NS      mamachine.mondomaine.fr.
mondomaine.fr.              86400   IN      MX      10 mamachine.mondomaine.fr.
mondomaine.fr.              86400   IN      MX      20 mamachine.mondomaine.fr.
;; ADDITIONAL SECTION:
mamachine.mondomaine.fr.      86400   IN      A       192.168.25.75
Received 179 bytes from 127.0.0.1#53 in 21 ms
Once connected, a client or server type
host -a www.shom.fr
Trying "www.shom.fr."
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12287
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 3
;; QUESTION SECTION:
;www.shom.fr.                   IN      ANY
;; ANSWER SECTION:
www.shom.fr.            217813  IN      CNAME   cyclone.shom.fr.
;; AUTHORITY SECTION:
shom.fr.                330241  IN      NS      neree.shom.fr.
shom.fr.                330241  IN      NS      resone.univ-rennes1.fr.
shom.fr.                330241  IN      NS      dns.univ-lyon1.fr.
;; ADDITIONAL SECTION:
dns.univ-lyon1.fr.      317766  IN      A       134.214.100.6
neree.shom.fr.          330241  IN      A       194.57.228.65
resone.univ-rennes1.fr. 300271  IN      A       129.20.254.1
Received 182 bytes from 192.168.25.75#53 in 157 ms

Le ping should work also.

From a position of windows to test your server in a Windows command prompt type
nslookup
At the prompt, type the name of machine under test

>www.shom.fr
Serveur: Unknown
Address: 192.168.26.75
Réponse de source secondaire :
Nom: cyclone.shom.fr
Address: 194.57.228.1
Aliases: www.shom.fr
Type CTRL + C to exit promptly at t

Create virtual hosts

You can create virtual hosts with your DNS server, in other words, your server may be identiifé by several names, it is particularly interesting for apache. With a different name that points to the same machine, however, we can point to different locations.
Suppose we want to create virtual hosts
www.idefix.mondomaine.fr et www.asterix.mondomaine.fr, on rajoutera à la fin du fichier /var/named/mondomaine.fr, the following lines:www.asterix    A    192.168.13.11
www.idefix      A    192.168.13.11
Restart the server by typing:
/etc/rc.d/init.d/named restart
To test a customer type in a shell:
ping www.asterix.mondomaine.fr
It should work.