mailinabox/scripts/dns.sh

46 lines
1.2 KiB
Bash
Raw Normal View History

# DNS: Configure a DNS server using nsd
#######################################
2013-08-21 20:53:22 +00:00
# After running this script, you also must run scripts/dns_update.sh,
# and any time a zone file is added/changed/removed, and any time a
# new domain name becomes in use by a mail user.
#
# This script will turn on DNS for $PUBLIC_HOSTNAME.
2014-04-18 00:17:24 +00:00
# Install nsd, our DNS server software.
2013-08-21 20:53:22 +00:00
# ...but first, we have to create the user because the
# current Ubuntu forgets to do so in the .deb
# see issue #25 and https://bugs.launchpad.net/ubuntu/+source/nsd/+bug/1311886
if id nsd > /dev/null 2>&1; then
true; #echo "nsd user exists... good";
else
useradd nsd;
fi
# Okay now install the package.
2014-04-18 00:17:24 +00:00
apt-get -qq -y install nsd
2013-08-21 20:53:22 +00:00
2014-04-18 00:17:24 +00:00
# Prepare nsd's configuration.
2014-04-18 00:17:24 +00:00
sudo mkdir -p /var/run/nsd
2013-08-21 20:53:22 +00:00
mkdir -p "$STORAGE_ROOT/dns";
# Create the default zone if it doesn't exist.
if [ ! -f "$STORAGE_ROOT/dns/$PUBLIC_HOSTNAME.txt" ]; then
# can be an empty file, defaults are applied elsewhere
cat > "$STORAGE_ROOT/dns/$PUBLIC_HOSTNAME.txt" << EOF;
EOF
fi
# Let the storage user own all DNS configuration files.
chown -R $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/dns
# Permit DNS queries on TCP/UDP in the firewall.
2013-08-21 20:53:22 +00:00
ufw allow domain