Commit 8545b11681a7e58606373a83d59b9f40c52bf144
1 parent
d46d85abb9
Exists in
master
e09fbe56-dc1f-4f12-b3d8-9a003944e560
Showing 1 changed file with 183 additions and 0 deletions
configure_bind9.sh
View file @
8545b11
1 | +#!/bin/bash | |
2 | + | |
3 | +if [[ $(/usr/bin/id -u) -ne 0 ]]; then | |
4 | + echo "Erreur !!!" | |
5 | + echo "Doit etre execute avec sudo" | |
6 | + exit 1 | |
7 | +fi | |
8 | + | |
9 | +bind9=`whereis bind9` | |
10 | +bind=`whereis bind` | |
11 | +bind9Ok=${bind9#*:} | |
12 | +bindOk=${bind#*:} | |
13 | +if [ "$bind9Ok" == "" ] && [ "$bindOk" == "" ]; then | |
14 | + echo "Le programme Bind n'est peut etre pas installe." | |
15 | + echo "Executer \"sudo apt-get install bind9\"" | |
16 | + exit 2 | |
17 | +fi | |
18 | + | |
19 | +adresse_ip=`hostname -i` | |
20 | +echo "Adresse IP : "$adresse_ip | |
21 | +echo "Est-ce correct ? [O/n]" | |
22 | +read reponse | |
23 | +if [ "$reponse" != "o" ] && [ "$reponse" != "O" ] && [ "$reponse" != "" ]; then | |
24 | + echo "Veuillez verifier vos parametres" | |
25 | + exit 2 | |
26 | +fi | |
27 | + | |
28 | +nom_de_domaine=`hostname -d` | |
29 | +echo "Nom de domaine : "$nom_de_domaine | |
30 | +echo "Est-ce correct ? [O/n]" | |
31 | +read reponse | |
32 | +if [ "$reponse" != "o" ] && [ "$reponse" != "O" ] && [ "$reponse" != "" ]; then | |
33 | + echo "Veuillez verifier votre fichier /etc/hosts" | |
34 | + exit 2 | |
35 | +fi | |
36 | + | |
37 | +host_name=`hostname` | |
38 | +echo "Nom d'hote : "$host_name | |
39 | +echo "Est-ce correct ? [O/n]" | |
40 | +read reponse | |
41 | +if [ "$reponse" != "o" ] && [ "$reponse" != "O" ] && [ "$reponse" != "" ]; then | |
42 | + echo "Veuillez verifier votre fichier /etc/hosts" | |
43 | + exit 2 | |
44 | +fi | |
45 | + | |
46 | +rep_bind="/etc/bind" | |
47 | +if [ ! -d $rep_bind ]; then | |
48 | + echo "Le repertoire $rep_bind n'existe pas !" | |
49 | + echo "Le programme Bind n'est peut etre pas installe." | |
50 | + echo "Executer \"sudo apt-get install bind9\"" | |
51 | + exit 2 | |
52 | +fi | |
53 | + | |
54 | +named_conf="/etc/bind/named.conf" | |
55 | +if [ ! -f $named_conf ]; then | |
56 | + echo "Le fichier $named_conf n'existe pas !" | |
57 | + echo "Le programme Bind n'est peut etre pas installe." | |
58 | + echo "Executer \"sudo apt-get install bind9\"" | |
59 | + exit 2 | |
60 | +fi | |
61 | + | |
62 | +old="$IFS" | |
63 | +IFS="." | |
64 | +tab=( $adresse_ip ) | |
65 | +IFS="$old" | |
66 | + | |
67 | +for (( i=0 ; i<${#tab[*]} ; i++ )) ; do | |
68 | + echo $i" -> "${tab[$i]} | |
69 | +done | |
70 | + | |
71 | +addr=${tab[2]}"."${tab[1]}"."${tab[0]} | |
72 | +addr_inv=${tab[0]}"."${tab[1]}"."${tab[2]} | |
73 | +file_conf=$rep_bind"/named.conf."$host_name | |
74 | +file_nom_de_domaine=$rep_bind"/zones/"$nom_de_domaine".hosts" | |
75 | +file_in_addr=$rep_bind"/zones/rev."$addr_inv".in-addr.arpa" | |
76 | + | |
77 | +echo "Creation du fichier \"$file_conf\"" | |
78 | +echo "" > $file_conf | |
79 | +echo "Ajout des informations dans le fichier \"$rep_bind"/named.conf."$host_name\"" | |
80 | + | |
81 | +echo "zone \"$nom_de_domaine\" { | |
82 | + type master; | |
83 | + file \"$file_nom_de_domaine\"; | |
84 | +};" >> $file_conf | |
85 | + | |
86 | +echo "" >> $file_conf | |
87 | + | |
88 | +echo "zone \"$addr.in-addr.arpa\" { | |
89 | + type master; | |
90 | + file \"$file_in_addr\"; | |
91 | +};" >> $file_conf | |
92 | + | |
93 | +echo "Ajout du lien vers \"$file_conf\" dans le fichier \"$named_conf\"" | |
94 | +echo "include \"$file_conf\";" >> $named_conf | |
95 | + | |
96 | +rep_zones=$rep_bind"/zones" | |
97 | +echo "Creation du repertoire \"$rep_zones\"" | |
98 | +mkdir $rep_zones | |
99 | + | |
100 | +hostname_f=`hostname -f` | |
101 | +echo "Creation du fichier \"$file_nom_de_domaine\"" | |
102 | +echo "" > $file_nom_de_domaine | |
103 | +echo "\$ttl 86400 | |
104 | +@ IN SOA $hostname_f. mail.$nom_de_domaine. ( | |
105 | + 2008061803 | |
106 | + 21600 | |
107 | + 3600 | |
108 | + 604800 | |
109 | + 86400 ) | |
110 | + | |
111 | +;ENREGISTREMENT \"A\" DNS <-> IP CLASSIQUES | |
112 | +@ IN NS mail.$nom_de_domaine. | |
113 | + IN MX 10 mail.$nom_de_domaine. | |
114 | + IN A $adresse_ip | |
115 | +mail IN A $adresse_ip | |
116 | +$host_name IN A $adresse_ip | |
117 | + | |
118 | +;ENREGISTREMENT MESSAGERIE | |
119 | +$nom_de_domaine. IN MX 10 $host_name" >> $file_nom_de_domaine | |
120 | + | |
121 | + | |
122 | +echo "Creation du fichier \"$file_in_addr\"" | |
123 | +echo "" > $file_in_addr | |
124 | +echo "@ IN SOA $nom_de_domaine. admin.$nom_de_domaine. ( | |
125 | + 2006081403; | |
126 | + 28800; | |
127 | + 604800; | |
128 | + 604800; | |
129 | + 86400); | |
130 | + | |
131 | + IN NS $hostname_f. | |
132 | +${tab[3]} IN PTR $hostname_f." >> $file_in_addr | |
133 | + | |
134 | +named_conf_options=$rep_bind"/named.conf.options" | |
135 | +echo "Creation du fichier \"$named_conf_options\"" | |
136 | +if [ -f $named_conf_options ]; then | |
137 | + mv $named_conf_options $named_conf_options".save" | |
138 | +fi | |
139 | +echo "" > $named_conf_options | |
140 | +echo "options { | |
141 | + directory \"/var/cache/bind\"; | |
142 | + | |
143 | + query-source address * port 53; | |
144 | + | |
145 | + forwarders { | |
146 | + 212.27.40.240; | |
147 | + 212.27.40.241; | |
148 | + }; | |
149 | + | |
150 | + auth-nxdomain no; # conform to RFC1035 | |
151 | + listen-on-v6 { any; }; | |
152 | +};" >> $named_conf_options | |
153 | + | |
154 | +echo "Configuration terminee." | |
155 | +echo "Appuyer sur Entree pour continuer..." | |
156 | +read | |
157 | + | |
158 | +echo "Redemarrage de Bind9" | |
159 | +/etc/init.d/bind9 restart | |
160 | +echo "Appuyer sur Entree pour continuer..." | |
161 | +read | |
162 | + | |
163 | +echo "Verification de la configuration" | |
164 | +named-checkconf | |
165 | +echo "Appuyer sur Entree pour continuer..." | |
166 | +read | |
167 | + | |
168 | +echo "Verification des enregistrements MX" | |
169 | +dig mx $nom_de_domaine | |
170 | +echo "Appuyer sur Entree pour continuer..." | |
171 | +read | |
172 | + | |
173 | +echo "Verification des enregistrements A" | |
174 | +dig a "mail."$nom_de_domaine | |
175 | +echo "Appuyer sur Entree pour continuer..." | |
176 | +read | |
177 | + | |
178 | +echo "Verification des enregistrements DNS" | |
179 | +nslookup $nom_de_domaine | |
180 | +echo "Appuyer sur Entree pour continuer..." | |
181 | +read | |
182 | + | |
183 | +exit 0 |