Faisons un peu de DNS caching pour notre réseau local.

Introduction.

On en profitera faire faire à bind le travail du resolv.conf pour les noms de machines, ce qui évitera d'avoir à les reproduire sur chaque poste (laborieux). Bind est fourni dans l'install de base d'OpenBSD, il se situe dans /var/named et (depuis la 3.5 il me semble, j'ai pas de 3.4 pour vérifier) s'active par une simple option: named_flags. (cf: /etc/rc.conf) Celui-ci se lance donc au démarrage pour peu qu'on fasse un petit

echo 'named_flags=""' > /etc/rc.conf.local

Passons à la configuration.

On va donc partir du constat suivant: on a 3 machines sur un réseau de classe C en 192.168.0.0/24 dont le domaine est mon-domaine. Les machines sont:

  • 192.168.1.1 gateway.mon-domaine
  • 192.168.1.2 workstation.mon-domaine
  • 192.168.1.3 crashtest.mon-domaine

Dans notre config de named (/var/named/etc/named.conf) va ressembler à ça:

// to execute recursive queries. The default setting allows all hosts
// on any IPv4 networks for which the system has an interface, and
// the IPv6 localhost address.
//
//ici, on définit qui à le droit d'interroger le serveur
acl clients {
        127.0.0.0/24; // Pour autoriser l'accès depuis localhost
        10.0.0.0/8;
        ::1;
};

options {
        version ""; // remove this to allow version queries
        listen-on { any; }; //pour peu que le 53 soit filtré, on peu laisser
        listen-on-v6 { any; };
        allow-recursion { clients; };
};

logging {
        category lame-servers { null; };
};

// Standard zones
//
zone "." {
        type hint;
        file "standard/root.hint";
};

zone "localhost" {
        type master;
        file "standard/localhost";
        allow-transfer { localhost; };
};

zone "127.in-addr.arpa" {
        type master;
        file "standard/loopback";
        allow-transfer { localhost; };
};

// Forward lookup (recherche directe)
zone "0.168.192.in-addr.arpa" {
        type master;
        file "standard/named-192.168.0";
        allow-transfer { localhost; };
};

// Reverse lookup (recherche inverse)
zone "mon-domaine" {
        type master;
        file "standard/named-mon-domaine";
};

Ensuite on créé les fichiers de zone /var/named/standard/named-192.168.0 et /var/named/standard/named-mon-domaine: Pour /var/named/standard/named-192.168.0 on renseigne l'équivalence IP –> nom des machines (Pointeurs):

$ORIGIN 0.168.192.in-addr.arpa.
$TTL 6h
@               IN              SOA             localhost.              root.localhost. (
                                                1 ; serial
                                                1h ; refresh
                                                30m ; retry
                                                7d ; expiration
                                                1h ) ; minimum
                IN              NS              localhost.
1               IN              PTR             gateway.mon-domaine.
2               IN              PTR             workstation.mon-domaine.
3               IN              PTR             crashtest.mon-domaine.

Ensuite on définit les alias dans /var/named/standard/named-mon-domaine:

@               IN          SOA         localhost       root.localhost. (
                2004051001
                10800
                3600
                604800
                86400 )
                IN          NS          ns.mon-domaine.
                IN          MX    10    smtp.mon-domaine.
                IN          A           192.168.0.1
localhost       IN          A           127.0.0.1
gateway         IN          A           192.168.0.1
ns              IN          CNAME       gateway
smtp            IN          CNAME       gateway
workstation     IN          A           192.168.0.2
crashtest       IN          A           192.168.0.3

Pour que tout cela fonctionne, on va encore modifier le /etc/resolv.conf du serveur:

# on définit le domaine DNS local
domain naxalite
# on indique l'ordre de recherche (c'est l'ordre par défaut)
lookup bind file
# on choisit notre machine comme serveur de noms
nameserver 127.0.0.1

Maintenant, on peut soit rebooter soit utiliser le script suivant pour démarrer bind, sachant qu'il sera relançé à chaque redémarrage.

#!/bin/sh
if ! cmp -s /etc/rndc.key /var/named/etc/rndc.key ; then
    echo -n "rndc-confgen: generating new shared secret... "
    if /usr/sbin/rndc-confgen -a -t /var/named >/dev/null 2>&1; then
        chmod 0640 /var/named/etc/rndc.key >/dev/null 2>&1
        echo done.
    else
        echo failed.
    fi
fi

echo 'starting named';      named

Crédits

Auteur Original : Eric DILLENSEGER
Mis Sur Le Wiki Par Azwaw OUSADOU
Date De Parrution : 20/07/2009

documentations/reseau/bind_cache.txt · Dernière modification: 2009/07/20 18:48 par bsdmaniak
OpenBSD Apache Driven by DokuWiki
CC Attribution-Noncommercial-Share Alike 3.0 Unported