Subversion Repositories ALCASAR

Rev

Rev 1332 | Rev 1364 | 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 1339 2014-05-05 12:55:57Z richard $
675 richard 3
# Script de mise en place des regles du parefeu d'Alcasar (mode normal)
1339 richard 4
# This script writes the netfilter rules for ALCASAR
675 richard 5
# Rexy - 3abtux - CPN
6
#
7
# Reminders
1221 richard 8
# There are four channels for log :
1294 richard 9
#	1 tracability of the consultation equipment with The 'Netflow' kernel module (iptables target = NETFLOW);
1221 richard 10
#	2 protection of ALCASAR with the Ulog group 1 (default group) 
1294 richard 11
#	3 SSH on ALCASAR with the Ulog group 2;
12
#	4 extern access attempts on ALCASAR with the Ulog group 3.
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}
1332 richard 32
BL_IP_CAT="/usr/local/share/iptables-bl-enabled"			# categories files of the BlackListed IP
1339 richard 33
BL_IP_OSSI="/usr/local/share/iptables-bl/ossi"				# ossi categoty
783 richard 34
QOS=`grep QOS= $conf_file|cut -d"=" -f2`				# QOS (on/off)
615 richard 35
QOS=${QOS:=off}
783 richard 36
SSH=`grep SSH= $conf_file|cut -d"=" -f2`				# sshd active (on/off)
615 richard 37
SSH=${SSH:=off}
1063 richard 38
SSH_ADMIN_FROM=`grep SSH_ADMIN_FROM= $conf_file|cut -d"=" -f2`
39
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 40
LDAP=`grep LDAP= $conf_file|cut -d"=" -f2`				# LDAP external server active (on/off)
615 richard 41
LDAP=${LDAP:=off}
783 richard 42
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 43
LDAP_IP=${LDAP_IP:="0.0.0.0/0.0.0.0"}
675 richard 44
EXTIF="eth0"
1 root 45
INTIF="eth1"
783 richard 46
TUNIF="tun0"								# listen device for chilli daemon
612 richard 47
IPTABLES="/sbin/iptables"
1339 richard 48
IP_REHABILITEES="/etc/dansguardian/lists/exceptioniplist"		# Rehabilitated IP
1 root 49
 
1291 richard 50
# loading of NetFlow probe (ipt_NETFLOW kernel module)
1159 crox53 51
modprobe ipt_NETFLOW destination=127.0.0.1:2055
52
 
498 richard 53
# Effacement des règles existantes
476 richard 54
# Flush all existing rules
1 root 55
$IPTABLES -F
56
$IPTABLES -t nat -F
57
$IPTABLES -t mangle -F
58
$IPTABLES -F INPUT
59
$IPTABLES -F FORWARD
60
$IPTABLES -F OUTPUT
61
 
498 richard 62
# Suppression des chaines utilisateurs sur les tables filter et nat
63
# Flush non default rules on filter and nat tables
64
$IPTABLES -X
65
$IPTABLES -t nat -X
66
 
67
# Stratégies par défaut
476 richard 68
# Default policies
1 root 69
$IPTABLES -P INPUT DROP
70
$IPTABLES -P FORWARD DROP
498 richard 71
$IPTABLES -P OUTPUT DROP
1 root 72
$IPTABLES -t nat -P PREROUTING ACCEPT
73
$IPTABLES -t nat -P POSTROUTING ACCEPT
74
$IPTABLES -t nat -P OUTPUT ACCEPT
75
 
1291 richard 76
# destruction de tous les SET
1332 richard 77
# destroy all SET
1291 richard 78
ipset destroy
79
 
1294 richard 80
# Création et initialisation du SET authenticated_ip (dynamiquement peuplé par les scripts conup/condown)
81
# creation and initialization of authenticated_ip_ SET (populated dynamicly by conup/condown scripts)
82
ipset create authenticated_ip hash:net hashsize 1024
83
OLDIFS=$IFS
84
IFS=$'\n'
85
for equipment in `/usr/sbin/chilli_query list |grep -v "\.0\.0\.0"`
86
do
87
	active_ip=`echo $equipment |cut -d" " -f2`
88
	active_session=`echo $equipment |cut -d" " -f5`
89
	if [[ $(expr $active_session) -eq 1 ]]
90
	then
91
		ipset add authenticated_ip $active_ip
92
	fi
93
done
94
IFS=$OLDIFS
95
 
1339 richard 96
# Calcul de la taille de l'ipset
1332 richard 97
cd $BL_IP_CAT
1339 richard 98
ipset_length=$(($(wc -l * | awk '{print $1}' | tail -n 1)+$(wc -l $BL_IP_OSSI | awk '{print $1}')))
1294 richard 99
 
1339 richard 100
# Création du fichier set temporaire, remplissage, chargement et suppression
101
echo "create blacklist_ip_blocked hash:net family inet hashsize 1024 maxelem $ipset_length" > /tmp/ipset_save
1332 richard 102
for category in `ls -1 | cut -d '@' -f1`
103
do
1339 richard 104
	cat $BL_IP_CAT/$category >> /tmp/ipset_save
1332 richard 105
done
1339 richard 106
cat $BL_IP_OSSI >> /tmp/ipset_save
107
ipset -! restore < /tmp/ipset_save
108
rm -f /tmp/ipset_save
1332 richard 109
 
1339 richard 110
# Extraction des ip réhabilitées
111
for ip in $(cat $IP_REHABILITEES)
112
do
113
	ipset del blacklist_ip_blocked $ip
114
done
115
 
116
# Sauvegarde de tous les set (pour restaurer après redémarrage)
1332 richard 117
ipset save > /etc/sysconfig/ipset_save
118
 
472 richard 119
#############################
783 richard 120
#       PREROUTING          #
472 richard 121
#############################
783 richard 122
# Marquage (et journalisation) des paquets qui tentent d'accéder directement à DansGuardian pour pouvoir les rejeter en INPUT
123
# mark (and log) the dansguardian bypass attempts in order to DROP them in INPUT rules
1221 richard 124
$IPTABLES -A PREROUTING -t nat -i $TUNIF -p tcp -d $PRIVATE_IP -m tcp --dport 8080 -j ULOG --ulog-prefix "RULE direct-proxy -- DENY "
783 richard 125
$IPTABLES -A PREROUTING -t mangle -i $TUNIF -d $PRIVATE_IP -p tcp -m tcp --dport 8080 -j MARK --set-mark 1
1 root 126
 
783 richard 127
# Marquage (et journalisation) des paquets qui tentent d'accéder directement au port udp 54 pour pouvoir les rejeter en INPUT
128
# Mark (and log) the udp 54 direct attempts to REJECT them in INPUT rules
129
# Remarque : Ce port n'est ouvert que lorsque le filtrage est activé
130
# Remark : this port is only open when filtering is on
131
# $IPTABLES -A PREROUTING -t nat -i $TUNIF -p udp -d $PRIVATE_IP -m udp --dport 54 -j ULOG --ulog-prefix "RULE DNS-proxy -- DENY "
132
$IPTABLES -A PREROUTING -t mangle -i $TUNIF -d $PRIVATE_IP -p tcp --dport 54 -j MARK --set-mark 2
133
 
1072 richard 134
# Si le filtrage DNS est activé, redirection des flux DNS vers le port 54 (dns+blackhole) sauf pour les IP en exceptions 
783 richard 135
# If DNS filter is on, redirect DNS request to udp 54 (dns+blackhole) except for exception IP addresses
136
if [ $DNS_FILTERING = on ]; then
137
	# Compute exception IP
138
	nb_exceptions=`wc -l /usr/local/etc/alcasar-filter-exceptions | cut -d" " -f1`
139
	if [ $nb_exceptions != "0" ]
140
	then
141
		while read ip_exception 
142
		do
143
			$IPTABLES -A PREROUTING -t nat -i $TUNIF -p udp -s $ip_exception -d $PRIVATE_IP --dport domain -j ACCEPT
144
		done < /usr/local/etc/alcasar-filter-exceptions
145
	fi
146
		$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport domain -j REDIRECT --to-port 54
147
fi
148
 
1294 richard 149
# Redirection des requêtes HTTP des IP de la blacklist vers ALCASAR (page 'accès interdit')
150
# Redirect HTTP requests of blacklist ip to ALCASAR (access deny window)
1332 richard 151
if [ $DNS_FILTERING = on ]; then
152
$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK -m set --match-set blacklist_ip_blocked dst -p tcp --dport http -j REDIRECT --to-port 80
153
fi
1294 richard 154
 
1291 richard 155
# Journalisation des requètes HTTP vers Internet (seulement les paquets SYN) - Les autres protocoles sont journalisés en FORWARD par netflow
156
## Log HTTP requests to Internet (only syn packets) - Other protocols are log in FORWARD by netflow
1230 crox53 157
$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 "
1221 richard 158
 
1291 richard 159
# Redirection des requêtes HTTP sortantes vers DansGuardian (proxy transparent)
160
# Redirect outbound HTTP requests to DansGuardian (transparent proxy)
783 richard 161
$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK ! -d $PRIVATE_IP -p tcp --dport http -j REDIRECT --to-port 8080
162
 
163
# Redirection des requêtes NTP vers le serveur NTP local
164
# Redirect NTP request in local NTP server
165
$IPTABLES -A PREROUTING -t nat -i $TUNIF -s $PRIVATE_NETWORK_MASK ! -d $PRIVATE_IP -p udp --dport ntp -j REDIRECT --to-port 123
166
 
472 richard 167
#############################
783 richard 168
#         INPUT             #
472 richard 169
#############################
871 richard 170
 
783 richard 171
# Tout passe sur loopback
172
# accept all on loopback
173
$IPTABLES -A INPUT -i lo -j ACCEPT
990 franck 174
$IPTABLES -A OUTPUT -o lo -j ACCEPT
783 richard 175
 
176
# Rejet des demandes de connexions non conformes (FIN-URG-PUSH, XMAS, NullScan, SYN-RST et NEW not SYN)
177
# Drop non standard connexions (FIN-URG-PUSH, XMAS, NullScan, SYN-RST et NEW not SYN)
472 richard 178
$IPTABLES -A INPUT -p tcp --tcp-flags FIN,URG,PSH FIN,URG,PSH -j DROP
179
$IPTABLES -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
180
$IPTABLES -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
181
$IPTABLES -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
675 richard 182
$IPTABLES -A INPUT -p tcp -m tcp ! --syn -m state --state NEW -j DROP
498 richard 183
 
871 richard 184
# On rejette les trame en broadcast et en multicast sur EXTIF (évite leur journalisation)
185
# Drop broadcast & multicast on EXTIF to avoid log 
783 richard 186
$IPTABLES -A INPUT -i $EXTIF -m addrtype --dst-type BROADCAST,MULTICAST -j DROP
498 richard 187
 
783 richard 188
# On autorise les retours de connexions légitimes par INPUT
189
# Conntrack on INPUT
190
$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
373 richard 191
 
1221 richard 192
# On interdit les connexions directes au port utilisé par DansGuardian (8080). Les packets concernés ont été marqués et loggués dans la table mangle (PREROUTING)
193
# Deny direct connections on DansGuardian port (8080). The concerned paquets are marked and logged in mangle table (PREROUTING)
783 richard 194
$IPTABLES -A INPUT -i $TUNIF -p tcp --dport 8080 -m mark --mark 1 -j REJECT --reject-with tcp-reset
791 richard 195
 
783 richard 196
# Autorisation des connexions légitimes à DansGuardian 
197
# Allow connections for DansGuardian
198
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport 8080 -m state --state NEW --syn -j ACCEPT
373 richard 199
 
783 richard 200
# On interdit les connexions directes au port UDP 54. Les packets concernés ont été marqués dans la table mangle (PREROUTING)
201
# Deny direct connections on UDP 54. The concerned paquets are marked in mangle table (PREROUTING)
202
$IPTABLES -A INPUT -i $TUNIF -p udp --dport 54 -m mark --mark 2 -j REJECT --reject-with icmp-port-unreachable
791 richard 203
 
783 richard 204
# autorisation des connexion légitime à DNSMASQ (avec blackhole)
205
# Allow connections for DNSMASQ (with blackhole)
206
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport 54 -j ACCEPT
207
 
208
# Accès direct aux services internes
209
# Internal services access
786 richard 210
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport domain -j ACCEPT	# DNS non filtré # DNS without blackhole
211
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p icmp --icmp-type 8 -j ACCEPT	# Réponse ping # ping responce
212
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p icmp --icmp-type 0 -j ACCEPT	# Requête  ping # ping request
213
$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
214
$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
215
$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
216
$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 217
 
218
# SSHD rules if activate 
219
if [ $SSH = on ]
520 richard 220
	then
783 richard 221
	$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"
222
	$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport ssh -j ACCEPT
1063 richard 223
	$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"
1161 richard 224
	$IPTABLES -A INPUT -i $EXTIF -s $SSH_ADMIN_FROM -d $PUBLIC_IP -p tcp --dport ssh -m state --state NEW -j ACCEPT
520 richard 225
fi
783 richard 226
 
227
# Insertion de règles locales
228
# Here, we add local rules (i.e. VPN from Internet)
229
if [ -f /usr/local/etc/alcasar-iptables-local.sh ]; then
230
        . /usr/local/etc/alcasar-iptables-local.sh
231
fi
232
 
233
# Journalisation et rejet des connexions (autres que celles autorisées) effectuées depuis le LAN
234
# Deny and log on INPUT from the LAN
235
$IPTABLES -A INPUT -i $TUNIF -m state --state NEW -j ULOG --ulog-prefix "RULE rej-int -- REJECT "
236
$IPTABLES -A INPUT -i $TUNIF -p tcp -j REJECT --reject-with tcp-reset
237
$IPTABLES -A INPUT -i $TUNIF -p udp -j REJECT --reject-with icmp-port-unreachable
238
 
239
# interdiction d'accès à INTIF (n'est utile que lorsque chilli est arrêté).
240
# Reject INTIF access (only when chilli is down)
241
$IPTABLES -A INPUT -i $INTIF -j ULOG --ulog-prefix "RULE Protect1 -- REJECT "
242
$IPTABLES -A INPUT -i $INTIF -j REJECT
243
 
244
# Journalisation et rejet des connexions initiées depuis le réseau extérieur (test des effets du paramètre --limit en cours)
245
# On EXTIF, the access attempts are log in channel 2 (we should test --limit option to avoid deny of service)
246
$IPTABLES -A INPUT -i $EXTIF -m state --state NEW -j ULOG --ulog-nlgroup 3 --ulog-qthreshold 10 --ulog-prefix "RULE rej-ext -- DROP"
247
 
871 richard 248
 
783 richard 249
#############################
250
#        FORWARD            #
251
#############################
252
 
253
# Rejet des requêtes DNS vers Internet
254
# Deny forward DNS
255
$IPTABLES -A FORWARD -i $TUNIF -p udp --dport domain -j REJECT --reject-with icmp-port-unreachable
256
$IPTABLES -A FORWARD -i $TUNIF -p tcp --dport domain -j REJECT --reject-with tcp-reset
257
 
1332 richard 258
if [ $DNS_FILTERING = on ]; then
1339 richard 259
	# Blocage des IPs du SET blacklist_ip_blocked
260
	# Deny IPs of the SET blacklist_ip_blocked 
1332 richard 261
	$IPTABLES -A FORWARD -i $TUNIF -m set --match-set blacklist_ip_blocked -p icmp -j REJECT --reject-with icmp-port-unreachable
262
	$IPTABLES -A FORWARD -i $TUNIF -m set --match-set blacklist_ip_blocked dst -p udp -j REJECT --reject-with icmp-port-unreachable
263
	$IPTABLES -A FORWARD -i $TUNIF -m set --match-set blacklist_ip_blocked -p tcp -j REJECT --reject-with tcp-reset
264
fi
1072 richard 265
 
815 richard 266
# Autorisation des retours de connexions légitimes
267
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
790 richard 268
 
783 richard 269
#  If protocols filter is activate 
612 richard 270
if [ $PROTOCOLS_FILTERING = on ]; then
688 richard 271
	# Compute exception IP (IP addresses that shouldn't be filtered)
272
	nb_exceptions=`wc -l /usr/local/etc/alcasar-filter-exceptions | cut -d" " -f1`
373 richard 273
	if [ $nb_exceptions != "0" ]
274
	then
275
		while read ip_exception 
276
		do
1221 richard 277
#			$IPTABLES -A FORWARD -i $TUNIF -s $ip_exception -m state --state NEW -j ULOG --ulog-prefix "RULE IP-exception -- ACCEPT "
1159 crox53 278
			$IPTABLES -A FORWARD -i $TUNIF -s $ip_exception -m state --state NEW -j NETFLOW
373 richard 279
			$IPTABLES -A FORWARD -i $TUNIF -s $ip_exception -m state --state NEW -j ACCEPT
280
		done < /usr/local/etc/alcasar-filter-exceptions
281
	fi
871 richard 282
	# Compute uamallowed IP (IP address of equipments connected between ALCASAR and Internet (DMZ, own servers, ...) 
283
	nb_uamallowed=`wc -l /usr/local/etc/alcasar-uamallowed | cut -d" "  -f1`
284
	if [ $nb_uamallowed != "0" ]
688 richard 285
	then
286
		while read ip_allowed_line 
287
		do
288
			ip_allowed=`echo $ip_allowed_line|cut -d"\"" -f2`
1221 richard 289
#			$IPTABLES -A FORWARD -i $TUNIF -d $ip_allowed -m state --state NEW -j ULOG --ulog-prefix "RULE IP-allowed -- ACCEPT "
1159 crox53 290
			$IPTABLES -A FORWARD -i $TUNIF -d $ip_allowed -m state --state NEW -j NETFLOW
688 richard 291
			$IPTABLES -A FORWARD -i $TUNIF -d $ip_allowed -m state --state NEW -j ACCEPT
292
		done < /usr/local/etc/alcasar-uamallowed
293
	fi
520 richard 294
	# Autorisation des protocoles non commentés
476 richard 295
	# Allow non comment protocols
373 richard 296
	while read svc_line
297
	do
298
		svc_on=`echo $svc_line|cut -b1`
299
		if [ $svc_on != "#" ]
300
		then	
301
			svc_name=`echo $svc_line|cut -d" " -f1`
302
			svc_port=`echo $svc_line|cut -d" " -f2`
303
			if [ $svc_name = "icmp" ]
304
			then
1159 crox53 305
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p icmp -j NETFLOW
859 richard 306
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p icmp -j ACCEPT 
373 richard 307
			else
1159 crox53 308
 
1221 richard 309
#				$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 "
1159 crox53 310
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport $svc_port -m state --state NEW -j NETFLOW
859 richard 311
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport $svc_port -m state --state NEW -j ACCEPT
1221 richard 312
#				$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 "
1159 crox53 313
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p udp --dport $svc_port -m state --state NEW -j NETFLOW
859 richard 314
				$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -p udp --dport $svc_port -m state --state NEW -j ACCEPT
373 richard 315
			fi
316
		fi
317
	done < /usr/local/etc/alcasar-services
783 richard 318
	# Rejet explicite des autres protocoles
319
	# reject the others protocols
1221 richard 320
#	$IPTABLES -A FORWARD -i $TUNIF -j ULOG --ulog-prefix "RULE F_filter -- REJECT "
373 richard 321
	$IPTABLES -A FORWARD -i $TUNIF -p tcp -j REJECT --reject-with tcp-reset
322
	$IPTABLES -A FORWARD -i $TUNIF -p udp -j REJECT --reject-with icmp-port-unreachable
323
	$IPTABLES -A FORWARD -i $TUNIF -p icmp -j REJECT 
1 root 324
fi
492 franck 325
 
326
#  If QOS is activate  #
612 richard 327
if [ $QOS = on ] && [ -e /usr/local/etc/alcasar-iptables-qos.sh ]; then
492 franck 328
	. /usr/local/etc/alcasar-iptables-qos.sh 	
329
fi
330
 
498 richard 331
# Autorisation des connections sortant du LAN  
476 richard 332
# Allow forward connections with log
1221 richard 333
#$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -m state --state NEW -j ULOG --ulog-prefix "RULE F_all -- ACCEPT "
1159 crox53 334
$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -m state --state NEW -j NETFLOW
859 richard 335
$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -m state --state NEW -j ACCEPT
1 root 336
 
783 richard 337
#############################
338
#         OUTPUT            #
339
#############################
1159 crox53 340
# On laisse tout sortir sur toutes les cartes sauf celle qui est connectée sur l'extérieur
341
# Everything is allowed but traffic through outside network interface
498 richard 342
$IPTABLES -A OUTPUT ! -o $EXTIF -j ACCEPT
520 richard 343
 
503 richard 344
# On autorise les requêtes DNS vers les serveurs DNS identifiés 
498 richard 345
# Allow DNS requests to identified DNS servers
346
$IPTABLES -A OUTPUT -o $EXTIF -d $DNSSERVERS -p udp --dport domain -m state --state NEW -j ACCEPT
783 richard 347
 
615 richard 348
# On autorise les requêtes HTTP sortantes
498 richard 349
# HTTP requests are allowed
1159 crox53 350
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport http -j NETFLOW
498 richard 351
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport http -j ACCEPT
783 richard 352
 
784 richard 353
# On autorise les requêtes FTP 
354
# FTP requests are allowed
355
modprobe ip_conntrack_ftp
356
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport ftp -j ACCEPT
1159 crox53 357
$IPTABLES -A OUTPUT -o $EXTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
784 richard 358
 
615 richard 359
# On autorise les requêtes NTP 
498 richard 360
# NTP requests are allowed
361
$IPTABLES -A OUTPUT -o $EXTIF -p udp --dport ntp -j ACCEPT
783 richard 362
 
503 richard 363
# On autorise les requêtes ICMP (ping) 
364
# ICMP (ping) requests are allowed
365
$IPTABLES -A OUTPUT -o $EXTIF -p icmp --icmp-type 8 -j ACCEPT
783 richard 366
 
615 richard 367
# On autorise les requêtes LDAP si un serveur externe est configué
368
# LDAP requests are allowed if an external server is declared
369
if [ $LDAP = on ]
370
	then
694 franck 371
	$IPTABLES -A OUTPUT -p tcp -d $LDAP_IP -m multiport --dports ldap,ldaps -m state --state NEW,ESTABLISHED -j ACCEPT
372
	$IPTABLES -A OUTPUT -p udp -d $LDAP_IP -m multiport --dports ldap,ldaps -m state --state NEW,ESTABLISHED -j ACCEPT
615 richard 373
fi
783 richard 374
 
1159 crox53 375
 
783 richard 376
#############################
377
#       POSTROUTING         #
378
#############################
498 richard 379
# Traduction dynamique d'adresse en sortie
476 richard 380
# Dynamic NAT on EXTIF
1 root 381
$IPTABLES -A POSTROUTING -t nat -o $EXTIF -j MASQUERADE
382
 
476 richard 383
# Save all rules
1 root 384
/etc/init.d/iptables save
385
 
476 richard 386
# End of script
1 root 387