Linuxhotel Wiki

Wie ging das nochmal?

Benutzer-Werkzeuge

Webseiten-Werkzeuge


lpi2:bind

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen gezeigt.

Link zu der Vergleichsansicht

Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung
lpi2:bind [2019/02/11 05:07]
lpi2:bind [2023/12/08 15:15] (aktuell)
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 (ab 6)
 +
 +''/​etc/​bind/​named.conf.options''​ : Debian (ab 7)
 +<​file>​
 +options {
 +
 +        // In der Praxis ist DNSSEC eine gute Sache ... aber zum Lernen erst mal aus:
 +        dnssec-enable no;
 +        dnssec-validation no;
 +        dnssec-lookaside 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
 +
 +<​file>​
 +flags: … ad
 +</​file>​
 +
 +Unser Nameserver sollte das ad-Flag nicht setzen.
 +
 +===== eigene Zonen in bind verwalten =====
 +==== Vorwärts-Zone ====
 +=== Zonendatei ===
 +Unter Debian und CentOS empfehlen wir ein entsprechendes Verzeichnis ''​primary''​ für die Zonendateien noch anzulegen ((oder man legt die Zonendateien direkt in /​var/​cache/​bind bzw. /var/named ab)):
 +
 +Debian :
 +  mkdir /​var/​cache/​bind/​primary
 +CentOS (ab 5) :
 +  mkdir /​var/​named/​primary
 +
 +''/​var/​named/​primary/​linuxhotel.de''​ : ( CentOS ab 5 )
 +
 +''/​var/​lib/​named/​primary/​linuxhotel.de''​ : ( SuSE ab 10.0)
 +
 +''/​var/​cache/​bind/​primary/​linuxhotel.de''​ : ( Debian ab 3.1 )
 +<​file>​
 +$ORIGIN . ; hilft Tippfehler (fehlender . am Ende) zu vermeiden
 +$TTL 2m   ; time to live: 2 Minuten, default wäre 2 Tage
 +linuxhotel.de. IN 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. ​                 IN NS notebook20.linuxhotel.de.
 +
 +; kanonische IP-Adressen:​
 +notebook22.linuxhotel.de. ​      IN A 192.168.1.222
 +notebook05.linuxhotel.de. ​      IN A 192.168.1.205
 +notebook20.linuxhotel.de. ​      IN A 192.168.1.220
 +notebook06.linuxhotel.de. ​      IN A 192.168.1.206
 +notebook09.linuxhotel.de. ​      IN A 192.168.1.209
 +
 +; Aliase:
 +peter.linuxhotel.de. ​           IN CNAME notebook09.linuxhotel.de.
 +lothar.linuxhotel.de. ​       60 IN CNAME notebook05.linuxhotel.de.
 +heribert.linuxhotel.de. ​     30 IN CNAME notebook06.linuxhotel.de.
 +bjoern.linuxhotel.de. ​          IN CNAME notebook20.linuxhotel.de.
 +admin.linuxhotel.de. ​           IN CNAME notebook22.linuxhotel.de.
 +</​file>​
 +
 +=== Zonendatei überprüfen ===
 +== CentOS (ab 5) ==
 +  named-checkzone -D linuxhotel.de. /​var/​named/​primary/​linuxhotel.de
 +
 +== SuSE (ab 10.0) ==
 +  named-checkzone -D linuxhotel.de. /​var/​lib/​named/​primary/​linuxhotel.de
 +
 +== Debian (ab 3.1) ==
 +  named-checkzone -D linuxhotel.de. /​var/​cache/​bind/​primary/​linuxhotel.de
 +
 +==== Konfigurationsdatei ====
 +''/​etc/​named.conf''​ : ( SuSE 10.2 )
 +
 +''/​etc/​named.conf''​ : ( CentOS ab 5 )
 +
 +''/​etc/​bind/​named.conf.local''​ : ( Debian ab 5.0 )
 +<​file>​
 +zone "​linuxhotel.de"​ {
 +  type primary;
 +  file "​primary/​linuxhotel.de";​
 +};
 +</​file>​
 +
 +Konfigdatei und eingetragene Zonen überprüfen:​
 +  named-checkconf -z
 +
 +=== bind die Änderung mitteilen ===
 +  rndc reconfig
 +oder 
 +
 +openSuSE, centos (ab 7)
 +  service named reload
 +
 +Debian (ab 6)
 +  service bind9 reload
 +
 +=== im Log prüfen, ob es Fehler gab ===
 +Debian (ab 11)
 +  journalctl -eu named.service
 +
 +==== testen ====
 +  host peter.linuxhotel.de 127.0.0.1
 +  dig peter.linuxhotel.de @127.0.0.1 any
 +
 +==== Zonendatei (kurze Schreibweise) ====
 +Das Format der Zonendatei (([[http://​tools.ietf.org/​html/​rfc1035|rfc1035]])) läßt es auch zu, diese Datei sehr viel kürzer zu schreiben:
 +<​file>​
 +$TTL 2h
 +@ SOA notebook20 root.notebook20 1999022301 1d 2h 5w 2d
 +
 +; Nameserver:
 +                 NS notebook20
 +
 +; kanonische IP-Adressen:​
 +notebook22 ​      A 192.168.1.222
 +notebook05 ​      A 192.168.1.205
 +notebook20 ​      A 192.168.1.220
 +notebook06 ​      A 192.168.1.206
 +notebook09 ​      A 192.168.1.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/​primary/​linuxhotel.de
 +
 +== SuSE ==
 +  named-checkzone -D linuxhotel.de. /​var/​lib/​named/​primary/​linuxhotel.de
 +
 +== Debian ==
 +  named-checkzone -D linuxhotel.de. /​var/​cache/​bind/​primary/​linuxhotel.de
 +
 +=== bind die Änderung mitteilen ===
 +  rndc reload linuxhotel.de
 +
 +==== Rückwärts-Zone ====
 +=== Zonendatei ===
 +''/​var/​named/​primary/​1.168.192.in-addr.arpa'':​ ( CentOS )
 +
 +''/​var/​lib/​named/​primary/​1.168.192.in-addr.arpa'':​ ( SuSE 10.0 )
 +
 +''/​var/​cache/​bind/​primary/​1.168.192.in-addr.arpa'':​ ( Debian 3.1 )
 +
 +<​file>​
 +$TTL 2h
 +1.168.192.in-addr.arpa. IN SOA notebook20.linuxhotel.de. root.notebook20.linuxhotel.de. (
 +    2005082401 ​   ; serial
 +    3h            ; refresh
 +    1h            ; retry
 +    1w            ; expire
 +    1h            ; negative ttl
 +)  ​
 +; Nameserver
 +1.168.192.in-addr.arpa. IN 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 (ab 5) ==
 +  named-checkzone -D linuxhotel.de. /​var/​named/​primary/​linuxhotel.de
 +  named-checkzone -D 1.168.192.in-addr.arpa. /​var/​named/​primary/​1.168.192.in-addr.arpa
 +
 +== SuSE (ab 10.0) ==
 +  named-checkzone -D linuxhotel.de. /​var/​lib/​named/​primary/​linuxhotel.de
 +  named-checkzone -D 1.168.192.in-addr.arpa. /​var/​lib/​named/​primary/​1.168.192.in-addr.arpa
 +
 +== Debian (ab 3.1) ==
 +  named-checkzone -D linuxhotel.de. /​var/​cache/​bind/​primary/​linuxhotel.de
 +  named-checkzone -D 1.168.192.in-addr.arpa. /​var/​cache/​bind/​primary/​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 "​primary/​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 127.0.0.1
 +  dig -x 192.168.1.222 @127.0.0.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 "​primary/​linuxhotel.de";​
 +};
 +
 +zone "​1.168.192.in-addr.arpa"​ {
 +        type primary;
 +        allow-update { "​nsupdate";​ };
 +        file "​primary/​1.168.192.in-addr.arpa";​
 +};
 +</​file>​
 +
 +oder mit ''​update-policy local'':​
 +<​file>​
 +zone "​linuxhotel.de"​ {
 +        type primary;
 +        update-policy local;
 +        file "​primary/​linuxhotel.de";​
 +};
 +</​file>​
 +==== bind Konfigurationsdatei prüfen ====
 +  named-checkconf
 +
 +==== bind Schreibzugriff auf Primary-Zonendateien geben ====
 +Debian:
 +  chown -R bind /​var/​cache/​bind/​primary
 +
 +==== 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/​primary
 +  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/​primary/​linuxhotel.de
 +  rndc reload linuxhotel.de
 +  tail /​var/​log/​messages
 +  dig @127.0.0.1 linuxhotel.de NS
 +
 +== debian 8 ==
 +  named-checkzone -i local -D linuxhotel.de /​var/​cache/​bind/​primary/​linuxhotel.de
 +  rndc reload linuxhotel.de
 +  journalctl -eu bind9
 +  dig @127.0.0.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 @127.0.0.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 @127.0.0.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 "​primary/​linuxhotel.de";​
 +        forwarders ​     { };
 +};
 +</​file>​
 +
 +:!: Fallstrick: __Unbedingt an **forwarders** denken!__ Und **alle** dnssec Optionen ausschalten :!:
 +
 +''/​var/​named/​primary''​ : ( 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/​primary/​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]]
 +