Subversion Repositories ALCASAR

Rev

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