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
|
#!/bin/sh
###########################################
# Script Installation BIN9 #
###########################################
# #
# $1: Mot de passe mysql #
# $2 contient le mode d'installation #
# (online ou offline) #
# #
###########################################
# Test si l'installation doit etre en ligne ou hors ligne
# si $2 == 1 mode online
# sinon mode offline
if [ $2 -eq 1 ]
then
# Telechargement de bind9
wget -P /usr/local/src/ http://ftp.isc.org/isc/bind9/9.8.0/bind-9.8.0.tar.gz
else
# Deplacement de l'archive de bind9
cp ./../../soft/bind*.tar.gz /usr/local/src/
fi
# On descent dans le dossier contenant les fichiers
cd /usr/local/src/
#*************************** Installation de Bind9 ********************************#
# Decompression de l'archive
tar xzf /usr/local/src/bind*.tar.gz
# Supression de l'archive
rm /usr/local/src/bind*.tar.gz
# ajout d'un group et d'un utilisateur pour bind9
groupadd bind9
useradd g bind9 bind9
# Descente dans le repertoire de Bind9
cd /usr/local/src/bind*
# Configuration de la compilation
#(on interface bind avec mysql et on lui permet d'utilisé openssl)
./configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --localstatedir=/var --sysconfdir=/etc/bind --with-openssl=/usr/local/ssl --with-dlz-mysql=/usr/local/mysql
# Compilation
make
#installation
make install
#******************* Configuration de Bind9 ***********************************#
# Creation de l'utilisateur bind9 et de la base bind9 dans MySQL
mysql -u root -p$1 -e "CREATE USER 'bind9'@'localhost' IDENTIFIED BY '"$1"';"
mysql -u root -p$1 -e "CREATE DATABASE IF NOT EXISTS bind9 ;"
mysql -u root -p$1 -e "GRANT ALL PRIVILEGES on bind9.* to bind9@'localhost' identified by '"$1"';"
mysql -u root -p$1 -e "FLUSH PRIVILEGES;"
# Creation de la table pour bind9 dans MySQL
mysql -u bind9 -p$1 -D bind9 -e "CREATE TABLE IF NOT EXISTS dns_records (
id int(11) NOT NULL AUTO_INCRserEMENT,
zone varchar(64) DEFAULT NULL,
host varchar(64) DEFAULT NULL,
type varchar(8) DEFAULT NULL,
data varchar(64) DEFAULT NULL,
ttl int(11) NOT NULL DEFAULT '3600',
mx_priority int(11) DEFAULT NULL,
refresh int(11) NOT NULL DEFAULT '3600',
retry int(11) NOT NULL DEFAULT '3600',
expire int(11) NOT NULL DEFAULT '86400',
minimum int(11) NOT NULL DEFAULT '3600',
serial bigint(20) NOT NULL DEFAULT '2008082700',
resp_person varchar(64) NOT NULL DEFAULT 'resp.person.email',
primary_ns varchar(64) NOT NULL DEFAULT 'ns1.yourdns.here',
data_count int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
KEY host (host),
KEY zone (zone),
KEY type (type)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;"
# Creation du fichier de configuration qui va permettre d'aller cherché les informations dans la BDD
echo "dlz \"Mysql zone\" { database \"mysql
{host=localhost dbname=bind9 user=bind9 pass="$mdp" ssl=false}
{select zone from dns_records where zone = '\$zone\$'}
{select ttl, type, mx_priority, case when lower(type)='txt' then concat('\\\"', data, '\\\"')
when lower(type) = 'soa' then concat_ws(' ', data, resp_person, serial, refresh, retry, expire, minimum)
else data end from dns_records where zone = '\$zone\$' and host = '\$record\$'}\";
};">/etc/bind/named.conf.local
# Creation du fichier d'option de bind9
echo '
options {
directory "/var/cache/bind";
// cacher sa version de bind9
version "L Administrateur vous regarde..."
forward first;
forwarders {
89.2.0.1;
};
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
recursion yes;
allow-recursion { localhost; 127.0.0.1; 90.11.175.142; 89.25.28.21; 12.6.0.1; };
allow-query-cache { localhost; 127.0.0.1; 90.11.175.142; 89.25.28.21; 12.6.0.1; };
dnssec-enable yes;
additional-from-cache yes;
zone-statistics yes;
statistics-file "/etc/bind/named.stats";
};
'>/etc/bind/named.conf.options
# Creation du fichier de configuration global de bind9
echo '
# inclut le fichier de conf pour mysql
include "/etc/bind/named.conf.local";
# inclut le fichier d option pour bind
include "/etc/bind/named.conf.options";
'>/etc/bind/named.conf
#************************* Demarrage automatique ***********************#
# Creation du script de demmarrage
echo '#!/bin/sh
### BEGIN INIT INFO
# Provides: Bind9
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 6
# Short-Description: Le script permet le lancement de bind9
# Description: Le script permet le lancement automatique au demarrage de bind9
### END INIT INFO
prog="named"
case "$1" in
start)
echo -n "Starting $prog: "
/usr/sbin/named -u bind9 -c /etc/bind/named.conf
lancer=$(pidof named|wc -l)
if [ $lancer -eq 0 ]
then
echo " \033[31mFail!!!!\033[00m"
else
echo " \033[32m[OK]\033[00m"
echo "named start on pid: $(pidof named)"
fi
;;
stop)
echo -n "Stopping $prog: "
killall /usr/sbin/named
lancer=$(pidof named|wc -l)
if [ $lancer -ne 0 ]
then
echo " \033[31mFail!!!!\033[00m"
echo "named is always on run"
else
echo " \033[32m[OK]\033[00m"
echo "named is stop"
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
status)
lancer=$(pidof named|wc -l)
if [ $lancer -eq 0 ]
then
echo "named stop"
else
echo "named start on pid: $(pidof named)"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
'>/etc/init.d/bind9
# Attribution des droits d execution
chmod +x /etc/init.d/bind9
# Creation des liens pour le demarrage
update-rc.d bind9 start 50 2 3 4 5 . stop 50 0 6 . |
Partager