2 # rebuild a zone file, adding all DCs
5 echo "rebuild_zone.sh <sam.ldb> <zonefile>"
12 dnshostname
=$
(bin
/ldbsearch
-H $LDB -s base
-b '' dnsHostname |
grep ^dns | cut
-d' ' -f2)
13 host=$
(echo $dnshostname | cut
-d.
-f1)
14 realm
=$
(echo $dnshostname | cut
-d.
-f2-)
15 GUIDs
=$
(bin
/ldbsearch
-H $LDB objectclass
=ntdsdsa objectguid
--cross-ncs|
grep ^objectGUID| cut
-d' ' -f2)
16 DOMAINGUID
=$
(bin
/ldbsearch
-H $LDB -s base objectguid |
grep ^objectGUID| cut
-d' ' -f2)
20 echo $
(bin
/ldbsearch
-H $LDB objectguid
=$GUID dn
--cross-ncs|
grep CN
=NTDS.Settings| cut
-d, -f2| cut
-d= -f2)
25 ret
=$
(nmblookup
$NAME|
egrep '^[0-9]' |
head -1 | cut
-d' ' -f1)
27 echo "Unable to find IP for $NAME. Using XX.XX.XX.XX. Please edit" 1>&2
33 echo "Generating header for host $host in realm $realm"
36 ; generated by rebuild_zone.sh
39 @ IN SOA @ hostmaster (
40 $(date +%Y%m%d%H) ; serial
49 for GUID
in $GUIDs; do
51 echo "Generating IP for DC $dc"
53 test -n "$ip" ||
exit 1
54 echo " IN A $ip" >> $ZFILE
57 echo "; IP Addresses" >> $ZFILE
58 for GUID
in $GUIDs; do
61 test -n "$ip" ||
exit 1
62 echo "$dc IN A $ip" >> $ZFILE
65 for GUID
in $GUIDs; do
68 test -n "$ip" ||
exit 1
69 echo "Generating zone body for DC $dc with IP $ip"
74 $GUID._msdcs IN CNAME $dc
75 _gc._tcp IN SRV 0 100 3268 $dc
76 _gc._tcp.Default-First-Site-Name._sites IN SRV 0 100 3268 $dc
77 _ldap._tcp.gc._msdcs IN SRV 0 100 389 $dc
78 _ldap._tcp.Default-First-Site-Name._sites.gc._msdcs IN SRV 0 100 389 $dc
79 _ldap._tcp IN SRV 0 100 389 $dc
80 _ldap._tcp.dc._msdcs IN SRV 0 100 389 $dc
81 _ldap._tcp.pdc._msdcs IN SRV 0 100 389 $dc
82 _ldap._tcp.$DOMAINGUID.domains._msdcs IN SRV 0 100 389 $dc
83 _ldap._tcp.Default-First-Site-Name._sites IN SRV 0 100 389 $dc
84 _ldap._tcp.Default-First-Site-Name._sites.dc._msdcs IN SRV 0 100 389 $dc
85 _kerberos._tcp IN SRV 0 100 88 $dc
86 _kerberos._tcp.dc._msdcs IN SRV 0 100 88 $dc
87 _kerberos._tcp.Default-First-Site-Name._sites IN SRV 0 100 88 $dc
88 _kerberos._tcp.Default-First-Site-Name._sites.dc._msdcs IN SRV 0 100 88 $dc
89 _kerberos._udp IN SRV 0 100 88 $dc
90 _kerberos-master._tcp IN SRV 0 100 88 $dc
91 _kerberos-master._udp IN SRV 0 100 88 $dc
92 _kpasswd._tcp IN SRV 0 100 464 $dc
93 _kpasswd._udp IN SRV 0 100 464 $dc
100 _kerberos IN TXT $(echo $realm | tr [a-z] [A-Z])
103 echo "Rebuilt zone file $ZFILE OK"
105 echo "Reloading bind config"
106 PATH
="/usr/sbin:$PATH" rndc reload