Subversion Repositories ALCASAR

Rev

Rev 1062 | Rev 1072 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
872 richard 1
#!/bin/bash
64 franck 2
# $Id: alcasar-iptables.sh 1063 2013-04-01 21:36:46Z richard $
675 richard 3
# Script de mise en place des regles du parefeu d'Alcasar (mode normal)
568 richard 4
# This script write the netfilter rules for ALCASAR
675 richard 5
# Rexy - 3abtux - CPN
6
#
7
# Reminders
568 richard 8
# There are three channels for log :
498 richard 9
#	1 (default) for tracability;
10
#	2 for secure admin (ssh);
11
#	3 for exterior access attempts.
783 richard 12
# The French Security Agency (ANSSI) rules was applied by 'this script
675 richard 13
# The bootps/dhcp (67) port is always open on tun0/eth1 by coova 
612 richard 14
conf_file="/usr/local/etc/alcasar.conf"
766 richard 15
private_ip_mask=`grep PRIVATE_IP= $conf_file|cut -d"=" -f2`
615 richard 16
private_ip_mask=${private_ip_mask:=192.168.182.1/24}
783 richard 17
PRIVATE_IP=`echo $private_ip_mask | cut -d"/" -f1`			# ALCASAR LAN IP address
604 richard 18
private_network=`/bin/ipcalc -n $private_ip_mask|cut -d"=" -f2`		# LAN IP address (ie.: 192.168.182.0)
19
private_prefix=`/bin/ipcalc -p $private_ip_mask|cut -d"=" -f2`		# LAN prefix (ie. 24)
783 richard 20
PRIVATE_NETWORK_MASK=$private_network/$private_prefix			# Lan IP address + prefix (192.168.182.0/24)
21
public_ip_mask=`grep PUBLIC_IP= $conf_file|cut -d"=" -f2`		# ALCASAR WAN IP address
22
PUBLIC_IP=`echo $public_ip_mask | cut -d"/" -f1`
766 richard 23
dns1=`grep DNS1= $conf_file|cut -d"=" -f2`				# first public DNS server
615 richard 24
dns1=${dns1:=208.67.220.220}
766 richard 25
dns2=`grep DNS2= $conf_file|cut -d"=" -f2`				# second public DNS server
615 richard 26
dns2=${dns2:=208.67.222.222}
783 richard 27
DNSSERVERS="$dns1,$dns2"						# first and second DNS IP servers addresses
766 richard 28
PROTOCOLS_FILTERING=`grep PROTOCOLS_FILTERING= $conf_file|cut -d"=" -f2`	# Network protocols filter (on/off)
615 richard 29
PROTOCOLS_FILTERING=${PROTOCOLS_FILTERING:=off}
766 richard 30
DNS_FILTERING=`grep DNS_FILTERING= $conf_file|cut -d"=" -f2`		# DNS and URLs filter (on/off)
615 richard 31
DNS_FILTERING=${DNS_FILTERING:=off}
783 richard 32
QOS=`grep QOS= $conf_file|cut -d"=" -f2`				# QOS (on/off)
615 richard 33
QOS=${QOS:=off}
783 richard 34
SSH=`grep SSH= $conf_file|cut -d"=" -f2`				# sshd active (on/off)
615 richard 35
SSH=${SSH:=off}
1063 richard 36
SSH_ADMIN_FROM=`grep SSH_ADMIN_FROM= $conf_file|cut -d"=" -f2`
37
SSH_ADMIN_FROM=${SSH_ADMIN_FROM:="0.0.0.0/0.0.0.0"}			# WAN IP address to reduce ssh access (all ip allowed on LAN side)
783 richard 38
LDAP=`grep LDAP= $conf_file|cut -d"=" -f2`				# LDAP external server active (on/off)
615 richard 39
LDAP=${LDAP:=off}
783 richard 40
LDAP_IP=`grep LDAP_IP= $conf_file|cut -d"=" -f2`			# WAN IP address to reduce LDAP WAN access (all ip allowed on LAN side)
768 richard 41
LDAP_IP=${LDAP_IP:="0.0.0.0/0.0.0.0"}
675 richard 42
EXTIF="eth0"
1 root 43
INTIF="eth1"
783 richard 44
TUNIF="tun0"								# listen device for chilli daemon
612 richard 45
IPTABLES="/sbin/iptables"
1 root 46
 
498 richard 47
# Effacement des règles existantes
476 richard 48
# Flush all existing rules
1 root 49
$IPTABLES -F
50
$IPTABLES -t nat -F
51
$IPTABLES -t mangle -F
52
$IPTABLES -F INPUT
53
$IPTABLES -F FORWARD
54
$IPTABLES -F OUTPUT
55
 
498 richard 56
# Suppression des chaines utilisateurs sur les tables filter et nat
57
# Flush non default rules on filter and nat tables
58
$IPTABLES -X
59
$IPTABLES -t nat -X
60
 
61
# Stratégies par défaut
476 richard 62
# Default policies
1 root 63
$IPTABLES -P INPUT DROP
64
$IPTABLES -P FORWARD DROP
498 richard 65
$IPTABLES -P OUTPUT DROP
1 root 66
$IPTABLES -t nat -P PREROUTING ACCEPT
67
$IPTABLES -t nat -P POSTROUTING ACCEPT
68
$IPTABLES -t nat -P OUTPUT ACCEPT
69
 
472 richard 70
#############################
783 richard 71
#       PREROUTING          #
472 richard 72
#############################
783 richard 73
# Marquage (et journalisation) des paquets qui tentent d'accéder directement à DansGuardian pour pouvoir les rejeter en INPUT
74
# mark (and log) the dansguardian bypass attempts in order to DROP them in INPUT rules
75
# $IPTABLES -A PREROUTING -t nat -i $TUNIF -p tcp -d $PRIVATE_IP -m tcp --dport 8080 -j ULOG --ulog-prefix "RULE direct-proxy -- DENY "
76
$IPTABLES -A PREROUTING -t mangle -i $TUNIF -d $PRIVATE_IP -p tcp -m tcp --dport 8080 -j MARK --set-mark 1
1 root 77
 
783 richard 78
# Marquage (et journalisation) des paquets qui tentent d'accéder directement au port udp 54 pour pouvoir les rejeter en INPUT
79
# Mark (and log) the udp 54 direct attempts to REJECT them in INPUT rules
80
# Remarque : Ce port n'est ouvert que lorsque le filtrage est activé
81
# Remark : this port is only open when filtering is on
82
# $IPTABLES -A PREROUTING -t nat -i $TUNIF -p udp -d $PRIVATE_IP -m udp --dport 54 -j ULOG --ulog-prefix "RULE DNS-proxy -- DENY "
83
$IPTABLES -A PREROUTING -t mangle -i $TUNIF -d $PRIVATE_IP -p tcp --dport 54 -j MARK --set-mark 2
84
 
85
# Si le filtrage est activé, redirection des flux DNS vers le port 54 (dns+blackhole) sauf pour les IP en exceptions 
86
# If DNS filter is on, redirect DNS request to udp 54 (dns+blackhole) except for exception IP addresses
87
if [ $DNS_FILTERING = on ]; then
88
	# Compute exception IP
89
	nb_exceptions=`wc -l /usr/local/etc/alcasar-filter-exceptions | cut -d" " -f1`
90
	if [ $nb_exceptions != "0" ]
91
	then
92
		while read ip_exception 
93
		do
94
			$IPTABLES -A PREROUTING -t nat -i $TUNIF -p udp -s $ip_exception -d $PRIVATE_IP --dport domain -j ACCEPT
95
		done < /usr/local/etc/alcasar-filter-exceptions
96
	fi
97
		$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport domain -j REDIRECT --to-port 54
98
fi
99
 
100
# Journalisation des requètes HTTP vers Internet (seulement les paquets SYN) - Les autres protocoles sont journalisés en FORWARD
101
# Log HTTP requests to Internet (only syn packets) - Other protocols are log in FORWARD
102
$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK ! -d $PRIVATE_IP -p tcp --dport http -m state --state NEW -j ULOG --ulog-prefix "RULE F_http -- ACCEPT "
103
# Redirection des requêtes HTTP vers DansGuardian (proxy transparent)
104
# Redirect HTTP requests in DansGuardian (transparent proxy)
105
$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK ! -d $PRIVATE_IP -p tcp --dport http -j REDIRECT --to-port 8080
106
 
107
# Redirection des requêtes NTP vers le serveur NTP local
108
# Redirect NTP request in local NTP server
109
$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK ! -d $PRIVATE_IP -p udp --dport ntp -j REDIRECT --to-port 123
110
 
472 richard 111
#############################
783 richard 112
#         INPUT             #
472 richard 113
#############################
871 richard 114
 
783 richard 115
# Tout passe sur loopback
116
# accept all on loopback
117
$IPTABLES -A INPUT -i lo -j ACCEPT
990 franck 118
$IPTABLES -A OUTPUT -o lo -j ACCEPT
783 richard 119
 
120
# Rejet des demandes de connexions non conformes (FIN-URG-PUSH, XMAS, NullScan, SYN-RST et NEW not SYN)
121
# Drop non standard connexions (FIN-URG-PUSH, XMAS, NullScan, SYN-RST et NEW not SYN)
472 richard 122
$IPTABLES -A INPUT -p tcp --tcp-flags FIN,URG,PSH FIN,URG,PSH -j DROP
123
$IPTABLES -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
124
$IPTABLES -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
125
$IPTABLES -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
675 richard 126
$IPTABLES -A INPUT -p tcp -m tcp ! --syn -m state --state NEW -j DROP
498 richard 127
 
871 richard 128
# On rejette les trame en broadcast et en multicast sur EXTIF (évite leur journalisation)
129
# Drop broadcast & multicast on EXTIF to avoid log 
783 richard 130
$IPTABLES -A INPUT -i $EXTIF -m addrtype --dst-type BROADCAST,MULTICAST -j DROP
498 richard 131
 
783 richard 132
# On autorise les retours de connexions légitimes par INPUT
133
# Conntrack on INPUT
134
$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
373 richard 135
 
783 richard 136
# On interdit les connexions directes au port utilisé par DansGuardian (8080). Les packets concernés ont été marqués dans la table mangle (PREROUTING)
137
# Deny direct connections on DansGuardian port (8080). The concerned paquets are marked in mangle table (PREROUTING)
138
$IPTABLES -A INPUT -i $TUNIF -p tcp --dport 8080 -m mark --mark 1 -j REJECT --reject-with tcp-reset
791 richard 139
 
859 richard 140
# Insertion des règles de blocage IP
141
# Here, we add IP block rules 
142
if [ -s /usr/local/etc/alcasar-ip-blocked ]; then 
143
	while read ip_line
144
	do
145
		ip_on=`echo $ip_line|cut -b1`
146
		if [ $ip_on != "#" ]
147
		then	
148
			ip_blocked=`echo $ip_line|cut -d" " -f1`
149
			$IPTABLES -A INPUT -i $TUNIF -d $ip_blocked -p tcp --dport 8080 -m state --state NEW --syn -j ULOG --ulog-prefix "RULE IP-blocked -- REJECT "
150
			$IPTABLES -A INPUT -i $TUNIF -d $ip_blocked -p tcp --dport 8080 -m state --state NEW --syn -j REJECT 
151
		fi
152
	done < /usr/local/etc/alcasar-ip-blocked
153
fi
783 richard 154
# Autorisation des connexions légitimes à DansGuardian 
155
# Allow connections for DansGuardian
156
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport 8080 -m state --state NEW --syn -j ACCEPT
373 richard 157
 
783 richard 158
# On interdit les connexions directes au port UDP 54. Les packets concernés ont été marqués dans la table mangle (PREROUTING)
159
# Deny direct connections on UDP 54. The concerned paquets are marked in mangle table (PREROUTING)
160
$IPTABLES -A INPUT -i $TUNIF -p udp --dport 54 -m mark --mark 2 -j REJECT --reject-with icmp-port-unreachable
791 richard 161
 
783 richard 162
# autorisation des connexion légitime à DNSMASQ (avec blackhole)
163
# Allow connections for DNSMASQ (with blackhole)
164
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport 54 -j ACCEPT
165
 
166
# Accès direct aux services internes
167
# Internal services access
786 richard 168
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport domain -j ACCEPT	# DNS non filtré # DNS without blackhole
169
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p icmp --icmp-type 8 -j ACCEPT	# Réponse ping # ping responce
170
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p icmp --icmp-type 0 -j ACCEPT	# Requête  ping # ping request
171
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport https -j ACCEPT	# Pages d'authentification et MCC # authentication pages and MCC
172
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport http -j ACCEPT	# Page d'avertissement filtrage # Filtering warning pages
173
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport 3990 -j ACCEPT	# Requêtes de deconnexion usagers # Users logout requests
174
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport ntp -j ACCEPT	# Serveur local de temps # local time server
783 richard 175
 
176
# SSHD rules if activate 
177
if [ $SSH = on ]
520 richard 178
	then
783 richard 179
	$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport ssh -m state --state NEW -j ULOG --ulog-nlgroup 2 --ulog-prefix "RULE ssh-from-LAN -- ACCEPT"
180
	$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport ssh -j ACCEPT
1063 richard 181
	$IPTABLES -A INPUT -i $EXTIF -s $SSH_ADMIN_FROM -d $PUBLIC_IP -p tcp --dport ssh -m state --state NEW --syn -j ULOG --ulog-nlgroup 2 --ulog-prefix "RULE ssh-from-WAN -- ACCEPT"
182
	$IPTABLES -A INPUT -i $EXTIF -s $SSH_ADMIN_FROM -d $PUBLIC_IP -p tcp --dport ssh -m state --state NEW,ESTABLISHED -j ACCEPT
520 richard 183
fi
783 richard 184
 
185
# Insertion de règles locales
186
# Here, we add local rules (i.e. VPN from Internet)
187
if [ -f /usr/local/etc/alcasar-iptables-local.sh ]; then
188
        . /usr/local/etc/alcasar-iptables-local.sh
189
fi
190
 
191
# Journalisation et rejet des connexions (autres que celles autorisées) effectuées depuis le LAN
192
# Deny and log on INPUT from the LAN
193
$IPTABLES -A INPUT -i $TUNIF -m state --state NEW -j ULOG --ulog-prefix "RULE rej-int -- REJECT "
194
$IPTABLES -A INPUT -i $TUNIF -p tcp -j REJECT --reject-with tcp-reset
195
$IPTABLES -A INPUT -i $TUNIF -p udp -j REJECT --reject-with icmp-port-unreachable
196
 
197
# interdiction d'accès à INTIF (n'est utile que lorsque chilli est arrêté).
198
# Reject INTIF access (only when chilli is down)
199
$IPTABLES -A INPUT -i $INTIF -j ULOG --ulog-prefix "RULE Protect1 -- REJECT "
200
$IPTABLES -A INPUT -i $INTIF -j REJECT
201
 
202
# Journalisation et rejet des connexions initiées depuis le réseau extérieur (test des effets du paramètre --limit en cours)
203
# On EXTIF, the access attempts are log in channel 2 (we should test --limit option to avoid deny of service)
204
$IPTABLES -A INPUT -i $EXTIF -m state --state NEW -j ULOG --ulog-nlgroup 3 --ulog-qthreshold 10 --ulog-prefix "RULE rej-ext -- DROP"
205
 
871 richard 206
 
783 richard 207
#############################
208
#        FORWARD            #
209
#############################
210
 
211
# Rejet des requêtes DNS vers Internet
212
# Deny forward DNS
213
$IPTABLES -A FORWARD -i $TUNIF -p udp --dport domain -j REJECT --reject-with icmp-port-unreachable
214
$IPTABLES -A FORWARD -i $TUNIF -p tcp --dport domain -j REJECT --reject-with tcp-reset
215
 
859 richard 216
# Insertion des règles de blocage IP
217
# Here, we add IP block rules 
218
if [ -s /usr/local/etc/alcasar-ip-blocked ]; then 
219
	while read ip_line
220
	do
221
		ip_on=`echo $ip_line|cut -b1`
222
		if [ $ip_on != "#" ]
223
		then	
224
			ip_blocked=`echo $ip_line|cut -d" " -f1`
225
			$IPTABLES -A FORWARD -i $TUNIF -d $ip_blocked -j ULOG --ulog-prefix "RULE IP-blocked -- REJECT "
226
			$IPTABLES -A FORWARD -i $TUNIF -d $ip_blocked -p udp -j REJECT --reject-with icmp-port-unreachable
227
			$IPTABLES -A FORWARD -i $TUNIF -d $ip_blocked -p icmp -j REJECT --reject-with icmp-port-unreachable
228
			$IPTABLES -A FORWARD -i $TUNIF -d $ip_blocked -p tcp -j REJECT --reject-with tcp-reset
229
		fi
230
	done < /usr/local/etc/alcasar-ip-blocked
790 richard 231
fi
859 richard 232
 
815 richard 233
# Autorisation des retours de connexions légitimes
234
# Allow conntrack
235
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
790 richard 236
 
783 richard 237
#  If protocols filter is activate 
612 richard 238
if [ $PROTOCOLS_FILTERING = on ]; then
688 richard 239
	# Compute exception IP (IP addresses that shouldn't be filtered)
240
	nb_exceptions=`wc -l /usr/local/etc/alcasar-filter-exceptions | cut -d" " -f1`
373 richard 241
	if [ $nb_exceptions != "0" ]
242
	then
243
		while read ip_exception 
244
		do
245
			$IPTABLES -A FORWARD -i $TUNIF -s $ip_exception -m state --state NEW -j ULOG --ulog-prefix "RULE IP-exception -- ACCEPT "
246
			$IPTABLES -A FORWARD -i $TUNIF -s $ip_exception -m state --state NEW -j ACCEPT
247
		done < /usr/local/etc/alcasar-filter-exceptions
248
	fi
871 richard 249
	# Compute uamallowed IP (IP address of equipments connected between ALCASAR and Internet (DMZ, own servers, ...) 
250
	nb_uamallowed=`wc -l /usr/local/etc/alcasar-uamallowed | cut -d" "  -f1`
251
	if [ $nb_uamallowed != "0" ]
688 richard 252
	then
253
		while read ip_allowed_line 
254
		do
255
			ip_allowed=`echo $ip_allowed_line|cut -d"\"" -f2`
256
			$IPTABLES -A FORWARD -i $TUNIF -d $ip_allowed -m state --state NEW -j ULOG --ulog-prefix "RULE IP-allowed -- ACCEPT "
257
			$IPTABLES -A FORWARD -i $TUNIF -d $ip_allowed -m state --state NEW -j ACCEPT
258
		done < /usr/local/etc/alcasar-uamallowed
259
	fi
520 richard 260
	# Autorisation des protocoles non commentés
476 richard 261
	# Allow non comment protocols
373 richard 262
	while read svc_line
263
	do
264
		svc_on=`echo $svc_line|cut -b1`
265
		if [ $svc_on != "#" ]
266
		then	
267
			svc_name=`echo $svc_line|cut -d" " -f1`
268
			svc_port=`echo $svc_line|cut -d" " -f2`
269
			if [ $svc_name = "icmp" ]
270
			then
859 richard 271
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p icmp -j ACCEPT 
373 richard 272
			else
859 richard 273
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport $svc_port -m state --state NEW -j ULOG --ulog-prefix "RULE F_TCP-$svc_name -- ACCEPT "
274
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport $svc_port -m state --state NEW -j ACCEPT
275
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p udp --dport $svc_port -m state --state NEW -j ULOG --ulog-prefix "RULE F_UDP-$svc_name -- ACCEPT "
276
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p udp --dport $svc_port -m state --state NEW -j ACCEPT
373 richard 277
			fi
278
		fi
279
	done < /usr/local/etc/alcasar-services
783 richard 280
	# Rejet explicite des autres protocoles
281
	# reject the others protocols
282
	$IPTABLES -A FORWARD -i $TUNIF -j ULOG --ulog-prefix "RULE F_filter -- REJECT "
373 richard 283
	$IPTABLES -A FORWARD -i $TUNIF -p tcp -j REJECT --reject-with tcp-reset
284
	$IPTABLES -A FORWARD -i $TUNIF -p udp -j REJECT --reject-with icmp-port-unreachable
285
	$IPTABLES -A FORWARD -i $TUNIF -p icmp -j REJECT 
1 root 286
fi
492 franck 287
 
288
#  If QOS is activate  #
612 richard 289
if [ $QOS = on ] && [ -e /usr/local/etc/alcasar-iptables-qos.sh ]; then
492 franck 290
	. /usr/local/etc/alcasar-iptables-qos.sh 	
291
fi
292
 
498 richard 293
# Autorisation des connections sortant du LAN  
476 richard 294
# Allow forward connections with log
859 richard 295
$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -m state --state NEW -j ULOG --ulog-prefix "RULE F_all -- ACCEPT "
296
$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -m state --state NEW -j ACCEPT
1 root 297
 
783 richard 298
#############################
299
#         OUTPUT            #
300
#############################
604 richard 301
# SSHD rules if activate 
612 richard 302
if [ $SSH = on ]
604 richard 303
	then
304
	$IPTABLES -A OUTPUT -o $EXTIF -p tcp --sport ssh -m state --state ESTABLISHED -j ACCEPT
305
fi
498 richard 306
# On laisse tout sortir sur toutes les cartes sauf celle qui est connectée sur l'extérieur
307
# Everything is allowed but traffic through outside network interface
308
$IPTABLES -A OUTPUT ! -o $EXTIF -j ACCEPT
520 richard 309
 
503 richard 310
# On autorise les requêtes DNS vers les serveurs DNS identifiés 
498 richard 311
# Allow DNS requests to identified DNS servers
312
$IPTABLES -A OUTPUT -o $EXTIF -d $DNSSERVERS -p udp --dport domain -m state --state NEW -j ACCEPT
783 richard 313
 
615 richard 314
# On autorise les requêtes HTTP sortantes
498 richard 315
# HTTP requests are allowed
316
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport http -j ACCEPT
783 richard 317
 
784 richard 318
# On autorise les requêtes FTP 
319
# FTP requests are allowed
320
modprobe ip_conntrack_ftp
321
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport ftp -j ACCEPT
322
$IPTABLES -A OUTPUT -o $EXTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
323
 
615 richard 324
# On autorise les requêtes NTP 
498 richard 325
# NTP requests are allowed
326
$IPTABLES -A OUTPUT -o $EXTIF -p udp --dport ntp -j ACCEPT
783 richard 327
 
503 richard 328
# On autorise les requêtes ICMP (ping) 
329
# ICMP (ping) requests are allowed
330
$IPTABLES -A OUTPUT -o $EXTIF -p icmp --icmp-type 8 -j ACCEPT
783 richard 331
 
615 richard 332
# On autorise les requêtes LDAP si un serveur externe est configué
333
# LDAP requests are allowed if an external server is declared
334
if [ $LDAP = on ]
335
	then
694 franck 336
	$IPTABLES -A OUTPUT -p tcp -d $LDAP_IP -m multiport --dports ldap,ldaps -m state --state NEW,ESTABLISHED -j ACCEPT
337
	$IPTABLES -A OUTPUT -p udp -d $LDAP_IP -m multiport --dports ldap,ldaps -m state --state NEW,ESTABLISHED -j ACCEPT
338
#	$IPTABLES -A INPUT  -p tcp -s $LDAP_IP -m multiports --sports ldap,ldaps -m state --state ESTABLISHED -j ACCEPT
339
#	$IPTABLES -A INPUT  -p udp -s $LDAP_IP -m multiports --sports ldap,ldaps -m state --state ESTABLISHED -j ACCEPT
615 richard 340
fi
783 richard 341
 
342
 
343
#############################
344
#       POSTROUTING         #
345
#############################
498 richard 346
# Traduction dynamique d'adresse en sortie
476 richard 347
# Dynamic NAT on EXTIF
1 root 348
$IPTABLES -A POSTROUTING -t nat -o $EXTIF -j MASQUERADE
349
 
476 richard 350
# Save all rules
1 root 351
/etc/init.d/iptables save
352
 
476 richard 353
# End of script
1 root 354