1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
#!/bin/sh -e
#
# Interactively configure BIND for Debian
#
# Robert Leslie <rob@mars.org>
reload="yes"
umask 022
###############################################################################
while [ $# -gt 0 ]
do
case "$1" in
--no-reload)
reload=""
shift
;;
*)
echo "Usage: $0 [--no-reload]" >&2
exit 1
;;
esac
done
###############################################################################
descrip() {
echo ""
echo "$1"
echo "$1" | sed -e 's/./-/g'
cat -
echo ""
}
yesno() {
local N="N" Y="Y"
local q="$1" def=$(eval "echo -n \$$2")
while :
do
echo -n "$q? [$def] "
read REPLY
REPLY=$(echo "$REPLY" | sed -e 's/^[ ]*//' -e 's/[ ]*$//')
test -n "$REPLY" || REPLY="$def"
case "$REPLY" in
[Yy]*)
eval "$2=\"Y\""
return 0
;;
[Nn]*)
eval "$2=\"N\""
return 1
;;
esac
done
}
input() {
local q="$1" def=$(eval "echo -n \$$2")
echo -n "$q? [$def] "
read REPLY
REPLY=$(echo "$REPLY" | sed -e 's/^[ ]*//' -e 's/[ ]*$//')
test -n "$REPLY" || REPLY="$def"
if [ NONE = "$3" ]
then
test none != "$REPLY" -a NONE != "$REPLY" || REPLY=""
fi
eval "$2=\"$REPLY\""
}
testconfig() {
CONFIG=$(grep "$1" $options 2>/dev/null)
}
reload() {
if [ "$reload" ] && \
yesno "Reload named now with the new configuration" Y
then
echo "Reloading named ..."
/etc/init.d/bind reload >/dev/null
fi
}
###############################################################################
options="/var/named/boot.options"
zones="/var/named/boot.zones"
exec 3>$options.new
trap "rm -f $options.new" 0
###############################################################################
if [ -f /etc/named.conf ]; then
echo ""
echo "It appears that you already have an /etc/named.conf file, suggesting"
echo "that you have already configured BIND version 8.X at least once. If"
echo "you proceed, a copy of this file will be saved, but no customizations"
echo "that you have made to it will be included in the new configuration."
echo ""
echo "If this means nothing to you, go ahead and proceed with the remainder"
echo "of the configuration process. If you have customized /etc/named.conf,"
echo "you probably want to stop now to preserve your customizations."
echo ""
yesno "Proceed to configure BIND, ignoring existing /etc/named.conf" N \
|| exit 0
fi
###############################################################################
descrip "BIND Configuration" <<EOT
By answering the following questions, you can configure BIND for your system.
If your system has already been configured, the default values will allow you
to verify your existing configuration.
EOT
echo -n "Press [ENTER] "
read REPLY
cat >&3 <<EOT
;
; Options for name server
; Use \`bindconfig' to automatically configure this file
;
EOT
###############################################################################
descrip "Forwarder Hosts" <<EOT
If you are close to a well-connected host or set of hosts which accept
recursive DNS queries, it would be to your advantage to use them as forwarders
in order to reduce traffic over links to outside servers.
Your DNS server will send all queries not in its cache to the forwarders
first. Each forwarder will be asked in turn until an answer is returned or the
list is exhausted. If no answer is forthcoming from a forwarder, the server
will continue as it would have without the forwarders.
To answer this question, separate each address with a space, or answer \`none'
to eliminate all forwarder hosts.
EOT
forwarders=""
! test -f $options || \
forwarders=$(sed -n -e '/^forwarders/s/^forwarders//p' $options |
tr -s '\n \t' ' ' | sed -e 's/^ *//' -e 's/ *$//')
input "Forwarder IP addresses" forwarders NONE
test -z "$forwarders" || echo "forwarders $forwarders" >&3
###############################################################################
if [ -n "$forwarders" ]
then
descrip "Forward Only" <<EOT
You can configure your DNS server as a "slave" -- that is, it will query only
the forwarder host(s) for answers to queries not in its cache. This is
recommended if your machine is not directly connected to the Internet, because
your server will then not try to contact hosts other than the forwarders.
EOT
forwardonly="N"
! testconfig "^options[ ]*forward-only" || forwardonly="Y"
! yesno "Enable forward-only mode" forwardonly || \
echo "options forward-only" >&3
fi
###############################################################################
descrip "Localhost Entries" <<EOT
With this option, BIND will contain entries for the \`localhost' pseudo-host
and its reverse mapping (127.0.0.1). This is recommended.
EOT
localhost="Y"
if [ -f $options ]
then
testconfig "^primary[ ]*localhost" || localhost="N"
fi
! yesno "Enable localhost entries" localhost || cat >&3 <<EOT
; type domain source file
primary localhost named.local
primary 127.in-addr.arpa named.rev-local
EOT
###############################################################################
echo "" >&3
if [ -f $options ]
then
sed -n -e '/^;; Custom/,$p' $options >&3
else
echo ";; Custom configurations below (will be preserved)" >&3
fi
if [ ! -f $zones ]
then
cat >$zones <<EOT
;
; Name server zone boot file
; See named(8) for syntax and further information
;
; type domain source file
EOT
fi
descrip "Configuration Complete" <<EOT
Advanced configuration, such as sortlists, xfrnets, limits, and other options
can be accomplished by manually editing the /var/named/boot.options
configuration file and reloading your nameserver. You may wish to refer to
the named(8) man page or review the documentation in /usr/doc/net/named to
assist in further customization.
This automatic configuration does not manipulate zone files; you should ensure
the proper boot entries are made in /var/named/boot.zones for each primary and
secondary zone you are serving. If you leave this file empty, your server will
act conveniently as a caching-only name server.
EOT
###############################################################################
exec 3>&-
if [ -f $options ]
then
echo "Saving old $options to $options.old ..."
mv -f $options $options.old
fi
mv -f $options.new $options
trap - 0
# Make sure we have a good /etc/named.boot
test ! -L /etc/named.boot || rm -f /etc/named.boot
if [ -e /etc/named.boot ]
then
echo "Moving your /etc/named.boot to /var/named and leaving a symlink ..."
mv -vi /etc/named.boot /var/named/named.boot.old
fi
ln -s ../var/named/named.boot /etc/named.boot
if [ -x /usr/sbin/named-bootconf ]
then
/usr/sbin/named-bootconf
fi
reload
exit 0
|