652 |
richard |
1 |
#!/bin/sh
|
2538 |
tom.houday |
2 |
#
|
826 |
franck |
3 |
# $Id: alcasar-iptables-local.sh 3018 2022-06-04 16:54:31Z rexy $
|
2538 |
tom.houday |
4 |
#
|
|
|
5 |
# Custom rules for ALCASAR firewall
|
|
|
6 |
#
|
|
|
7 |
# Examples:
|
|
|
8 |
# - Local MAC addresses filtering (MAC are in '/usr/local/etc/alcasar-iptables-local-mac-filtered'. Format : aa:09:23:2f:4d:ee)
|
|
|
9 |
# - allow ICMP from an Internet IP address (Admin_from) to EXTIF
|
|
|
10 |
# - Deny access to protected networks from internal LAN
|
3018 |
rexy |
11 |
# - allow SMTP from ALCASAR to an other server
|
2538 |
tom.houday |
12 |
# - Allow managers to access ACC from the external network
|
2989 |
rexy |
13 |
# - Ports Address Translation (PAT) from Internet (one & multiple)
|
2538 |
tom.houday |
14 |
# This script inherit of alcasar-iptables.sh variables : $INTIF, $EXTIF, $IPTABLES, etc
|
2740 |
rexy |
15 |
# !!Beware, run the script "alcasar-iptables.sh" after changing this file.
|
2538 |
tom.houday |
16 |
|
|
|
17 |
# Local MAC addresses filtering (MAC are in '/usr/local/etc/alcasar-iptables-local-mac-filtered'. Format : aa:09:23:2f:4d:ee)
|
1829 |
richard |
18 |
if [ -s /usr/local/etc/alcasar-iptables-local-mac-filtered ]; then
|
2547 |
tom.houday |
19 |
while read mac_line
|
|
|
20 |
do
|
|
|
21 |
ip_on=`echo $mac_line|cut -b1`
|
|
|
22 |
if [ $ip_on != "#" ]
|
|
|
23 |
then
|
|
|
24 |
mac_filtered=`echo $mac_line|cut -d" " -f1`
|
|
|
25 |
echo "MAC filtered = $mac_filtered"
|
|
|
26 |
$IPTABLES -A FORWARD -i $INTIF -m mac --mac-source $mac_filtered -j NFLOG --nflog-group 1 --nflog-prefix "$mac_filtered -- Filt_DROP"
|
|
|
27 |
$IPTABLES -A FORWARD -i $INTIF -p tcp -m mac --mac-source $mac_filtered -j DROP
|
|
|
28 |
$IPTABLES -A FORWARD -i $INTIF -p udp -m mac --mac-source $mac_filtered -j DROP
|
|
|
29 |
$IPTABLES -A FORWARD -i $INTIF -m mac --mac-source $mac_filtered -j DROP
|
|
|
30 |
fi
|
|
|
31 |
done < /usr/local/etc/alcasar-iptables-local-mac-filtered
|
1522 |
franck |
32 |
fi
|
652 |
richard |
33 |
|
2854 |
rexy |
34 |
# On autorise le ping (echo & request) (ICMP N°0 & 8) en provenance d'Internet vers ALCASAR
|
|
|
35 |
# Allow ping (echo & request) (ICMP N°0 & 8) from Internet
|
2956 |
rexy |
36 |
#$IPTABLES -A INPUT -i $EXTIF -p icmp --icmp-type 8 -j ACCEPT
|
|
|
37 |
#$IPTABLES -A OUTPUT -o $EXTIF -p icmp --icmp-type 0 -j ACCEPT
|
652 |
richard |
38 |
|
2986 |
rexy |
39 |
# On interdit les utilisateurs d'accéder à des réseaux situés entre ALCASAR et le routeur d'accès à Internet
|
|
|
40 |
# Deny access of users to networks connected between ALCASAR and Internet broadband router
|
|
|
41 |
#protectedNetworks='10.0.0.0/8,172.16.0.0/12,192.168.0.0/16' # (RFC 1918)
|
|
|
42 |
#[ -n "$TUNIF" ] && consultationIF=$TUNIF || consultationIF=$INTIF
|
|
|
43 |
#$IPTABLES -A FORWARD -i $consultationIF -d $protectedNetworks -j DROP
|
|
|
44 |
#$IPTABLES -A FORWARD -o $consultationIF -s $protectedNetworks -j DROP
|
|
|
45 |
|
2995 |
rexy |
46 |
# On autorise ALCASAR à contacter un serveur MAIL externe (envoie de rapports, alertes, inscription d'utilisateurs, etc.)
|
2993 |
rexy |
47 |
# Allow ALCASAR to connect to a mail server (send reports, alerts, users registration, etc.)
|
|
|
48 |
#SMTP_IP='192.168.111.5'
|
|
|
49 |
#SMTP_PORT=25
|
3016 |
rexy |
50 |
#$IPTABLES -A OUTPUT -p tcp --dport $SMTP_PORT -d $SMTP_IP -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
|
|
|
51 |
#$IPTABLES -A INPUT -p tcp --sport $SMTP_PORT -s $SMTP_IP -m conntrack --ctstate ESTABLISHED -j ACCEPT
|
652 |
richard |
52 |
|
2986 |
rexy |
53 |
# On autorise un admin à accéder à l'ACC depuis l'extérieur (Internet ou le LAN entre ALCASAR et la BOX)
|
|
|
54 |
# Allow managerIP to access ACC from the external network (Internet or LAN between ALCASAR and the broadband router)
|
|
|
55 |
#managerIPs='192.168.0.10'
|
|
|
56 |
#externalPort='34443'
|
|
|
57 |
#$IPTABLES -t mangle -A PREROUTING -i $EXTIF -s $managerIPs -p tcp -d $PUBLIC_IP --dport $externalPort -j MARK --set-mark 100
|
|
|
58 |
#$IPTABLES -t nat -A PREROUTING -i $EXTIF -s $managerIPs -p tcp -d $PUBLIC_IP --dport $externalPort -j DNAT --to $PRIVATE_IP:443
|
|
|
59 |
#$IPTABLES -A INPUT -i $EXTIF -s $managerIPs -p tcp --dport 443 -m mark --mark 100 -j ACCEPT
|
|
|
60 |
|
2989 |
rexy |
61 |
# On autorise l'accès depuis Internet (ex: port 11222) vers un equipement du LAN (ex: port 22). L'équipement sur le LAN doit être en IP fixe
|
|
|
62 |
# Access is allowed from Internet (ie: port 11222) to a LAN equipment (ie: port 22). The equipment must be in static IP
|
2645 |
rexy |
63 |
#$IPTABLES -A PREROUTING -i $EXTIF -t nat -p tcp -d $PUBLIC_IP --dport 11222 -j DNAT --to 192.168.182.10:22
|
|
|
64 |
#$IPTABLES -A PREROUTING -i $EXTIF -t nat -p udp -d $PUBLIC_IP --dport 11222 -j DNAT --to 192.168.182.10:22
|
|
|
65 |
#$IPTABLES -A FORWARD -p tcp -d 192.168.182.10 --dport 22 -j ACCEPT
|
2652 |
tom.houday |
66 |
#$IPTABLES -A FORWARD -p udp -d 192.168.182.10 --dport 22 -j ACCEPT
|
652 |
richard |
67 |
|
2995 |
rexy |
68 |
# On autorise l'accès depuis Internet (en multiports) vers un équipement du LAN (qui doit être en IP fixe)
|
2989 |
rexy |
69 |
# Access is allowed from Internet (multiports) to a LAN equipment (which must be in static IP)
|
2994 |
rexy |
70 |
#ext_ports=11223:11323; int_ports=12000:12100
|
2986 |
rexy |
71 |
#to_ip=192.168.182.7
|
2989 |
rexy |
72 |
#int_ports_dnat=`echo $int_ports|tr : -`
|
2994 |
rexy |
73 |
#ext_ports_dnat=`echo $ext_ports|tr : -`
|
2995 |
rexy |
74 |
#first_ext_port=`echo $ext_ports|cut -d":" -f1`
|
|
|
75 |
#$IPTABLES -A PREROUTING -i $EXTIF -t nat -p tcp -d $PUBLIC_IP --dport $ext_ports -j DNAT --to $to_ip:$int_ports_dnat/$first_ext_port
|
2994 |
rexy |
76 |
#$IPTABLES -A FORWARD -i $EXTIF -p tcp -d $to_ip -m multiport --dports $int_ports -j ACCEPT
|
2995 |
rexy |
77 |
#$IPTABLES -A PREROUTING -i $EXTIF -t nat -p udp -d $PUBLIC_IP --dport $ext_ports -j DNAT --to $to_ip:$int_ports_dnat/$first_ext_port
|
2994 |
rexy |
78 |
#$IPTABLES -A FORWARD -i $EXTIF -p udp -d $to_ip -m multiport --dports $int_ports -j ACCEPT
|
2989 |
rexy |
79 |
|