Skip to content

Commit b1e3bb4

Browse files
author
root
committed
Finalize DNSSEC
1 parent 234a7f9 commit b1e3bb4

File tree

2 files changed

+88
-4
lines changed

2 files changed

+88
-4
lines changed

envfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
SHARED_SECRET=changeme
22
ZONE=example.org
3-
RECORD_TTL=3600
3+
RECORD_TTL=3600
4+
NS=ns.example.org

setup.sh

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,29 @@ zone "$ZONE" {
1818
EOF
1919

2020
echo "creating zone file..."
21+
if [ 'z "$NS" ]
22+
then
23+
IFS="," read -r -a elements <<< "$NS"
24+
for element in ${elements[@]}
25+
do
26+
SHORT+="${element%%.*}. "
27+
LONG+="$element. "
28+
done
29+
else
30+
SHORT="${NS%%.*}."
31+
LONG+="$NS."
32+
fi
2133
cat > /var/cache/bind/$ZONE.zone <<EOF
2234
\$ORIGIN .
2335
\$TTL 86400 ; 1 day
24-
$ZONE IN SOA localhost. root.localhost. (
36+
$ZONE IN SOA $SHORT $LONG (
2537
74 ; serial
2638
3600 ; refresh (1 hour)
2739
900 ; retry (15 minutes)
2840
604800 ; expire (1 week)
2941
86400 ; minimum (1 day)
3042
)
31-
NS localhost.
43+
NS $SHORT
3244
\$ORIGIN ${ZONE}.
3345
\$TTL ${RECORD_TTL}
3446
EOF
@@ -44,9 +56,80 @@ then
4456
"Zone": "${ZONE}.",
4557
"Domain": "${ZONE}",
4658
"NsupdateBinary": "/usr/bin/nsupdate",
47-
"RecordTTL": ${RECORD_TTL}
59+
"RecordTTL": ${RECORD_TTL}
4860
}
4961
EOF
5062
fi
5163
5264
chown -R bind:bind /var/cache/bind
65+
66+
# DNSSEC configuration
67+
if [ ! -f /var/cache/bind/$ZONE.zone.signed ]
68+
then
69+
echo "Signing zone..."
70+
cd /var/cache/bind
71+
dnssec-keygen -a NSEC3RSASHA1 -b 2048 -n ZONE $ZONE
72+
dnssec-keygen -f KSK -a NSEC3RSASHA1 -b 4096 -n ZONE $ZONE
73+
for key in `ls K${ZONE}*.key`
74+
do
75+
echo "\$INCLUDE $key">> $ZONE.zone
76+
done
77+
78+
dnssec-signzone -A -3 $(head -c 1000 /dev/urandom | sha1sum | cut -b 1-16) -N INCREMENT -o $ZONE -t $ZONE.zone
79+
fi
80+
81+
# Increase safety to prevents hacks with raindow tables
82+
if [ ! -f /usr/sbin/zonesigner.sh ]
83+
then
84+
echo "Creating /usr/sbin/zonesigner.sh..."
85+
cat > /usr/sbin/zonesigner.sh <<EOF
86+
#!/bin/sh
87+
88+
PDIR=\`pwd\`
89+
ZONEDIR="/var/cache/bind" #location of your zone files
90+
ZONE=\$1
91+
ZONEFILE=\$2
92+
DNSSERVICE="bind9" #On CentOS/Fedora replace this with "named"
93+
cd \$ZONEDIR
94+
SERIAL=\`/usr/sbin/named-checkzone \$ZONE \$ZONEFILE | egrep -ho '[0-9]{10}'\`
95+
sed -i 's/'\$SERIAL'/'\$((\$SERIAL+1))'/' \$ZONEFILE
96+
/usr/sbin/dnssec-signzone -A -3 \$(head -c 1000 /dev/urandom | sha1sum | cut -b 1-16) -N increment -o \$1 -t \$2
97+
service \$DNSSERVICE reload
98+
cd \$PDIR
99+
EOF
100+
101+
chmod +x /usr/sbin/zonesigner.sh
102+
fi
103+
104+
if [ ! -f /var/spool/cron/crontabs/root ]
105+
then
106+
echo "Implements crontab..."
107+
cat > /var/spool/cron/crontabs/root <<EOF
108+
# Edit this file to introduce tasks to be run by cron.
109+
#
110+
# Each task to run has to be defined through a single line
111+
# indicating with different fields when the task will be run
112+
# and what command to run for the task
113+
#
114+
# To define the time you can provide concrete values for
115+
# minute (m), hour (h), day of month (dom), month (mon),
116+
# and day of week (dow) or use '*' in these fields (for 'any').#
117+
# Notice that tasks will be started based on the cron's system
118+
# daemon's notion of time and timezones.
119+
#
120+
# Output of the crontab jobs (including errors) is sent through
121+
# email to the user the crontab file belongs to (unless redirected).
122+
#
123+
# For example, you can run a backup of all your user accounts
124+
# at 5 a.m every week with:
125+
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
126+
#
127+
# For more information see the manual pages of crontab(5) and cron(8)
128+
#
129+
# m h dom mon dow command
130+
0 0 */3 0 0 /usr/sbin/zonesigner.sh $ZONE $ZONE.zone
131+
EOF
132+
fi
133+
134+
echo "Service Bind9 restart..."
135+
service bind9 restart

0 commit comments

Comments
 (0)