minifirewall/minifirewall

608 lines
17 KiB
Plaintext
Raw Normal View History

#!/bin/sh
2011-04-02 12:12:49 +02:00
# minifirewall is shellscripts for easy firewalling on a standalone server
# we used netfilter/iptables http://netfilter.org/ designed for recent Linux kernel
2020-02-17 10:54:01 +01:00
# See https://gitea.evolix.org/evolix/minifirewall
2021-05-22 23:22:31 +02:00
# Copyright (c) 2007-2021 Evolix
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License.
# Description
# script for standalone server
# Start or stop minifirewall
#
### BEGIN INIT INFO
# Provides: minfirewall
# Required-Start:
# Required-Stop:
# Should-Start: $network $syslog $named
# Should-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop the firewall
# Description: Firewall designed for standalone server
### END INIT INFO
2021-09-06 14:02:03 +02:00
VERSION="21.09"
DESC="minifirewall"
NAME="minifirewall"
2021-05-22 22:44:47 +02:00
set -u
# Variables configuration
#########################
# iptables paths
2021-05-22 23:12:09 +02:00
IPT=$(command -v iptables)
if [ -z "${IPT}" ]; then
echo "Unable to find 'iptables\` command in PATH." >&2
exit 1
fi
IPT6=$(command -v ip6tables)
if [ -z "${IPT6}" ]; then
echo "Unable to find 'ip6tables\` command in PATH." >&2
exit 1
fi
# TCP/IP variables
LOOPBACK='127.0.0.0/8'
CLASSA='10.0.0.0/8'
CLASSB='172.16.0.0/12'
CLASSC='192.168.0.0/16'
CLASSD='224.0.0.0/4'
CLASSE='240.0.0.0/5'
ALL='0.0.0.0'
BROAD='255.255.255.255'
PORTSROOT='0:1023'
PORTSUSER='1024:65535'
2020-02-21 16:26:41 +01:00
# Configuration
2021-05-22 22:44:47 +02:00
INT=''
IPV6=''
DOCKER=''
INTLAN=''
TRUSTEDIPS=''
PRIVILEGIEDIPS=''
SERVICESTCP1p=''
SERVICESUDP1p=''
SERVICESTCP1=''
SERVICESUDP1=''
SERVICESTCP2=''
SERVICESUDP2=''
SERVICESTCP3=''
SERVICESUDP3=''
DNSSERVEURS=''
HTTPSITES=''
HTTPSSITES=''
FTPSITES=''
SSHOK=''
SMTPOK=''
SMTPSECUREOK=''
NTPOK=''
2021-05-26 13:20:12 +02:00
PROXY=''
PROXYBYPASS=''
PROXYPORT=''
2021-05-26 13:12:15 +02:00
BACKUPSERVERS=''
2021-05-22 22:44:47 +02:00
2021-05-22 23:14:27 +02:00
legacy_config_file="/etc/firewall.rc"
config_file="/etc/default/minifirewall"
2021-05-26 13:09:50 +02:00
includes_dir="/etc/minifirewall.d"
2020-02-21 16:26:41 +01:00
2021-05-22 23:14:27 +02:00
IPV6=$(grep "IPV6=" "${config_file}" | awk -F '=' -F "'" '{print $2}')
DOCKER=$(grep "DOCKER=" "${config_file}" | awk -F '=' -F "'" '{print $2}')
INT=$(grep "INT=" "${config_file}" | awk -F '=' -F "'" '{print $2}')
2021-05-22 22:46:02 +02:00
is_ipv6_enabled() {
test "${IPV6}" != "off"
}
is_docker_enabled() {
test "${DOCKER}" = "on"
}
2021-05-26 13:20:12 +02:00
is_proxy_enabled() {
test "${PROXY}" = "on"
}
2021-09-06 14:33:22 +02:00
is_ipv6() {
2021-09-14 08:54:52 +02:00
echo "$1" | grep -q ':'
2021-09-06 14:33:22 +02:00
}
2021-05-22 09:46:22 +02:00
chain_exists() {
2021-05-22 23:14:40 +02:00
chain_name="$1"
if [ $# -ge 2 ]; then
intable="--table $2"
fi
# shellcheck disable=SC2086
iptables ${intable} -nL "${chain_name}" >/dev/null 2>&1
2021-05-22 09:23:14 +02:00
}
source_file_or_error() {
file=$1
echo "...sourcing '${file}\`"
2021-05-22 09:23:31 +02:00
tmpfile=$(mktemp --tmpdir=/tmp minifirewall.XXX)
. "${file}" 2>"${tmpfile}" >&2
if [ -s "${tmpfile}" ]; then
echo "${file} returns standard or error output (see below). Stopping." >&2
cat "${tmpfile}"
exit 1
fi
rm "${tmpfile}"
}
2021-05-22 23:14:27 +02:00
source_configuration() {
if test -f ${legacy_config_file}; then
echo "${legacy_config_file} is deprecated, rename to ${config_file}" >&2
exit 1
fi
if ! test -f ${config_file}; then
echo "${config_file} does not exist" >&2
exit 1
fi
source_file_or_error ${config_file}
if [ -d "${includes_dir}" ]; then
include_files=$(find ${includes_dir} -type f -readable -not -name '*.*')
for include_file in ${include_files}; do
source_file_or_error "${include_file}"
done
fi
}
2021-05-22 09:23:14 +02:00
start() {
2021-09-06 14:02:03 +02:00
echo "Start IPTables rules..."
2021-05-22 09:23:14 +02:00
# Stop and warn if error!
set -e
trap 'echo "ERROR in minifirewall configuration (fix it now!) or script manipulation (fix yourself)." ' INT TERM EXIT
# sysctl network security settings
##################################
# Don't answer to broadcast pings
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
# Ignore bogus ICMP responses
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
# Disable Source Routing
2021-05-22 23:13:00 +02:00
for proc_sys_file in /proc/sys/net/ipv4/conf/*/accept_source_route; do
echo 0 > "${proc_sys_file}"
done
2021-05-22 09:23:14 +02:00
# Enable TCP SYN cookies to avoid TCP-SYN-FLOOD attacks
# cf http://cr.yp.to/syncookies.html
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
# Disable ICMP redirects
2021-05-22 23:13:00 +02:00
for proc_sys_file in /proc/sys/net/ipv4/conf/*/accept_redirects; do
echo 0 > "${proc_sys_file}"
done
2021-05-22 23:13:00 +02:00
for proc_sys_file in /proc/sys/net/ipv4/conf/*/send_redirects; do
echo 0 > "${proc_sys_file}"
done
2021-05-22 09:23:14 +02:00
# Enable Reverse Path filtering : verify if responses use same network interface
2021-05-22 23:13:00 +02:00
for proc_sys_file in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo 1 > "${proc_sys_file}"
2021-05-22 09:23:14 +02:00
done
2021-05-22 09:23:14 +02:00
# log des paquets avec adresse incoherente
2021-05-22 23:13:00 +02:00
for proc_sys_file in /proc/sys/net/ipv4/conf/*/log_martians; do
echo 1 > "${proc_sys_file}"
2021-05-22 09:23:14 +02:00
done
2021-05-22 09:23:14 +02:00
# IPTables configuration
########################
${IPT} -N LOG_DROP
${IPT} -A LOG_DROP -j LOG --log-prefix '[IPTABLES DROP] : '
${IPT} -A LOG_DROP -j DROP
${IPT} -N LOG_ACCEPT
${IPT} -A LOG_ACCEPT -j LOG --log-prefix '[IPTABLES ACCEPT] : '
${IPT} -A LOG_ACCEPT -j ACCEPT
2021-05-22 23:14:27 +02:00
source_configuration
2021-05-22 09:23:14 +02:00
# Trusted ip addresses
${IPT} -N ONLYTRUSTED
${IPT} -A ONLYTRUSTED -j LOG_DROP
2021-05-22 09:41:29 +02:00
for ip in ${TRUSTEDIPS}; do
${IPT} -I ONLYTRUSTED -s ${ip} -j ACCEPT
done
2021-05-22 09:23:14 +02:00
# Privilegied ip addresses
# (trusted ip addresses *are* privilegied)
${IPT} -N ONLYPRIVILEGIED
${IPT} -A ONLYPRIVILEGIED -j ONLYTRUSTED
2021-05-22 09:41:29 +02:00
for ip in ${PRIVILEGIEDIPS}; do
${IPT} -I ONLYPRIVILEGIED -s ${ip} -j ACCEPT
done
2021-05-22 09:23:14 +02:00
# Chain for restrictions (blacklist IPs/ranges)
${IPT} -N NEEDRESTRICT
2021-05-22 09:23:14 +02:00
# We allow all on loopback interface
${IPT} -A INPUT -i lo -j ACCEPT
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -A INPUT -i lo -j ACCEPT
fi
2021-05-22 09:23:14 +02:00
# if OUTPUTDROP
${IPT} -A OUTPUT -o lo -j ACCEPT
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -A OUTPUT -o lo -j ACCEPT
fi
2021-05-22 09:23:14 +02:00
# We avoid "martians" packets, typical when W32/Blaster virus
# attacked windowsupdate.com and DNS was changed to 127.0.0.1
# ${IPT} -t NAT -I PREROUTING -s ${LOOPBACK} -i ! lo -j DROP
${IPT} -A INPUT -s ${LOOPBACK} ! -i lo -j DROP
2021-05-22 22:46:02 +02:00
if is_docker_enabled; then
${IPT} -N MINIFW-DOCKER-TRUSTED
${IPT} -A MINIFW-DOCKER-TRUSTED -j DROP
${IPT} -N MINIFW-DOCKER-PRIVILEGED
${IPT} -A MINIFW-DOCKER-PRIVILEGED -j MINIFW-DOCKER-TRUSTED
${IPT} -A MINIFW-DOCKER-PRIVILEGED -j RETURN
${IPT} -N MINIFW-DOCKER-PUB
${IPT} -A MINIFW-DOCKER-PUB -j MINIFW-DOCKER-PRIVILEGED
${IPT} -A MINIFW-DOCKER-PUB -j RETURN
2021-05-22 09:23:14 +02:00
# Flush DOCKER-USER if exist, create it if absent
if chain_exists 'DOCKER-USER'; then
${IPT} -F DOCKER-USER
2021-05-22 09:23:14 +02:00
else
${IPT} -N DOCKER-USER
2021-05-22 09:23:14 +02:00
fi;
2021-05-22 09:23:14 +02:00
# Pipe new connection through MINIFW-DOCKER-PUB
${IPT} -A DOCKER-USER -i ${INT} -m state --state NEW -j MINIFW-DOCKER-PUB
${IPT} -A DOCKER-USER -j RETURN
2021-05-22 09:23:14 +02:00
fi
2021-05-22 09:23:14 +02:00
# Local services restrictions
#############################
# Allow services for ${INTLAN} (local server or local network)
${IPT} -A INPUT -s ${INTLAN} -j ACCEPT
2021-05-22 09:23:14 +02:00
# Enable protection chain for sensible services
2021-05-22 09:41:29 +02:00
for port in ${SERVICESTCP1p}; do
${IPT} -A INPUT -p tcp --dport ${port} -j NEEDRESTRICT
done
2021-05-22 09:41:29 +02:00
for port in ${SERVICESUDP1p}; do
${IPT} -A INPUT -p udp --dport ${port} -j NEEDRESTRICT
done
2021-05-22 09:23:14 +02:00
# Public service
2021-05-22 09:41:29 +02:00
for port in ${SERVICESTCP1}; do
${IPT} -A INPUT -p tcp --dport ${port} -j ACCEPT
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -A INPUT -p tcp --dport ${port} -j ACCEPT
fi
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:41:29 +02:00
for port in ${SERVICESUDP1}; do
${IPT} -A INPUT -p udp --dport ${port} -j ACCEPT
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -A INPUT -p udp --dport ${port} -j ACCEPT
fi
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:23:14 +02:00
# Privilegied services
2021-05-22 09:41:29 +02:00
for port in ${SERVICESTCP2}; do
${IPT} -A INPUT -p tcp --dport ${port} -j ONLYPRIVILEGIED
done
2021-05-22 09:41:29 +02:00
for port in ${SERVICESUDP2}; do
${IPT} -A INPUT -p udp --dport ${port} -j ONLYPRIVILEGIED
done
2021-05-22 09:23:14 +02:00
# Private services
2021-05-22 09:41:29 +02:00
for port in ${SERVICESTCP3}; do
${IPT} -A INPUT -p tcp --dport ${port} -j ONLYTRUSTED
done
2021-05-22 09:41:29 +02:00
for port in ${SERVICESUDP3}; do
${IPT} -A INPUT -p udp --dport ${port} -j ONLYTRUSTED
done
2021-05-22 22:46:02 +02:00
if is_docker_enabled; then
2021-05-22 09:23:14 +02:00
# Public services defined in SERVICESTCP1 & SERVICESUDP1
2021-05-22 09:41:29 +02:00
for dstport in ${SERVICESTCP1}; do
${IPT} -I MINIFW-DOCKER-PUB -p tcp --dport "${dstport}" -j RETURN
done
for dstport in ${SERVICESUDP1}; do
${IPT} -I MINIFW-DOCKER-PUB -p udp --dport "${dstport}" -j RETURN
done
# Privileged services (accessible from privileged & trusted IPs)
for dstport in ${SERVICESTCP2}; do
for srcip in ${PRIVILEGIEDIPS}; do
${IPT} -I MINIFW-DOCKER-PRIVILEGED -p tcp -s "${srcip}" --dport "${dstport}" -j RETURN
2021-05-22 09:23:14 +02:00
done
2021-05-22 09:41:29 +02:00
for srcip in ${TRUSTEDIPS}; do
${IPT} -I MINIFW-DOCKER-PRIVILEGED -p tcp -s "${srcip}" --dport "${dstport}" -j RETURN
2021-05-22 09:23:14 +02:00
done
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:23:14 +02:00
2021-05-22 09:41:29 +02:00
for dstport in ${SERVICESUDP2}; do
for srcip in ${PRIVILEGIEDIPS}; do
${IPT} -I MINIFW-DOCKER-PRIVILEGED -p udp -s "${srcip}" --dport "${dstport}" -j RETURN
2021-05-22 09:23:14 +02:00
done
2021-05-22 09:41:29 +02:00
for srcip in ${TRUSTEDIPS}; do
${IPT} -I MINIFW-DOCKER-PRIVILEGED -p udp -s "${srcip}" --dport "${dstport}" -j RETURN
2021-05-22 09:23:14 +02:00
done
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:23:14 +02:00
# Trusted services (accessible from trusted IPs)
2021-05-22 09:41:29 +02:00
for dstport in ${SERVICESTCP3}; do
for srcip in ${TRUSTEDIPS}; do
${IPT} -I MINIFW-DOCKER-TRUSTED -p tcp -s "${srcip}" --dport "${dstport}" -j RETURN
2021-05-22 09:23:14 +02:00
done
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:23:14 +02:00
2021-05-22 09:41:29 +02:00
for dstport in ${SERVICESUDP3}; do
for srcip in ${TRUSTEDIPS}; do
${IPT} -I MINIFW-DOCKER-TRUSTED -p udp -s "${srcip}" --dport "${dstport}" -j RETURN
2021-05-22 09:23:14 +02:00
done
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:23:14 +02:00
fi
# External services
###################
2021-05-22 09:23:14 +02:00
# DNS authorizations
2021-05-22 22:45:48 +02:00
for src in ${DNSSERVEURS}; do
${IPT} -A INPUT -p tcp ! --syn --sport 53 --dport ${PORTSUSER} -s ${src} -j ACCEPT
${IPT} -A INPUT -p udp --sport 53 --dport ${PORTSUSER} -s ${src} -m state --state ESTABLISHED,RELATED -j ACCEPT
${IPT} -A OUTPUT -o ${INT} -p udp -d ${src} --dport 53 --match state --state NEW -j ACCEPT
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:23:14 +02:00
# HTTP (TCP/80) authorizations
2021-05-22 22:45:48 +02:00
for src in ${HTTPSITES}; do
${IPT} -A INPUT -p tcp ! --syn --sport 80 --dport ${PORTSUSER} -s ${src} -j ACCEPT
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:23:14 +02:00
# HTTPS (TCP/443) authorizations
2021-05-22 22:45:48 +02:00
for src in ${HTTPSSITES}; do
${IPT} -A INPUT -p tcp ! --syn --sport 443 --dport ${PORTSUSER} -s ${src} -j ACCEPT
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:23:14 +02:00
# FTP (so complex protocol...) authorizations
2021-05-22 22:45:48 +02:00
for src in ${FTPSITES}; do
2021-05-22 09:41:29 +02:00
# requests on Control connection
2021-05-22 22:45:48 +02:00
${IPT} -A INPUT -p tcp ! --syn --sport 21 --dport ${PORTSUSER} -s ${src} -j ACCEPT
2021-05-22 09:41:29 +02:00
# FTP port-mode on Data Connection
2021-05-22 22:45:48 +02:00
${IPT} -A INPUT -p tcp --sport 20 --dport ${PORTSUSER} -s ${src} -j ACCEPT
2021-05-22 09:41:29 +02:00
# FTP passive-mode on Data Connection
# WARNING, this allow all connections on TCP ports > 1024
2021-05-22 22:45:48 +02:00
${IPT} -A INPUT -p tcp ! --syn --sport ${PORTSUSER} --dport ${PORTSUSER} -s ${src} -j ACCEPT
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:23:14 +02:00
# SSH authorizations
2021-05-22 22:45:48 +02:00
for src in ${SSHOK}; do
${IPT} -A INPUT -p tcp ! --syn --sport 22 -s ${src} -j ACCEPT
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:23:14 +02:00
# SMTP authorizations
2021-05-22 22:45:48 +02:00
for src in ${SMTPOK}; do
${IPT} -A INPUT -p tcp ! --syn --sport 25 --dport ${PORTSUSER} -s ${src} -j ACCEPT
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:23:14 +02:00
# secure SMTP (TCP/465 et TCP/587) authorizations
2021-05-22 22:45:48 +02:00
for src in ${SMTPSECUREOK}; do
${IPT} -A INPUT -p tcp ! --syn --sport 465 --dport ${PORTSUSER} -s ${src} -j ACCEPT
${IPT} -A INPUT -p tcp ! --syn --sport 587 --dport ${PORTSUSER} -s ${src} -j ACCEPT
2021-05-22 09:41:29 +02:00
done
2021-05-22 09:23:14 +02:00
# NTP authorizations
2021-05-22 22:45:48 +02:00
for src in ${NTPOK}; do
${IPT} -A INPUT -p udp --sport 123 -s ${src} -j ACCEPT
${IPT} -A OUTPUT -o ${INT} -p udp -d ${src} --dport 123 --match state --state NEW -j ACCEPT
2021-05-22 09:41:29 +02:00
done
2021-05-26 13:20:12 +02:00
# Proxy (Squid)
if is_proxy_enabled; then
${IPT} -t nat -A OUTPUT -p tcp --dport 80 -m owner --uid-owner proxy -j ACCEPT
for dstip in ${PROXYBYPASS}; do
${IPT} -t nat -A OUTPUT -p tcp --dport 80 -d "${dstip}" -j ACCEPT
done
${IPT} -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-port "${PROXYPORT:-'8888'}"
fi
2021-05-26 13:12:15 +02:00
# Output for backup servers
for server in ${BACKUPSERVERS}; do
server_ip=$(echo "${server}" | cut -d ':' -f1)
server_port=$(echo "${server}" | cut -d ':' -f2)
if [ -n "${server_ip}" ] && [ -n "${server_port}" ]; then
${IPT} -A INPUT -p tcp --sport "${server_port}" --dport 1024:65535 -s "${server_ip}" -m state --state ESTABLISHED,RELATED -j ACCEPT
else
echo "Unrecognized syntax for BACKUPSERVERS '${server}\`. Use space-separated IP:PORT tuples." >&2
exit 1
fi
done
2021-05-22 09:23:14 +02:00
# Always allow ICMP
${IPT} -A INPUT -p icmp -j ACCEPT
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -A INPUT -p icmpv6 -j ACCEPT
fi
2021-05-22 09:23:14 +02:00
# IPTables policy
#################
2021-05-22 09:23:14 +02:00
# by default DROP INPUT packets
${IPT} -P INPUT DROP
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -P INPUT DROP
fi
2021-05-22 22:46:02 +02:00
# by default, no FORWARDING (deprecated for Virtual Machines)
2021-05-22 09:23:14 +02:00
#echo 0 > /proc/sys/net/ipv4/ip_forward
#${IPT} -P FORWARD DROP
#${IPT6} -P FORWARD DROP
2021-05-22 09:23:14 +02:00
# by default allow OUTPUT packets... but drop UDP packets (see OUTPUTDROP to drop OUTPUT packets)
${IPT} -P OUTPUT ACCEPT
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -P OUTPUT ACCEPT
fi
${IPT} -A OUTPUT -o ${INT} -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -A OUTPUT -o ${INT} -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT
fi
${IPT} -A OUTPUT -p udp --match state --state ESTABLISHED,RELATED -j ACCEPT
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -A OUTPUT -p udp --match state --state ESTABLISHED,RELATED -j ACCEPT
fi
${IPT} -A OUTPUT -p udp -j DROP
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -A OUTPUT -p udp -j DROP
fi
2021-05-22 09:23:14 +02:00
trap - INT TERM EXIT
echo "...starting IPTables rules is now finish : OK"
}
stop() {
2015-09-13 20:31:04 +02:00
echo "Flush all rules and accept everything..."
# Delete all rules
${IPT} -F INPUT
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -F INPUT
fi
${IPT} -F OUTPUT
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -F OUTPUT
fi
${IPT} -F LOG_DROP
${IPT} -F LOG_ACCEPT
${IPT} -F ONLYTRUSTED
${IPT} -F ONLYPRIVILEGIED
${IPT} -F NEEDRESTRICT
2021-05-22 22:46:02 +02:00
${IPT} -t mangle -F
2021-05-22 22:46:02 +02:00
if is_docker_enabled; then
${IPT} -F DOCKER-USER
${IPT} -A DOCKER-USER -j RETURN
${IPT} -F MINIFW-DOCKER-PUB
${IPT} -X MINIFW-DOCKER-PUB
${IPT} -F MINIFW-DOCKER-PRIVILEGED
${IPT} -X MINIFW-DOCKER-PRIVILEGED
${IPT} -F MINIFW-DOCKER-TRUSTED
${IPT} -X MINIFW-DOCKER-TRUSTED
2021-05-22 22:46:02 +02:00
else
${IPT} -t nat -F
fi
# Accept all
${IPT} -P INPUT ACCEPT
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -P INPUT ACCEPT
fi
${IPT} -P OUTPUT ACCEPT
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -P OUTPUT ACCEPT
fi
#${IPT} -P FORWARD ACCEPT
#${IPT} -t nat -P PREROUTING ACCEPT
#${IPT} -t nat -P POSTROUTING ACCEPT
# Delete non-standard chains
${IPT} -X LOG_DROP
${IPT} -X LOG_ACCEPT
${IPT} -X ONLYPRIVILEGIED
${IPT} -X ONLYTRUSTED
${IPT} -X NEEDRESTRICT
2015-09-13 20:31:04 +02:00
echo "...flushing IPTables rules is now finish : OK"
2021-05-22 09:23:14 +02:00
}
2021-05-22 09:23:14 +02:00
status() {
${IPT} -L -n -v --line-numbers
${IPT} -t nat -L -n -v --line-numbers
${IPT} -t mangle -L -n -v --line-numbers
${IPT6} -L -n -v --line-numbers
${IPT6} -t mangle -L -n -v --line-numbers
2021-05-22 09:23:14 +02:00
}
2021-05-22 09:23:14 +02:00
reset() {
echo "Reset all IPTables counters..."
${IPT} -Z
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -Z
fi
${IPT} -t nat -Z
2021-05-22 22:46:02 +02:00
${IPT} -t mangle -Z
2021-05-22 22:46:02 +02:00
if is_ipv6_enabled; then
${IPT6} -t mangle -Z
fi
2015-09-13 20:31:04 +02:00
echo "...reseting IPTables counters is now finish : OK"
2021-05-22 09:23:14 +02:00
}
2021-05-22 09:23:14 +02:00
case "$1" in
start)
2021-09-06 14:33:22 +02:00
echo "${NAME} version ${VERSION}"
2021-05-22 09:23:14 +02:00
start
;;
stop)
2021-09-06 14:33:22 +02:00
echo "${NAME} version ${VERSION}"
2021-05-22 09:23:14 +02:00
stop
;;
status)
2021-09-06 14:33:22 +02:00
echo "${NAME} version ${VERSION}"
2021-05-22 09:23:14 +02:00
status
;;
reset)
2021-09-06 14:33:22 +02:00
echo "${NAME} version ${VERSION}"
2021-05-22 09:23:14 +02:00
reset
;;
restart)
2021-09-06 14:33:22 +02:00
echo "${NAME} version ${VERSION}"
2021-05-22 09:23:14 +02:00
stop
start
;;
2021-09-06 14:02:03 +02:00
*)
2021-09-06 14:33:22 +02:00
echo "${NAME} version ${VERSION}"
2021-09-06 14:02:03 +02:00
echo "Usage: $0 {start|stop|restart|status|reset}"
exit 1
esac
exit 0