Subversion Repositories ALCASAR

Rev

Rev 2386 | Rev 2465 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2386 Rev 2454
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-iptables.sh 2386 2017-08-22 16:38:58Z tom.houdayer $
2
# $Id: alcasar-iptables.sh 2454 2017-12-09 18:59:31Z tom.houdayer $
3
# Script de mise en place des regles du parefeu d'Alcasar (mode normal)
3
# Script de mise en place des regles du parefeu d'Alcasar (mode normal)
4
# This script writes the netfilter rules for ALCASAR
4
# This script writes the netfilter rules for ALCASAR
5
# Rexy - 3abtux - CPN
5
# Rexy - 3abtux - CPN
6
#
6
#
7
# Reminders
7
# Reminders
8
# There are four channels for log :
8
# There are four channels for log :
9
#	1 tracability of the consultation equipment with The 'Netflow' kernel module (iptables target = NETFLOW);
9
#	1 tracability of the consultation equipment with The 'Netflow' kernel module (iptables target = NETFLOW);
10
#	2 protection of ALCASAR with the Ulog group 1 (default group) 
10
#	2 protection of ALCASAR with the Ulog group 1 (default group)
11
#	3 SSH on ALCASAR with the Ulog group 2;
11
#	3 SSH on ALCASAR with the Ulog group 2;
12
#	4 extern access attempts on ALCASAR with the Ulog group 3.
12
#	4 extern access attempts on ALCASAR with the Ulog group 3.
13
# The bootps/dhcp (67) port is always open on tun0/INTIF by coova 
13
# The bootps/dhcp (67) port is always open on tun0/INTIF by coova
14
CONF_FILE="/usr/local/etc/alcasar.conf"
14
CONF_FILE="/usr/local/etc/alcasar.conf"
15
EXTIF=`grep ^EXTIF= $CONF_FILE|cut -d"=" -f2`				# EXTernal InterFace
15
EXTIF=`grep ^EXTIF= $CONF_FILE|cut -d"=" -f2`				# EXTernal InterFace
16
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2`				# INTernal InterFace
16
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2`				# INTernal InterFace
17
TUNIF="tun0"								# listen device for chilli daemon
17
TUNIF="tun0"								# listen device for chilli daemon
18
private_ip_mask=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
18
private_ip_mask=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
Line 33... Line 33...
33
dns1=${dns1:=208.67.220.220}
33
dns1=${dns1:=208.67.220.220}
34
dns2=${dns2:=208.67.222.222}
34
dns2=${dns2:=208.67.222.222}
35
DNSSERVERS="$dns1,$dns2"						# first and second public DNS servers
35
DNSSERVERS="$dns1,$dns2"						# first and second public DNS servers
36
BL_IP_CAT="/usr/local/share/iptables-bl-enabled"			# categories files of the BlackListed IP
36
BL_IP_CAT="/usr/local/share/iptables-bl-enabled"			# categories files of the BlackListed IP
37
WL_IP_CAT="/usr/local/share/iptables-wl-enabled"			# categories files of the WhiteListed IP
37
WL_IP_CAT="/usr/local/share/iptables-wl-enabled"			# categories files of the WhiteListed IP
38
TMP_users_set_save="/tmp/users_set_save"				# tmp file for backup users set 
38
TMP_users_set_save="/tmp/users_set_save"				# tmp file for backup users set
39
TMP_set_save="/tmp/ipset_save"						# tmp file for blacklist and whitelist creation
39
TMP_set_save="/tmp/ipset_save"						# tmp file for blacklist and whitelist creation
40
SSH=`grep ^SSH= $CONF_FILE|cut -d"=" -f2`				# sshd active (on/off)
40
SSH=`grep ^SSH= $CONF_FILE|cut -d"=" -f2`				# sshd active (on/off)
41
SSH=${SSH:=off}
41
SSH=${SSH:=off}
42
SSH_ADMIN_FROM=`grep ^SSH_ADMIN_FROM= $CONF_FILE|cut -d"=" -f2`
42
SSH_ADMIN_FROM=`grep ^SSH_ADMIN_FROM= $CONF_FILE|cut -d"=" -f2`
43
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)
43
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)
Line 127... Line 127...
127
	cat $WL_IP_CAT/$category >> $TMP_set_save
127
	cat $WL_IP_CAT/$category >> $TMP_set_save
128
done
128
done
129
ipset -! restore < $TMP_set_save
129
ipset -! restore < $TMP_set_save
130
rm -f $TMP_set_save
130
rm -f $TMP_set_save
131
 
131
 
132
# Restoration des SET des utilisateurs connectés si ils existent sinon création des SET 
132
# Restoration des SET des utilisateurs connectés si ils existent sinon création des SET
133
# Restoring the connected users SETs if available, otherwise creating SETs
133
# Restoring the connected users SETs if available, otherwise creating SETs
134
if [ -e $TMP_users_set_save ];
134
if [ -e $TMP_users_set_save ];
135
then
135
then
136
	ipset -! restore < $TMP_users_set_save
136
	ipset -! restore < $TMP_users_set_save
137
	rm -f $TMP_users_set_save
137
	rm -f $TMP_users_set_save
Line 186... Line 186...
186
 
186
 
187
# redirection DNS des usagers 'havp_wl' vers le port 55
187
# redirection DNS des usagers 'havp_wl' vers le port 55
188
# redirect DNS of 'havp_wl' users to port 55
188
# redirect DNS of 'havp_wl' users to port 55
189
$IPTABLES -A PREROUTING -t nat -i $TUNIF -m set --match-set havp_wl src -d $PRIVATE_IP -p udp --dport domain -j REDIRECT --to-port 55
189
$IPTABLES -A PREROUTING -t nat -i $TUNIF -m set --match-set havp_wl src -d $PRIVATE_IP -p udp --dport domain -j REDIRECT --to-port 55
190
 
190
 
191
# Journalisation HTTP_Internet des usagers 'havp_bl' (paquets SYN uniquement). Les autres protocoles sont journalisés en FORWARD par netflow. 
191
# Journalisation HTTP_Internet des usagers 'havp_bl' (paquets SYN uniquement). Les autres protocoles sont journalisés en FORWARD par netflow.
192
# Log Internet HTTP of 'havp_bl' users" (only syn packets). Other protocols are logged in FORWARD by netflow
192
# Log Internet HTTP of 'havp_bl' users" (only syn packets). Other protocols are logged in FORWARD by netflow
193
$IPTABLES -A PREROUTING -t nat -i $TUNIF -m set --match-set havp_bl src ! -d $PRIVATE_IP -p tcp --dport http -m state --state NEW -j NFLOG --nflog-group 1 --nflog-prefix "RULE F_http -- ACCEPT "
193
$IPTABLES -A PREROUTING -t nat -i $TUNIF -m set --match-set havp_bl src ! -d $PRIVATE_IP -p tcp --dport http -m state --state NEW -j NFLOG --nflog-group 1 --nflog-prefix "RULE F_http -- ACCEPT "
194
 
194
 
195
# Redirection HTTP des usagers 'havp_bl' cherchant à joindre les IP de la blacklist vers ALCASAR (page 'accès interdit')
195
# Redirection HTTP des usagers 'havp_bl' cherchant à joindre les IP de la blacklist vers ALCASAR (page 'accès interdit')
196
# Redirect HTTP of 'havp_bl' users who want blacklist IP to ALCASAR ('access denied' page)
196
# Redirect HTTP of 'havp_bl' users who want blacklist IP to ALCASAR ('access denied' page)
Line 228... Line 228...
228
$IPTABLES -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
228
$IPTABLES -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
229
$IPTABLES -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
229
$IPTABLES -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
230
$IPTABLES -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
230
$IPTABLES -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
231
$IPTABLES -A INPUT -p tcp -m tcp ! --syn -m state --state NEW -j DROP
231
$IPTABLES -A INPUT -p tcp -m tcp ! --syn -m state --state NEW -j DROP
232
 
232
 
233
# Si configéré, on autorise les réponses DHCP 
233
# Si configéré, on autorise les réponses DHCP
234
# Allow DHCP answers if configured
234
# Allow DHCP answers if configured
235
public_ip_mask=`grep ^PUBLIC_IP= $CONF_FILE|cut -d"=" -f2`		# ALCASAR WAN IP address
235
public_ip_mask=`grep ^PUBLIC_IP= $CONF_FILE|cut -d"=" -f2`		# ALCASAR WAN IP address
236
if [[ "$public_ip_mask" == "dhcp" ]]
236
if [[ "$public_ip_mask" == "dhcp" ]]
237
then
237
then
238
	$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport 68 -j ACCEPT
238
	$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport 68 -j ACCEPT
239
	$IPTABLES -A OUTPUT -o $EXTIF -p udp --dport 68 -j ACCEPT
239
	$IPTABLES -A OUTPUT -o $EXTIF -p udp --dport 68 -j ACCEPT
240
fi
240
fi
241
# On rejette les trame en broadcast et en multicast sur EXTIF (évite leur journalisation)
241
# On rejette les trame en broadcast et en multicast sur EXTIF (évite leur journalisation)
242
# Drop broadcast & multicast on EXTIF to avoid log 
242
# Drop broadcast & multicast on EXTIF to avoid log
243
$IPTABLES -A INPUT -m addrtype --dst-type BROADCAST,MULTICAST -j DROP
243
$IPTABLES -A INPUT -m addrtype --dst-type BROADCAST,MULTICAST -j DROP
244
 
244
 
245
# On autorise les retours de connexions légitimes par INPUT
245
# On autorise les retours de connexions légitimes par INPUT
246
# Conntrack on INPUT
246
# Conntrack on INPUT
247
$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
247
$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
248
 
248
 
249
# 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)
249
# 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)
250
# Deny direct connections on DansGuardian port (8080). The concerned paquets have been marked and logged in mangle table (PREROUTING)
250
# Deny direct connections on DansGuardian port (8080). The concerned paquets have been marked and logged in mangle table (PREROUTING)
251
$IPTABLES -A INPUT -i $TUNIF -p tcp --dport 8080 -m mark --mark 1 -j REJECT --reject-with tcp-reset
251
$IPTABLES -A INPUT -i $TUNIF -p tcp --dport 8080 -m mark --mark 1 -j REJECT --reject-with tcp-reset
252
 
252
 
253
# Autorisation des connexions légitimes à DansGuardian 
253
# Autorisation des connexions légitimes à DansGuardian
254
# Allow connections for DansGuardian
254
# Allow connections for DansGuardian
255
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport 8080 -m state --state NEW --syn -j ACCEPT
255
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport 8080 -m state --state NEW --syn -j ACCEPT
256
 
256
 
257
# On interdit les connexions directes au port utilisé par tinyproxy (8090). Les packets concernés ont été marqués et loggués dans la table mangle (PREROUTING)
257
# On interdit les connexions directes au port utilisé par tinyproxy (8090). Les packets concernés ont été marqués et loggués dans la table mangle (PREROUTING)
258
# Deny direct connections on tinyproxy port (8090). The concerned paquets have been marked in mangle table (PREROUTING)
258
# Deny direct connections on tinyproxy port (8090). The concerned paquets have been marked in mangle table (PREROUTING)
259
$IPTABLES -A INPUT -i $TUNIF -p tcp --dport 8090 -m mark --mark 2 -j REJECT --reject-with tcp-reset
259
$IPTABLES -A INPUT -i $TUNIF -p tcp --dport 8090 -m mark --mark 2 -j REJECT --reject-with tcp-reset
260
 
260
 
261
# Autorisation des connexions légitimes vers tinyproxy 
261
# Autorisation des connexions légitimes vers tinyproxy
262
# Allow connections to tinyproxy
262
# Allow connections to tinyproxy
263
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport 8090 -m state --state NEW --syn -j ACCEPT
263
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -p tcp --dport 8090 -m state --state NEW --syn -j ACCEPT
264
 
264
 
265
# On interdit les connexions directes au port 54 (DNS-blacklist). Les packets concernés ont été marqués dans la table mangle (PREROUTING)
265
# On interdit les connexions directes au port 54 (DNS-blacklist). Les packets concernés ont été marqués dans la table mangle (PREROUTING)
266
# Deny direct connections on port 54 (DNS-blacklist). The concerned paquets are marked in mangle table (PREROUTING)
266
# Deny direct connections on port 54 (DNS-blacklist). The concerned paquets are marked in mangle table (PREROUTING)
Line 292... Line 292...
292
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport 56 -j ACCEPT
292
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport 56 -j ACCEPT
293
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport 56 -j ACCEPT
293
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport 56 -j ACCEPT
294
 
294
 
295
# Accès direct aux services internes
295
# Accès direct aux services internes
296
# Internal services access
296
# Internal services access
297
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport domain -j ACCEPT	# DNS 
297
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p udp --dport domain -j ACCEPT	# DNS
298
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport domain -j ACCEPT	# DNS
298
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport domain -j ACCEPT	# DNS
299
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p icmp --icmp-type 8 -j ACCEPT	# Réponse ping # ping responce
299
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p icmp --icmp-type 8 -j ACCEPT	# Réponse ping # ping responce
300
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p icmp --icmp-type 0 -j ACCEPT	# Requête  ping # ping request
300
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p icmp --icmp-type 0 -j ACCEPT	# Requête  ping # ping request
301
$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
301
$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
302
$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
302
$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
303
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport 3990:3991 -j ACCEPT	# Requêtes de deconnexion usagers # Users logout requests
303
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport 3990:3991 -j ACCEPT	# Requêtes de deconnexion usagers # Users logout requests
304
$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
304
$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
305
 
305
 
306
# SSHD rules if activate 
306
# SSHD rules if activate
307
if [ $SSH = on ]
307
if [ $SSH = on ]
308
	then
308
	then
309
	$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport ssh -m state --state NEW -j NFLOG --nflog-group 2 --nflog-prefix "RULE ssh-from-LAN -- ACCEPT"
309
	$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport ssh -m state --state NEW -j NFLOG --nflog-group 2 --nflog-prefix "RULE ssh-from-LAN -- ACCEPT"
310
	$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport ssh -j ACCEPT
310
	$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -d $PRIVATE_IP -p tcp --dport ssh -j ACCEPT
311
	$IPTABLES -A INPUT -i $EXTIF -s $SSH_ADMIN_FROM -d $PUBLIC_IP -p tcp --dport ssh -m state --state NEW --syn -j NFLOG --nflog-group 2 --nflog-prefix "RULE ssh-from-WAN -- ACCEPT"
311
	$IPTABLES -A INPUT -i $EXTIF -s $SSH_ADMIN_FROM -d $PUBLIC_IP -p tcp --dport ssh -m state --state NEW --syn -j NFLOG --nflog-group 2 --nflog-prefix "RULE ssh-from-WAN -- ACCEPT"
Line 313... Line 313...
313
fi
313
fi
314
 
314
 
315
# Insertion de règles locales
315
# Insertion de règles locales
316
# Here, we add local rules (i.e. VPN from Internet)
316
# Here, we add local rules (i.e. VPN from Internet)
317
if [ -f /usr/local/etc/alcasar-iptables-local.sh ]; then
317
if [ -f /usr/local/etc/alcasar-iptables-local.sh ]; then
318
        . /usr/local/etc/alcasar-iptables-local.sh
318
	. /usr/local/etc/alcasar-iptables-local.sh
319
fi
319
fi
320
 
320
 
321
# Journalisation et rejet des connexions (autres que celles autorisées) effectuées depuis le LAN
321
# Journalisation et rejet des connexions (autres que celles autorisées) effectuées depuis le LAN
322
# Deny and log on INPUT from the LAN
322
# Deny and log on INPUT from the LAN
323
$IPTABLES -A INPUT -i $TUNIF -m state --state NEW -j NFLOG --nflog-group 1 --nflog-prefix "RULE rej-int -- REJECT "
323
$IPTABLES -A INPUT -i $TUNIF -m state --state NEW -j NFLOG --nflog-group 1 --nflog-prefix "RULE rej-int -- REJECT "
Line 350... Line 350...
350
 
350
 
351
# Active le suivi de session
351
# Active le suivi de session
352
# Allow Conntrack
352
# Allow Conntrack
353
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
353
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
354
 
354
 
355
# Compute uamallowed IP (IP address of equipments connected between ALCASAR and Internet (DMZ, own servers, ...) 
355
# Compute uamallowed IP (IP address of equipments connected between ALCASAR and Internet (DMZ, own servers, ...)
356
nb_uamallowed=`wc -l /usr/local/etc/alcasar-uamallowed | cut -d" "  -f1`
356
nb_uamallowed=`wc -l /usr/local/etc/alcasar-uamallowed | cut -d" "  -f1`
357
if [ $nb_uamallowed != "0" ]
357
if [ $nb_uamallowed != "0" ]
358
then
358
then
359
	while read ip_allowed_line 
359
	while read ip_allowed_line
360
	do
360
	do
361
		ip_allowed=`echo $ip_allowed_line|cut -d"\"" -f2`
361
		ip_allowed=`echo $ip_allowed_line|cut -d"\"" -f2`
362
		$IPTABLES -A FORWARD -i $TUNIF -d $ip_allowed -m state --state NEW -j NETFLOW
362
		$IPTABLES -A FORWARD -i $TUNIF -d $ip_allowed -m state --state NEW -j NETFLOW
363
		$IPTABLES -A FORWARD -i $TUNIF -d $ip_allowed -m state --state NEW -j ACCEPT
363
		$IPTABLES -A FORWARD -i $TUNIF -d $ip_allowed -m state --state NEW -j ACCEPT
364
	done < /usr/local/etc/alcasar-uamallowed
364
	done < /usr/local/etc/alcasar-uamallowed
Line 419... Line 419...
419
		fi
419
		fi
420
		$IPTABLES -A FORWARD -i $TUNIF -m set --match-set proto_3 src -s $PRIVATE_NETWORK_MASK -p tcp -m multiport ! --dports $custom_tcp_protocols_list -m state --state NEW -j REJECT --reject-with tcp-reset
420
		$IPTABLES -A FORWARD -i $TUNIF -m set --match-set proto_3 src -s $PRIVATE_NETWORK_MASK -p tcp -m multiport ! --dports $custom_tcp_protocols_list -m state --state NEW -j REJECT --reject-with tcp-reset
421
		$IPTABLES -A FORWARD -i $TUNIF -m set --match-set proto_3 src -s $PRIVATE_NETWORK_MASK -p udp -m multiport ! --dports $custom_udp_protocols_list -m state --state NEW -j REJECT --reject-with icmp-port-unreachable
421
		$IPTABLES -A FORWARD -i $TUNIF -m set --match-set proto_3 src -s $PRIVATE_NETWORK_MASK -p udp -m multiport ! --dports $custom_udp_protocols_list -m state --state NEW -j REJECT --reject-with icmp-port-unreachable
422
	fi
422
	fi
423
 
423
 
424
# journalisation et autorisation des connections sortant du LAN  
424
# journalisation et autorisation des connections sortant du LAN
425
# Allow forward connections with log
425
# Allow forward connections with log
426
$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -m state --state NEW -j NETFLOW
426
$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -m state --state NEW -j NETFLOW
427
$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -m state --state NEW -j ACCEPT
427
$IPTABLES -A FORWARD -i $TUNIF -s $PRIVATE_NETWORK_MASK -m state --state NEW -j ACCEPT
428
 
428
 
429
#############################
429
#############################
Line 431... Line 431...
431
#############################
431
#############################
432
# On laisse tout sortir sur toutes les cartes sauf celle qui est connectée sur l'extérieur
432
# On laisse tout sortir sur toutes les cartes sauf celle qui est connectée sur l'extérieur
433
# Everything is allowed but traffic through outside network interface
433
# Everything is allowed but traffic through outside network interface
434
$IPTABLES -A OUTPUT ! -o $EXTIF -j ACCEPT
434
$IPTABLES -A OUTPUT ! -o $EXTIF -j ACCEPT
435
 
435
 
436
# Si configéré, on autorise les requêtes DHCP 
436
# Si configéré, on autorise les requêtes DHCP
437
# Allow DHCP requests if configured
437
# Allow DHCP requests if configured
438
public_ip_mask=`grep ^PUBLIC_IP= $CONF_FILE|cut -d"=" -f2`		# ALCASAR WAN IP address
438
public_ip_mask=`grep ^PUBLIC_IP= $CONF_FILE|cut -d"=" -f2`		# ALCASAR WAN IP address
439
if [[ "$public_ip_mask" == "dhcp" ]]
439
if [[ "$public_ip_mask" == "dhcp" ]]
440
then
440
then
441
	$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport 67 -j ACCEPT
441
	$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport 67 -j ACCEPT
442
	$IPTABLES -A OUTPUT -o $EXTIF -p udp --dport 67 -j ACCEPT
442
	$IPTABLES -A OUTPUT -o $EXTIF -p udp --dport 67 -j ACCEPT
443
fi
443
fi
444
 
444
 
445
# On autorise les requêtes DNS vers les serveurs DNS identifiés 
445
# On autorise les requêtes DNS vers les serveurs DNS identifiés
446
# Allow DNS requests to identified DNS servers
446
# Allow DNS requests to identified DNS servers
447
$IPTABLES -A OUTPUT -o $EXTIF -d $DNSSERVERS -p udp --dport domain -m state --state NEW -j ACCEPT
447
$IPTABLES -A OUTPUT -o $EXTIF -d $DNSSERVERS -p udp --dport domain -m state --state NEW -j ACCEPT
448
 
448
 
449
# On autorise les requêtes HTTP sortantes
449
# On autorise les requêtes HTTP sortantes
450
# HTTP requests are allowed
450
# HTTP requests are allowed
Line 457... Line 457...
457
 
457
 
458
# On autorise les requêtes RSYNC sortantes (maj BL de Toulouse)
458
# On autorise les requêtes RSYNC sortantes (maj BL de Toulouse)
459
# RSYNC requests are allowed (to update BL of Toulouse)
459
# RSYNC requests are allowed (to update BL of Toulouse)
460
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport rsync -j ACCEPT
460
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport rsync -j ACCEPT
461
 
461
 
462
# On autorise les requêtes FTP 
462
# On autorise les requêtes FTP
463
# FTP requests are allowed
463
# FTP requests are allowed
464
modprobe nf_conntrack_ftp
464
modprobe nf_conntrack_ftp
465
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport ftp -j ACCEPT
465
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport ftp -j ACCEPT
466
$IPTABLES -A OUTPUT -o $EXTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
466
$IPTABLES -A OUTPUT -o $EXTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
467
 
467
 
468
# On autorise les requêtes NTP 
468
# On autorise les requêtes NTP
469
# NTP requests are allowed
469
# NTP requests are allowed
470
$IPTABLES -A OUTPUT -o $EXTIF -p udp --dport ntp -j ACCEPT
470
$IPTABLES -A OUTPUT -o $EXTIF -p udp --dport ntp -j ACCEPT
471
 
471
 
472
# On autorise les requêtes ICMP (ping) 
472
# On autorise les requêtes ICMP (ping)
473
# ICMP (ping) requests are allowed
473
# ICMP (ping) requests are allowed
474
$IPTABLES -A OUTPUT -o $EXTIF -p icmp --icmp-type 8 -j ACCEPT
474
$IPTABLES -A OUTPUT -o $EXTIF -p icmp --icmp-type 8 -j ACCEPT
475
 
475
 
476
# On autorise les requêtes LDAP si un serveur externe est configué
476
# On autorise les requêtes LDAP si un serveur externe est configué
477
# LDAP requests are allowed if an external server is declared
477
# LDAP requests are allowed if an external server is declared
Line 487... Line 487...
487
# Traduction dynamique d'adresse en sortie
487
# Traduction dynamique d'adresse en sortie
488
# Dynamic NAT on EXTIF
488
# Dynamic NAT on EXTIF
489
$IPTABLES -A POSTROUTING -t nat -o $EXTIF -j MASQUERADE
489
$IPTABLES -A POSTROUTING -t nat -o $EXTIF -j MASQUERADE
490
 
490
 
491
# End of script
491
# End of script
492
 
-