Linuxhotel Wiki

Wie ging das nochmal?

Benutzer-Werkzeuge

Webseiten-Werkzeuge


lpi2:bind

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen gezeigt.


Vorherige Überarbeitung
—lpi2:bind [2026/03/20 15:15] (aktuell) – Externe Bearbeitung 127.0.0.1
Zeile 1: Zeile 1:
 +Vorraussetzung: [[bind caching only | bind als caching only nameserver]]
 +
 +===== Vorbereiten =====
 +=== systemd-resolvd ===
 +"systemd-resolved is not intended to be used on DNS servers. If you’re running a DNS server, you’ll need to disable systemd-resolved before setting up BIND or Unbound instead"
 +=== CentOS 7 ===
 +Paket ''caching-nameserver'' deinstallieren
 +
 +=== DNSSEC temporär abschalten ===
 +''/etc/named.conf'' : CentOS
 +
 +''/etc/bind/named.conf.options'' : Debian (ab 12)
 +<file>
 +options {
 +…
 +        // In der Praxis ist DNSSEC eine gute Sache ... aber im Intranet zum Lernen erst mal aus:
 +        dnssec-validation no;
 +…
 +}
 +</file>
 +(( mehr zu ''allow-query'' weiter unten im Kapitel "Bind absichern" und natürlich unter 
 +  man named.conf
 +))
 +  named-checkconf 
 +  rndc reconfig
 +
 +== testen ==
 +Eine mit DNSSEC signierte Zone abfragen:
 +
 +Ein validierender Nameserver sollte bei einer signierten Zone liefern:
 +  dig www.posteo.de @1.1.1.1
 +
 +-> ''flags: … ad''
 +
 +Unser Nameserver sollte das ad-Flag nicht setzen.
 +
 +===== eigene Zonen in bind verwalten =====
 +==== Vorwärts-Zone ====
 +=== Zonendatei ===
 +
 +  * ''/var/named/linuxhotel.de'' : ( CentOS )
 +  * ''/var/lib/named/linuxhotel.de'' : ( SuSE )
 +  * ''/var/cache/bind/linuxhotel.de'' : ( Debian )
 +
 +<file txt linuxhotel.de>
 +$ORIGIN . ; hilft Tippfehler (fehlender . am Ende) zu vermeiden
 +$TTL 2m   ; time to live: 2 Minuten, default wäre 2 Tage
 +linuxhotel.de. SOA notebook20.linuxhotel.de. root.notebook20.linuxhotel.de. (
 +        1             ; Seriennummer
 +        1h20m         ; refresh      / 1 Stunde 20 Minuten
 +        1d12h         ; retry        / 1,5 Tage
 +        1w            ; expire       / 1 Woche
 +        60s           ; negative ttl / 60 Sekunden
 +)
 +
 +; Nameserver:
 +linuxhotel.de.                  NS notebook20.linuxhotel.de.
 +
 +; kanonische IP-Adressen:
 +notebook22.linuxhotel.de.       A 192.168.1.222
 +notebook05.linuxhotel.de.       A 192.168.1.205
 +notebook20.linuxhotel.de.       A 192.168.1.220
 +notebook06.linuxhotel.de.       A 192.168.1.206
 +notebook09.linuxhotel.de.       A 192.168.1.209
 +
 +notebook22.linuxhotel.de.       AAAA 2a0f:6480:1:600::222
 +notebook05.linuxhotel.de.       AAAA 2a0f:6480:1:600::205
 +notebook20.linuxhotel.de.       AAAA 2a0f:6480:1:600::220
 +notebook06.linuxhotel.de.       AAAA 2a0f:6480:1:600::206
 +notebook09.linuxhotel.de.       AAAA 2a0f:6480:1:600::209
 +
 +; Aliase:
 +peter.linuxhotel.de.            CNAME notebook09.linuxhotel.de.
 +lothar.linuxhotel.de.        60 CNAME notebook05.linuxhotel.de.
 +heribert.linuxhotel.de.      30 CNAME notebook06.linuxhotel.de.
 +bjoern.linuxhotel.de.           CNAME notebook20.linuxhotel.de.
 +admin.linuxhotel.de.            CNAME notebook22.linuxhotel.de.
 +</file>
 +
 +=== Zonendatei überprüfen ===
 +== CentOS ==
 +  named-checkzone -D linuxhotel.de. /var/named/linuxhotel.de
 +
 +== SuSE ==
 +  named-checkzone -D linuxhotel.de. /var/lib/named/linuxhotel.de
 +
 +== Debian ==
 +  named-checkzone -D linuxhotel.de. /var/cache/bind/linuxhotel.de
 +
 +=== Konfigurationsdatei ===
 +  * ''/etc/named.conf'' : ( SuSE )
 +  * ''/etc/named.conf'' : ( CentOS )
 +  * ''/etc/bind/named.conf.local'' : ( Debian )
 +<file>
 +zone "linuxhotel.de" {
 +  type primary;
 +  file "linuxhotel.de";
 +};
 +</file>
 +
 +Konfigdatei und eingetragene Zonen überprüfen:
 +  named-checkconf -z
 +
 +=== bind die Änderung mitteilen ===
 +  rndc reconfig
 +((oder 
 +
 +openSuSE, CentOS
 +  service named reload
 +
 +Debian
 +  service bind9 reload
 +))
 +=== im Log prüfen, ob es Fehler gab ===
 +Debian
 +  journalctl -eu named.service
 +
 +=== testen ===
 +  host peter.linuxhotel.de ::1
 +  dig peter.linuxhotel.de @::1 any
 +
 +=== Zonendatei (kürzere Schreibweise) ===
 +Das Format der Zonendatei ((RFC [[rfc>1035]])) läßt es auch zu, diese Datei kürzer zu schreiben:
 +<file>
 +$TTL 2h
 +@ SOA notebook20.linuxhotel.de. root.notebook20.linuxhotel.de. 1999022301 1d 2h 5w 2d
 +
 +; Nameserver:
 +                 NS notebook20.linuxhotel.de.
 +
 +; kein Mailserver, weder empfangen (RFC 7505), noch senden:
 +                 MX 0 .
 +                 TXT "v=spf1 -all"
 +
 +; kanonische IP-Adressen:
 +notebook22       A 192.168.1.222
 +                 AAAA 2a0f:6480:1:600::222
 +notebook05       A 192.168.1.205
 +                 AAAA 2a0f:6480:1:600::205
 +notebook20       A 192.168.1.220
 +                 AAAA 2a0f:6480:1:600::220
 +notebook06       A 192.168.1.206
 +                 AAAA 2a0f:6480:1:600::206
 +notebook09       A 192.168.1.209
 +                 AAAA 2a0f:6480:1:600::209
 +
 +; Aliase:
 +peter            CNAME notebook09
 +lothar           CNAME notebook05
 +heribert      60 CNAME notebook06
 +bjoern        30 CNAME notebook20
 +admin            CNAME notebook22
 +</file>
 +
 +Hier habe ich die Zeitangaben im SOA entsprechend der Empfehlungen des Ripe ((
 +https://www.ripe.net/publications/docs/ripe-203
 +<file>
 +example.com.  3600  SOA  dns.example.com. hostmaster.example.com. (
 +                         1999022301   ; serial YYYYMMDDnn
 +                         86400        ; refresh (  24 hours)
 +                         7200         ; retry   (   2 hours)
 +                         3600000      ; expire  (1000 hours)
 +                         172800 )     ; minimum (   2 days)
 +</file>
 +)) gewählt. 
 +
 +Bei jeder Änderung der Zonendatei sollte die Seriennummer hochgezählt werden.
 +
 +=== Zonendatei überprüfen ===
 +== CentOS ==
 +  named-checkzone -D linuxhotel.de. /var/named/linuxhotel.de
 +
 +== SuSE ==
 +  named-checkzone -D linuxhotel.de. /var/lib/named/linuxhotel.de
 +
 +== Debian ==
 +  named-checkzone -D linuxhotel.de. /var/cache/bind/linuxhotel.de
 +
 +=== bind die Änderung mitteilen ===
 +  rndc reload linuxhotel.de
 +
 +==== Rückwärts-Zone IPv4 ====
 +=== Zonendatei ===
 +  * ''/var/named/1.168.192.in-addr.arpa'': ( CentOS )
 +  * ''/var/lib/named/1.168.192.in-addr.arpa'': ( SuSE 10.0 )
 +  * ''/var/cache/bind/1.168.192.in-addr.arpa'': ( Debian 3.1 )
 +
 +<file>
 +$TTL 2h
 +@ SOA notebook20.linuxhotel.de. root.notebook20.linuxhotel.de. 1999022301 1d 2h 5w 2d
 +
 +; Nameserver:
 +                 NS notebook20.linuxhotel.de.
 +
 +; kanonische IP-Adressen
 +205.1.168.192.in-addr.arpa. IN PTR notebook05.linuxhotel.de.
 +220.1.168.192.in-addr.arpa. IN PTR notebook20.linuxhotel.de.
 +206.1.168.192.in-addr.arpa. IN PTR notebook06.linuxhotel.de.
 +209.1.168.192.in-addr.arpa. IN PTR notebook09.linuxhotel.de.
 +222.1.168.192.in-addr.arpa. IN PTR notebook22.linuxhotel.de.
 +</file>
 +
 +=== testen ===
 +== CentOS ==
 +  named-checkzone -D 1.168.192.in-addr.arpa. /var/named/1.168.192.in-addr.arpa
 +
 +== SuSE ==
 +  named-checkzone -D 1.168.192.in-addr.arpa. /var/lib/named/1.168.192.in-addr.arpa
 +
 +== Debian ==
 +  named-checkzone -D 1.168.192.in-addr.arpa. /var/cache/bind/1.168.192.in-addr.arpa
 +
 +=== Konfigurationsdatei ===
 +  * ''/etc/named.conf'' : ( SuSE 10.2 )
 +  * ''/etc/named.conf'' : ( CentOS )
 +  * ''/etc/bind/named.conf.local'' : ( Debian 3.1 )
 +<file>
 +zone "1.168.192.in-addr.arpa" {
 +      type primary;
 +      file "1.168.192.in-addr.arpa";
 +};
 +</file>
 +==  Syntax der Konfigurationsdatei prüfen ==
 +  named-checkconf -z
 +
 +== bind die Änderung mitteilen ==
 +  rndc reconfig
 +=== testen ===  
 +  host 192.168.1.222 ::1
 +  dig -x 192.168.1.222 @::1
 +
 +==== Rückwärts-Zone IPv6 ====
 +Paket:
 +  * Debian (12): ''ipv6calc''
 +=== Zonendatei ===
 +  ipv6calc --out revnibbles.arpa --in ipv6addr 2a0f:6480:1:600::222
 +-> ''2.2.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.6.0.1.0.0.0.0.8.4.6.f.0.a.2.ip6.arpa.''
 +  * ''/var/named/0.0.6.0.1.0.0.0.0.8.4.6.f.0.a.2.ip6.arpa'': ( CentOS )
 +  * ''/var/lib/named/0.0.6.0.1.0.0.0.0.8.4.6.f.0.a.2.ip6.arpa'': ( SuSE )
 +  * ''/var/cache/bind/0.0.6.0.1.0.0.0.0.8.4.6.f.0.a.2.ip6.arpa'': ( Debian )
 +
 +<file>
 +$TTL 2h
 +@ SOA notebook20.linuxhotel.de. root.notebook20.linuxhotel.de. 1999022301 1d 2h 5w 2d
 +
 +; Nameserver:
 +                 NS notebook20.linuxhotel.de.
 +
 +; kanonische IP-Adressen
 +2.0.5.0.0.0.0.0.0.0.0.0.0.0.0.0. IN PTR notebook05.linuxhotel.de.
 +2.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0. IN PTR notebook20.linuxhotel.de.
 +2.0.6.0.0.0.0.0.0.0.0.0.0.0.0.0. IN PTR notebook06.linuxhotel.de.
 +2.0.9.0.0.0.0.0.0.0.0.0.0.0.0.0. IN PTR notebook09.linuxhotel.de.
 +2.2.2.0.0.0.0.0.0.0.0.0.0.0.0.0. IN PTR notebook22.linuxhotel.de.
 +</file>
 +
 +=== testen ===
 +== CentOS ==
 +  named-checkzone -D 0.0.6.0.1.0.0.0.0.8.4.6.f.0.a.2.ip6.arpa. /var/named/0.0.6.0.1.0.0.0.0.8.4.6.f.0.a.2.ip6.arpa
 +
 +== SuSE ==
 +  named-checkzone -D 0.0.6.0.1.0.0.0.0.8.4.6.f.0.a.2.ip6.arpa. /var/lib/named/0.0.6.0.1.0.0.0.0.8.4.6.f.0.a.2.ip6.arpa
 +== Debian ==
 +  named-checkzone -D 0.0.6.0.1.0.0.0.0.8.4.6.f.0.a.2.ip6.arpa. /var/cache/bind/0.0.6.0.1.0.0.0.0.8.4.6.f.0.a.2.ip6.arpa
 +
 +=== Konfigurationsdatei ===
 +  * ''/etc/named.conf'' : ( SuSE )
 +  * ''/etc/named.conf'' : ( CentOS )
 +  * ''/etc/bind/named.conf.local'' : ( Debian )
 +<file>
 +zone "0.0.6.0.1.0.0.0.0.8.4.6.f.0.a.2.ip6.arpa" {
 +      type primary;
 +      file "0.0.6.0.1.0.0.0.0.8.4.6.f.0.a.2.ip6.arpa";
 +};
 +</file>
 +==  Syntax der Konfigurationsdatei prüfen ==
 +  named-checkconf -z
 +
 +== bind die Änderung mitteilen ==
 +  rndc reconfig
 +=== testen ===  
 +  host 2a0f:6480:1:600::222 ::1
 +  dig -x 2a0f:6480:1:600::222 @::1
 +
 +===== Zonendateien mit nsupdate bearbeiten =====
 +==== bind konfigurieren ====
 +  * ''/etc/named.conf'' : ( SuSE, CentOS )
 +  * ''/etc/bind/named.conf.local'' : ( Debian )
 +mit ''allow-update'':
 +<file>
 +acl "nsupdate" {
 +  127.0.0.1;
 +};
 +
 +zone "linuxhotel.de" {
 +        type primary;
 +        allow-update { "nsupdate"; };
 +        file "linuxhotel.de";
 +};
 +
 +zone "1.168.192.in-addr.arpa" {
 +        type primary;
 +        allow-update { "nsupdate"; };
 +        file "1.168.192.in-addr.arpa";
 +};
 +</file>
 +
 +oder mit ''update-policy local'':
 +<file>
 +zone "linuxhotel.de" {
 +        type primary;
 +        update-policy local;
 +        file "linuxhotel.de";
 +};
 +</file>
 +==== bind Konfigurationsdatei prüfen ====
 +  named-checkconf
 +
 +==== bind Schreibzugriff auf Primary-Zonendateien geben ====
 +Debian:
 +  chown bind /var/cache/bind/linuxhotel.de
 +
 +==== Testen: Eintrag hinzufügen ====
 +für ''allow-update'':
 +<file>
 +nsupdate <<EOT
 +
 +server localhost
 +
 +update add notebook23.linuxhotel.de 43200 IN A 192.168.1.223
 +
 +update add 223.1.168.192.in-addr.arpa 43200 IN PTR notebook23.linuxhotel.de
 +
 +EOT
 +</file>
 +
 +für ''update-policy local'':
 +<file>
 +nsupdate -l <<EOT
 +
 +update add notebook23.linuxhotel.de 43200 IN A 192.168.1.223
 +
 +update add 223.1.168.192.in-addr.arpa 43200 IN PTR notebook23.linuxhotel.de
 +
 +EOT
 +</file>
 +
 +==== Trotz nsupdate Zonen mit Editor bearbeiten ====
 +  rndc freeze linuxhotel.de
 +  vim linuxhotel.de
 +  rndc reload linuxhotel.de
 +  rndc thaw linuxhotel.de
 +
 +Hilfreich ist vielleicht:
 +
 +''~/.bashrc'' :
 +<code bash>
 +function zvi {
 +  cd /var/cache/bind
 +  rndc freeze $1
 +  vim $1
 +  rndc reload $1
 +  rndc thaw $1
 +  cd -
 +}
 +</code>
 +
 +===== mehrere NS für eine Zone =====
 +==== Master? Primary! Slave? Secondary! ;-) ====
 +//**Mittlerweile **(Version)** sind auch die Begriffe primary und secondary als Ersatz für master und slave möglich**//
 +
 +  masters { ...; };  =>  primaries { ...; };
 +  type master;  =>  type primary;
 +  type slave;   =>  type secondary;
 +
 +==== Primary konfigurieren ====
 +Erst müssen die Secondary-Nameserver in der Zonendatei des Primarys eingetragen werden:
 +<file>
 +linuxhotel.de. IN NS notebook04.linuxhotel.de.
 +</file>
 +
 +Bei SuSE muß noch der Eintrag
 +<file>
 +notify yes;
 +</file>
 +in der Datei ''/etc/named.conf'' eingetragen werden, oder die Zeile ganz entfernt oder auskommentiert werden.
 +=== testen: funktioniert der Primary? ===
 +== openSuSE 12.3 ==
 +  named-checkzone -i local -D linuxhotel.de /var/lib/named/linuxhotel.de
 +  rndc reload linuxhotel.de
 +  tail /var/log/messages
 +  dig @::1 linuxhotel.de NS
 +
 +== debian 8 ==
 +  named-checkzone -i local -D linuxhotel.de /var/cache/bind/linuxhotel.de
 +  rndc reload linuxhotel.de
 +  journalctl -eu bind9
 +  dig @::1 linuxhotel.de NS
 +
 +==== Secondary konfigurieren ====
 +Vorraussetzung: Primary funktioniert
 +  dig @<IP-des-Primary> linuxhotel.de AXFR
 +
 +Ausgabe muss mindestens 2 NS Records enthalten:
 +  - den eigenen Rechner
 +  - den Primary
 +
 +''/etc/named.conf'' : ( CentOS 5.3 )
 +<file>
 +zone "linuxhotel.de" {
 +        type secondary;
 +        file "secondary/linuxhotel.de";
 +        masters { 192.168.1.220; };
 +};
 +zone "1.168.192.in-addr.arpa" {
 +        type secondary;
 +        file "secondary/1.168.192.in-addr.arpa";
 +        masters { 192.168.1.220; };
 +};
 +</file>
 +
 +  * ''/etc/named.conf'' : ( SuSE 10.0 )
 +  * ''/etc/bind/named.conf.local'' : ( Debian )
 +<file>
 +zone "linuxhotel.de" {
 +        type secondary;
 +        file "secondary/linuxhotel.de";
 +        primaries { 192.168.1.220; };
 +};
 +zone "1.168.192.in-addr.arpa" {
 +        type secondary;
 +        file "secondary/1.168.192.in-addr.arpa";
 +        primaries { 192.168.1.220; };
 +};
 +</file>
 +
 +Zonendateien im Binärformat kann man mit:
 +  named-checkzone -D -f raw linuxhotel.de secondary/linuxhotel.de
 +oder
 +  named-compilezone -f raw -F text -o - example.org. /var/cache/bind/secondary/example.org
 +anzeigen. Wenn man die Zonenfiles **lieber im Textformat statt im Binärformat** haben will, kann man in die Zone eintragen:
 +<file txt>
 +zone "…" {
 +  …
 +  masterfile-format text;
 +  …
 +</file>
 +
 +=== bind Schreibzugriff auf Secondary-Zonendateien geben ===
 +Debian:
 +  mkdir /var/cache/bind/secondary
 +  chown bind /var/cache/bind/secondary
 +
 +=== testen: funktioniert der Secondary? ===
 +== Debian ==
 +  named-checkconf -z
 +  rndc reconfig
 +  journalctl -eu bind9
 +  ls /var/cache/bind/secondary/{linuxhotel.de,1.168.192.in-addr.arpa}
 +  dig @::1 linuxhotel.de AXFR
 +
 +== OpenSuSE 12.3 ==
 +  named-checkconf -z
 +  rcnamed restart
 +  tail /var/log/messages
 +  ls /var/lib/named/secondary/{linuxhotel.de,1.168.192.in-addr.arpa}
 +  dig @::1 linuxhotel.de AXFR
 +
 +=== testen: funktionieren alle verantwortlichen Nameserver? ===
 +  dig @141.1.1.1 linuxhotel.de +nssearch
 +
 +===== Subdomains delegieren =====
 +==== Übergeordneter DNS ====
 +  * ''/etc/named.conf.local'' : ( Debian ab 5.0 )
 +  * ''/etc/named.conf'' : ( CentOS ab 5 )
 +<file>
 +zone "linuxhotel.de" IN {
 +        type primary;
 +        file "linuxhotel.de";
 +        forwarders      { };
 +};
 +</file>
 +
 +:!: Fallstrick: __Unbedingt an **forwarders** denken!__ Und **alle** dnssec Optionen ausschalten :!:
 +
 +''/var/named'' : ( CentOS 5 )
 +<file>
 +sub05.linuxhotel.de.        IN NS ns1.sub05.linuxhotel.de.
 +ns1.sub05.linuxhotel.de.    IN A 192.168.150.110
 +</file>
 +
 +Fallstrick: Seit bind 9.9 werden die empty zones automatisch "aufgefüllt". Dadurch werden aber PTR-RR für nicht eigene Netze nicht mehr geforwarded :!:
 +
 +''/etc/named.conf.options'' : ( Debian 8 )
 +<file>
 +disable-empty-zone "168.192.in-addr.arpa";
 +</file>
 +
 +Das muss auch auf jedem Delegaten konfiguriert werden :!:
 +
 +  named-checkzone -i local -D linuxhotel.de /var/named/linuxhotel.de
 +==== Subdomain DNS ====
 +Wie oben, unter "eigene Zonen in bind verwalten"
 +
 +===== Zonendatei für Subnetz per Skript erzeugen ===== 
 +<code bash>
 +#!/bin/bash
 +NAMESERVER=$(hostname -f)
 +SUBNET=192.168.1
 +
 +cat <<HEAD
 +\$TTL 2h
 +@ IN SOA $NAMESERVER. root.$NAMESERVER. (
 +        $(date '+%Y%m%d')01             ; Seriennummer
 +        3h            ; refresh
 +        1h            ; retry
 +        1w            ; expire
 +        1h            ; negative ttl
 +)
 +
 +  IN NS $NAMESERVER.
 +
 +HEAD
 +
 +for ip in $(seq 1 254)
 +do
 +  getent hosts $SUBNET.$ip | ( read ip name && echo -e "$name.\tIN\tA\t$ip" | expand -t '34 37 43 ' )
 +done
 +</code>
 +
 +
 +====== Dokus & Links ======
 +  * [[ http://www.zytrax.com/books/dns/ | Bind Buch "DNS for Rocket Scientists"]]
 +  * [[ http://en.opensuse.org/Howto_setup_SUSE_as_SAMBA_PDC_with_OpenLDAP%2C_DYNDNS_and_CLAM#Dynamic_DNS_Setup | Howto zu Bind und DHCP unter SuSE]]
 +  * [[ http://www.microsoft.com/technet/archive/interopmigration/linux/mvc/cfgbind.mspx | bind und Active Directory ]]
 +  * [[http://k.root-servers.org|DNS Root Server System]]
 +  * [[http://technet.microsoft.com/de-de/library/cc755717%28WS.10%29.aspx|Zusammenspiel Windows NS und Bind]]
 +  * [[http://www.serverhowto.de/DNS-Server-BIND-9-als-Ersatz-fuer-den-Windows-DNS-Server.277.0.html|Beispiel einer Windows AD unter Bind]]
 +