Skip to content

Commit 7549ba6

Browse files
committed
added multiport chains
1 parent 4af1e4b commit 7549ba6

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

bin/v-add-firewall-chain

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,10 @@ is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
4343
case $chain in
4444
SSH) port=22; protocol=TCP ;;
4545
FTP) port=21; protocol=TCP ;;
46-
MAIL) port=25; protocol=TCP ;;
46+
MAIL) port='25,465,587,2525,110,995,143,993'; protocol=TCP ;;
4747
DNS) port=53; protocol=UDP ;;
48-
HTTP) port=80; protocol=TCP ;;
49-
HTTPS) port=443; protocol=TCP ;;
50-
POP3) port=110; protocol=TCP ;;
51-
IMAP) port=143; protocol=TCP ;;
52-
MYSQL) port=3306; protocol=TCP ;;
53-
POSTGRES) port=5432; protocol=TCP ;;
48+
WEB) port='80,443'; protocol=TCP ;;
49+
DB) port='3306,5432'; protocol=TCP ;;
5450
VESTA) port=8083; protocol=TCP ;;
5551
*) check_args '2' "$#" 'CHAIN PORT' ;;
5652
esac
@@ -59,7 +55,14 @@ esac
5955
$iptables -N fail2ban-$chain 2>/dev/null
6056
if [ $? -eq 0 ]; then
6157
$iptables -A fail2ban-$chain -j RETURN
62-
$iptables -I INPUT -p $protocol --dport $port -j fail2ban-$chain
58+
59+
# Adding multiport module
60+
if [[ "$port" =~ ,|-|: ]] ; then
61+
port_str="-m multiport --dports $port"
62+
else
63+
port_str="--dport $port"
64+
fi
65+
$iptables -I INPUT -p $protocol $port_str -j fail2ban-$chain
6366
fi
6467

6568
# Preserving chain

bin/v-update-firewall

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,14 @@ fi
129129
chains=$VESTA/data/firewall/chains.conf
130130
for chain in $(cat $chains 2>/dev/null); do
131131
eval $chain
132-
$iptables -I INPUT -p $PROTOCOL --dport $PORT -j fail2ban-$CHAIN
132+
if [[ "$PORT" =~ ,|-|: ]] ; then
133+
port="-m multiport --dports $PORT"
134+
else
135+
port="--dport $PORT"
136+
fi
137+
echo "$iptables -I INPUT -p $PROTOCOL $port -j fail2ban-$CHAIN" > $tmp
138+
bash $tmp
139+
rm -f $tmp
133140
done
134141

135142
# Saving rules to the master iptables file

0 commit comments

Comments
 (0)