sbin/mbse-firewall

Mon, 30 Oct 2023 16:24:44 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 30 Oct 2023 16:24:44 +0100
changeset 14
654773d80b70
parent 13
06b03eeae540
permissions
-rwxr-xr-x

Version 0.0.27 Fix for igmp protocol, do not use -m option.

0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 #!/bin/bash
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 # ---------------------------------------------------------------------------
12
8aaa305805df Make sure ipset tables exist.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
4 # Copyright (C) 2013-2023 by Michiel Broek.
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 # Homepage http://www.mbse.eu
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 # Email mbse At mbse dOt eu
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 #
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 # This file is part of mbse-firewall.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 #
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 # This program is free software; you can redistribute it and/or modify it
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 # under the terms of the GNU General Public License as published by the
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 # Free Software Foundation; either version 2, or (at your option) any
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 # later version.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 #
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 # This program is distributed in the hope that it will be useful, but
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 # General Public License for more details.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 #
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 # You should have received a copy of the GNU General Public License
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 # along with this program; see the file COPYING. If not, write to the Free
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 # Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 # ---------------------------------------------------------------------------
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
14
654773d80b70 Version 0.0.27 Fix for igmp protocol, do not use -m option.
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
25 MBSEFW_VERSION="0.0.27"
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 # Sanity checks
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 if [ "$(id -u)" != "0" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 echo "** You must be root to run this program"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 exit 1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 # If possible, log events in /var/log/messages:
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 if [ -f /var/run/syslogd.pid -a -x /usr/bin/logger ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 LOGGER=/usr/bin/logger
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 else # output to stdout/stderr:
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 LOGGER=/bin/cat
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 # IPv6 enabled?
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 USE_IPV6="0"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 if [ -f /proc/sys/net/ipv6/conf/all/disable_ipv6 ] && [ "$(cat /proc/sys/net/ipv6/conf/all/disable_ipv6)" == "0" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 USE_IPV6="1"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 # Find programs
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 IPTABLES=$(which iptables 2>/dev/null)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 IPTABLES_SAVE=$(which iptables-save 2>/dev/null)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 IPTABLES_RESTORE=$(which iptables-restore 2>/dev/null)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 LSMOD=$(which lsmod 2>/dev/null)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 AWK=$(which awk 2>/dev/null)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 GREP=$(which grep 2>/dev/null)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 IPSET=$(which ipset 2>/dev/null)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 SYSCTL=$(which sysctl 2>/dev/null)
2
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
56 NFACCT=$(which nfacct 2>/dev/null)
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 if [ "$USE_IPV6" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 IP6TABLES=$(which ip6tables 2>/dev/null)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 IP6TABLES_SAVE=$(which ip6tables-save 2>/dev/null)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 IP6TABLES_RESTORE=$(which ip6tables-restore 2>/dev/null)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 # Load configuration
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 if [ ! -f /etc/mbse-firewall/firewall.conf ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 echo "** /etc/mbse-firewall/firewall.conf not found, abort"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 exit 1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 . /etc/mbse-firewall/firewall.conf
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 # Some defaults, they are replaced when configured in
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 # /etc/mbse-firewall/firewall.conf
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 IF_EXT_AUTO_TO=${IF_EXT_AUTO_TO:=3600}
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 IF_EXT_AUTO_LIMIT=${IF_EXT_AUTO_LIMIT:=5/hour}
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 IF_EXT_AUTO_BURST=${IF_EXT_AUTO_BURST:=10}
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 # ---------------------------------------------------------------------------
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 #
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 # Functions
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 #
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 # ---------------------------------------------------------------------------
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 # Reset iptables back to Slackware default.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 reset_iptables() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 if [ -f /proc/net/ip_tables_names ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 cat /proc/net/ip_tables_names | while read table; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 $IPTABLES -t $table -L -n | while read c chain rest; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 if test "X$c" = "XChain" ; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 $IPTABLES -t $table -F $chain
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 $IPTABLES -t $table -X
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 $IPTABLES -P INPUT $1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 $IPTABLES -P OUTPUT $1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 $IPTABLES -P FORWARD $1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 echo "Reset iptables default policy $1" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 if [ "$USE_IPV6" == "1" ] && [ -f /proc/net/ip6_tables_names ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 cat /proc/net/ip6_tables_names | while read table; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 $IP6TABLES -t $table -L -n | while read c chain rest; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 if test "X$c" = "XChain" ; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 $IP6TABLES -t $table -F $chain
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 $IP6TABLES -t $table -X
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 $IP6TABLES -P OUTPUT $1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 $IP6TABLES -P INPUT $1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 $IP6TABLES -P FORWARD $1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 echo "Reset ip6tables default policy $1" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 # Remove any ipset tables.
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
121 HOST="$(hostname)"
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
122 SETS="$(${IPSET} list -n | grep ${HOST})"
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
123 for MySET in ${SETS}; do
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
124 $IPSET flush ${MySET}
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
125 $IPSET destroy ${MySET}
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
126 echo "Destroyed IPSET table ${MySET}" | $LOGGER
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
127 done
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 is_external_if4() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 [ "x${IF_EXT}" == "x$1" ] && return 1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 return 0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 is_external_if6() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 [ "x${IF_EXT6}" == "x$1" ] && return 1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 [ "x${IF_EXT}" == "x$1" -a -z "${IF_EXT6}" ] && return 1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 return 0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 reload_blocklist4() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 BLOCKLIST="/etc/mbse-firewall/conf.d/blocklist4.conf"
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
154 HOST="$(hostname)"
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
155
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 if [ -f $BLOCKLIST ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 echo "Reload $BLOCKLIST" | $LOGGER
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
158 $IPSET create ${HOST}-new-mbsefw-blk4ip hash:ip counters -exist
6
be2d7c142726 Fixed an error when reloading blocklists. Version 0.0.17
Michiel Broek <mbroek@mbse.eu>
parents: 5
diff changeset
159 $IPSET create ${HOST}-new-mbsefw-blk4net hash:net counters -exist
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 $GREP -Ev '^#|^;|^\s*$' $BLOCKLIST | while read L ; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 set $L
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 if echo $1 | $GREP -q "/" ; then
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
163 $IPSET add ${HOST}-new-mbsefw-blk4net $1 -exist
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 else
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
165 $IPSET add ${HOST}-new-mbsefw-blk4ip $1 -exist
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 done
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
168 $IPSET swap ${HOST}-mbsefw-blk4net ${HOST}-new-mbsefw-blk4net
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
169 $IPSET flush ${HOST}-new-mbsefw-blk4net
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
170 $IPSET destroy ${HOST}-new-mbsefw-blk4net
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
171 $IPSET swap ${HOST}-mbsefw-blk4ip ${HOST}-new-mbsefw-blk4ip
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
172 $IPSET flush ${HOST}-new-mbsefw-blk4ip
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
173 $IPSET destroy ${HOST}-new-mbsefw-blk4ip
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 reload_blocklist6() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 BLOCKLIST="/etc/mbse-firewall/conf.d/blocklist6.conf"
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
182 HOST="$(hostname)"
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
183
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 if [ -f $BLOCKLIST ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 echo "Reload $BLOCKLIST" | $LOGGER
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
186 $IPSET create ${HOST}-new-mbsefw-blk6 hash:net family inet6 counters -exist
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 $GREP -Ev '^#|^;|^\s*$' $BLOCKLIST | while read L ; do
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
188 set $L ; $IPSET add ${HOST}-new-mbsefw-blk6 $1 -exist
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 done
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
190 $IPSET swap ${HOST}-mbsefw-blk6 ${HOST}-new-mbsefw-blk6
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
191 $IPSET flush ${HOST}-new-mbsefw-blk6
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
192 $IPSET destroy ${HOST}-new-mbsefw-blk6
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197
2
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
198 fw_init_nfacct() {
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
199 NFACCTCONF="/etc/mbse-firewall/conf.d/nfacct.conf"
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
200 if [ -f $NFACCTCONF ]; then
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
201 echo "Init netfilter accounting" | $LOGGER
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
202 $GREP -Ev '^#|^;|^\s*$' $NFACCTCONF | while read L ; do
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
203 set $L
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
204 if [ -z "$($NFACCT list | $GREP $1)" ]; then
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
205 $NFACCT add $1
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
206 fi
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
207 done
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
208 fi
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
209 }
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
210
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
211
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
212
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 fw_init_sysctl() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 # If we have bridges and don't want iptables to work between
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 # the physical interfaces, turn it off.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 if [ "$FW_NO_BRIDGE_NF_CALL" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 $SYSCTL -e -q -w net.bridge.bridge-nf-call-arptables=0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 $SYSCTL -e -q -w net.bridge.bridge-nf-call-ip6tables=0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 $SYSCTL -e -q -w net.bridge.bridge-nf-call-iptables=0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 # No arp about internal interfaces across the border.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 if [ "$IF_EXT_IS_BORDER_GW" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 $SYSCTL -q -w net.ipv4.conf.${IF_EXT}.arp_ignore=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 $SYSCTL -q -w net.ipv4.conf.${IF_EXT}.arp_announce=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 fw_start_init() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 echo "Init new firewall" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 BLOCKLIST="/etc/mbse-firewall/conf.d/blocklist4.conf"
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
236 HOST="$(hostname)"
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
237
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 if [ -f $BLOCKLIST -a -n "$IF_EXT" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 echo " Install $BLOCKLIST" | $LOGGER
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
240 $IPSET create ${HOST}-mbsefw-blk4ip hash:ip counters -exist
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
241 $IPSET create ${HOST}-mbsefw-blk4net hash:net counters -exist
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
242 $IPTABLES -A INPUT -i $IF_EXT -m state --state NEW -m set --match-set ${HOST}-mbsefw-blk4ip src -j DROP
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
243 $IPTABLES -A INPUT -i $IF_EXT -m state --state NEW -m set --match-set ${HOST}-mbsefw-blk4net src -j DROP
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 if [ "$FW_FORWARD" = "1" ]; then
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
245 $IPTABLES -A FORWARD -i $IF_EXT -m state --state NEW -m set --match-set ${HOST}-mbsefw-blk4ip src -j DROP
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
246 $IPTABLES -A FORWARD -i $IF_EXT -m state --state NEW -m set --match-set ${HOST}-mbsefw-blk4net src -j DROP
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 $GREP -Ev '^#|^;|^\s*$' $BLOCKLIST | while read L ; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249 set $L
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 if echo $1 | $GREP -q "/" ; then
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
251 $IPSET add ${HOST}-mbsefw-blk4net $1 -exist
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 else
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
253 $IPSET add ${HOST}-mbsefw-blk4ip $1 -exist
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 BLOCKLIST="/etc/mbse-firewall/conf.d/blocklist6.conf"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 if [ -f $BLOCKLIST ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 echo " Install $BLOCKLIST" | $LOGGER
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
262 $IPSET create ${HOST}-mbsefw-blk6 hash:net family inet6 counters -exist
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263 if [ -n "$IF_EXT6" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264 IF6=$IF_EXT6
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 IF6=$IF_EXT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267 fi
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
268 $IP6TABLES -A INPUT -i $IF6 -m state --state NEW -m set --match-set ${HOST}-mbsefw-blk6 src -j DROP
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 if [ "$FW_FORWARD" = "1" ]; then
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
270 $IP6TABLES -A FORWARD -i $IF6 -m state --state NEW -m set --match-set ${HOST}-mbsefw-blk6 src -j DROP
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272 $GREP -Ev '^#|^;|^\s*$' $BLOCKLIST | while read L ; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 set $L
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
274 $IPSET add ${HOST}-mbsefw-blk6 $1 -exist
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278
7
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
279 # If we use the global blocktables.
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
280 if [ "$IF_EXT_GLOBAL_BLOCK" == "1" ]; then
12
8aaa305805df Make sure ipset tables exist.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
281 $IPSET create global-blk4 hash:ip counters -exist
8
c8e957eb1b36 Hosts blocked by the ipset global tables are now stateless blocked. Version 0.0.19.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
282 $IPTABLES -A INPUT -i $IF_EXT -m set --match-set global-blk4 src -j DROP
7
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
283 if [ "$FW_FORWARD" = "1" ]; then
8
c8e957eb1b36 Hosts blocked by the ipset global tables are now stateless blocked. Version 0.0.19.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
284 $IPTABLES -A FORWARD -i $IF_EXT -m set --match-set global-blk4 src -j DROP
7
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
285 fi
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
286 if [ "$USE_IPV6" == "1" ]; then
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
287 if [ -n "$IF_EXT6" ]; then
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
288 IF6=$IF_EXT6
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
289 else
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
290 IF6=$IF_EXT
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
291 fi
12
8aaa305805df Make sure ipset tables exist.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
292 $IPSET create global-blk6 hash:net family inet6 counters -exist
8
c8e957eb1b36 Hosts blocked by the ipset global tables are now stateless blocked. Version 0.0.19.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
293 $IP6TABLES -A INPUT -i $IF6 -m set --match-set global-blk6 src -j DROP
7
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
294 if [ "$FW_FORWARD" = "1" ]; then
8
c8e957eb1b36 Hosts blocked by the ipset global tables are now stateless blocked. Version 0.0.19.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
295 $IP6TABLES -A FORWARD -i $IF6 -m set --match-set global-blk6 src -j DROP
7
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
296 fi
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
297 fi
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
298 echo -n "."
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
299 fi
c846ebedfff3 Added global block ipset tables. Bumped to version 0.0.18
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
300
2
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
301 fw_init_nfacct
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
302 echo -n "."
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
303
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
304 # accept established and related connections
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
305 $IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 $IPTABLES -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307 [ "$FW_FORWARD" = "1" ] && $IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 $IP6TABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310 $IP6TABLES -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 [ "$FW_FORWARD" = "1" ] && $IP6TABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314 # drop packets that do not match any valid state. This also blocks invalid
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315 # flag combinations that are used by portscans.
13
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
316 $IPTABLES -A OUTPUT -m state --state INVALID -j DROP
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 $IPTABLES -A INPUT -m state --state INVALID -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 [ "$FW_FORWARD" = "1" ] && $IPTABLES -A FORWARD -m state --state INVALID -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320 $IP6TABLES -A OUTPUT -m state --state INVALID -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
321 $IP6TABLES -A INPUT -m state --state INVALID -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322 [ "$FW_FORWARD" = "1" ] && $IP6TABLES -A FORWARD -m state --state INVALID -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
323 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
324
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
325 # Allow everything on the loopback interface
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
326 $IPTABLES -A INPUT -i lo -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
327 $IPTABLES -A OUTPUT -o lo -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329 $IP6TABLES -A INPUT -i lo -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
330 $IP6TABLES -A OUTPUT -o lo -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
331 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333 # Anti spoofing on the external interface. Methods since the 3.3 kernel!
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334 if [ -n "$IF_EXT" ]; then
12
8aaa305805df Make sure ipset tables exist.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
335 # was 1, now 2 for IPTV.
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336 for f in $(ls /proc/sys/net/ipv4/conf/*/rp_filter); do
12
8aaa305805df Make sure ipset tables exist.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
337 echo 2 > $f
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
338 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339 $IPTABLES -A PREROUTING -t raw -i $IF_EXT -m rpfilter --invert -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341 if [ -n "$IF_EXT6" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342 $IP6TABLES -A PREROUTING -t raw -i $IF_EXT6 -m rpfilter --invert -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344 $IP6TABLES -A PREROUTING -t raw -i $IF_EXT -m rpfilter --invert -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347 # Manual anti spoofing on the interfaces is configured using the
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348 # interfaces configuration and only if the system is a router.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 # IPv4 ssh backdoor
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352 if [ -n "$IPV4_BACKDOOR_SSH" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353 $IPTABLES -A INPUT -p tcp -m tcp -s $IPV4_BACKDOOR_SSH --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 $IPTABLES -A OUTPUT -p tcp -m tcp -d $IPV4_BACKDOOR_SSH --sport 22 -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
355 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
356 # IPv6 ssh backdoor
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
357 if [ "$USE_IPV6" == "1" ] && [ -n "$IPV6_BACKDOOR_SSH" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
358 $IP6TABLES -A INPUT -p tcp -m tcp -s $IPV6_BACKDOOR_SSH --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
359 $IP6TABLES -A OUTPUT -p tcp -m tcp -d $IPV6_BACKDOOR_SSH --sport 22 -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
360 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
361
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
362 # Usefull ICMPv4
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
363 $IPTABLES -A INPUT -p icmp -m icmp --icmp-type 3 -m hashlimit --hashlimit 15/second --hashlimit-mode srcip --hashlimit-name icmp -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
364 $IPTABLES -A INPUT -p icmp -m icmp --icmp-type 0/0 -m hashlimit --hashlimit 15/second --hashlimit-mode srcip --hashlimit-name icmp -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
365 $IPTABLES -A INPUT -p icmp -m icmp --icmp-type 8/0 -m hashlimit --hashlimit 15/second --hashlimit-mode srcip --hashlimit-name icmp -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
366 $IPTABLES -A INPUT -p icmp -m icmp --icmp-type 11/0 -m hashlimit --hashlimit 15/second --hashlimit-mode srcip --hashlimit-name icmp -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
367 $IPTABLES -A INPUT -p icmp -m icmp --icmp-type 11/1 -m hashlimit --hashlimit 15/second --hashlimit-mode srcip --hashlimit-name icmp -j ACCEPT
9
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
368 $IPTABLES -A INPUT -p icmp -m limit --limit 10/minute -j "${FW_LOGDEST[@]}" "DENY=ICMPv4_INPUT "
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
369 $IPTABLES -A INPUT -p icmp -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
370 $IPTABLES -A OUTPUT -p icmp -m icmp --icmp-type 3 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
371 $IPTABLES -A OUTPUT -p icmp -m icmp --icmp-type 0/0 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
372 $IPTABLES -A OUTPUT -p icmp -m icmp --icmp-type 8/0 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
373 $IPTABLES -A OUTPUT -p icmp -m icmp --icmp-type 11/0 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
374 $IPTABLES -A OUTPUT -p icmp -m icmp --icmp-type 11/1 -j ACCEPT
9
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
375 $IPTABLES -A OUTPUT -p icmp -m limit --limit 10/minute -j "${FW_LOGDEST[@]}" "DENY=ICMPv4_OUTPUT "
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376 $IPTABLES -A OUTPUT -p icmp -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
377 if [ "$FW_FORWARD" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378 $IPTABLES -A FORWARD -p icmp -m icmp --icmp-type 3 -m hashlimit --hashlimit 15/second --hashlimit-mode srcip --hashlimit-name icmp -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
379 $IPTABLES -A FORWARD -p icmp -m icmp --icmp-type 0/0 -m hashlimit --hashlimit 15/second --hashlimit-mode srcip --hashlimit-name icmp -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
380 $IPTABLES -A FORWARD -p icmp -m icmp --icmp-type 8/0 -m hashlimit --hashlimit 15/second --hashlimit-mode srcip --hashlimit-name icmp -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381 $IPTABLES -A FORWARD -p icmp -m icmp --icmp-type 11/0 -m hashlimit --hashlimit 15/second --hashlimit-mode srcip --hashlimit-name icmp -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
382 $IPTABLES -A FORWARD -p icmp -m icmp --icmp-type 11/1 -m hashlimit --hashlimit 15/second --hashlimit-mode srcip --hashlimit-name icmp -j ACCEPT
9
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
383 $IPTABLES -A FORWARD -p icmp -m limit --limit 10/minute -j "${FW_LOGDEST[@]}" "DENY=ICMPv4_FORWARD "
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 $IPTABLES -A FORWARD -p icmp -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
385 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
386
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387 # If this system has enabled IPv6 ...
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
388 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
389 # ICMPv6
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type destination-unreachable -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
391 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type packet-too-big -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
392 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type time-exceeded -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
393 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type parameter-problem -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
394 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type destination-unreachable -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
395 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type packet-too-big -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
396 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type time-exceeded -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
397 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type parameter-problem -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
398 if [ "$FW_FORWARD" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 $IP6TABLES -A FORWARD -p ipv6-icmp -m icmp6 --icmpv6-type destination-unreachable -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
400 $IP6TABLES -A FORWARD -p ipv6-icmp -m icmp6 --icmpv6-type packet-too-big -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
401 $IP6TABLES -A FORWARD -p ipv6-icmp -m icmp6 --icmpv6-type time-exceeded -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
402 $IP6TABLES -A FORWARD -p ipv6-icmp -m icmp6 --icmpv6-type parameter-problem -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
403 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
404
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
405 # Rate limited icmpv6
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
406 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type echo-request -m limit --limit 15/second -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
407 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type echo-reply -m limit --limit 15/second -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type echo-request -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
409 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type echo-reply -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
410 if [ "$FW_FORWARD" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
411 $IP6TABLES -A FORWARD -p ipv6-icmp -m icmp6 --icmpv6-type echo-request -m limit --limit 15/second -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412 $IP6TABLES -A FORWARD -p ipv6-icmp -m icmp6 --icmpv6-type echo-reply -m limit --limit 15/second -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
414
10
798ac120a09e Added icmpv6 code 132. Version 0.0.22
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
415 if [ -n "$IF_EXT6" -a "$IF_EXT_IS_BORDER_GW" = "1" ]; then
798ac120a09e Added icmpv6 code 132. Version 0.0.22
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
416 $IP6TABLES -A INPUT -o $IF_EXT6 -p ipv6-icmp -d ff00::/8 -m icmp6 --icmpv6-type 132 -j DROP
798ac120a09e Added icmpv6 code 132. Version 0.0.22
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
417 $IP6TABLES -A OUTPUT -o $IF_EXT6 -p ipv6-icmp -d ff00::/8 -m icmp6 --icmpv6-type 132 -j DROP
798ac120a09e Added icmpv6 code 132. Version 0.0.22
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
418 elif [ -n "$IF_EXT" -a "$IF_EXT_IS_BORDER_GW" = "1" ]; then
798ac120a09e Added icmpv6 code 132. Version 0.0.22
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
419 $IP6TABLES -A INPUT -o $IF_EXT -p ipv6-icmp -d ff00::/8 -m icmp6 --icmpv6-type 132 -j DROP
798ac120a09e Added icmpv6 code 132. Version 0.0.22
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
420 $IP6TABLES -A OUTPUT -o $IF_EXT -p ipv6-icmp -d ff00::/8 -m icmp6 --icmpv6-type 132 -j DROP
798ac120a09e Added icmpv6 code 132. Version 0.0.22
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
421 fi
798ac120a09e Added icmpv6 code 132. Version 0.0.22
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
422 $IP6TABLES -A INPUT -p ipv6-icmp -d ff00::/8 -m icmp6 --icmpv6-type 132 -j ACCEPT
798ac120a09e Added icmpv6 code 132. Version 0.0.22
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
423 $IP6TABLES -A OUTPUT -p ipv6-icmp -d ff00::/8 -m icmp6 --icmpv6-type 132 -j ACCEPT
798ac120a09e Added icmpv6 code 132. Version 0.0.22
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
424
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
425 # rules to permit IPv6 Neighbor discovery
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
426 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type router-solicitation -m hl --hl-eq 255 -j ACCEPT
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
427 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type router-solicitation -j DROP # Silent drop HOPLIMIT <> 255
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
428 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type router-advertisement -m hl --hl-eq 255 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
429 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type neighbour-solicitation -m hl --hl-eq 255 -j ACCEPT
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
430 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type neighbour-solicitation -j DROP # Silent drop HOPLIMIT <> 255
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
431 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type neighbour-advertisement -m hl --hl-eq 255 -j ACCEPT
11
c5697bee6884 Version 0.0.23 drop ICMPv6 neighbour advertisement packets with hoplimit not 256
Michiel Broek <mbroek@mbse.eu>
parents: 10
diff changeset
432 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type neighbour-advertisement -j DROP # Silent drop HOPLIMIT <> 255
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
433 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type router-solicitation -m hl --hl-eq 255 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
434 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type router-advertisement -m hl --hl-eq 255 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
435 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type neighbour-solicitation -m hl --hl-eq 255 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
436 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type neighbour-advertisement -m hl --hl-eq 255 -j ACCEPT
5
2340826a516b Allow inverse neighbour discovery solicitation (141) / advertisement (142)
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
437 # Allow inverse neighbour discovery solicitation (141) / advertisement (142)
2340826a516b Allow inverse neighbour discovery solicitation (141) / advertisement (142)
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
438 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type 141 -m hl --hl-eq 255 -j ACCEPT
2340826a516b Allow inverse neighbour discovery solicitation (141) / advertisement (142)
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
439 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type 142 -m hl --hl-eq 255 -j ACCEPT
2340826a516b Allow inverse neighbour discovery solicitation (141) / advertisement (142)
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
440 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type 141 -m hl --hl-eq 255 -j ACCEPT
2340826a516b Allow inverse neighbour discovery solicitation (141) / advertisement (142)
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
441 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type 142 -m hl --hl-eq 255 -j ACCEPT
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
442
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
443 # MLD messages. DROP on external interface, but ACCEPT on others.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
444 if [ -n "$IF_EXT6" -a "$IF_EXT_IS_BORDER_GW" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
445 $IP6TABLES -A OUTPUT -o $IF_EXT6 -p ipv6-icmp -d ff00::/8 -m icmp6 --icmpv6-type 143 -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
446 elif [ -n "$IF_EXT" -a "$IF_EXT_IS_BORDER_GW" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
447 $IP6TABLES -A OUTPUT -o $IF_EXT -p ipv6-icmp -d ff00::/8 -m icmp6 --icmpv6-type 143 -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
448 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
449 $IP6TABLES -A OUTPUT -p ipv6-icmp -d ff00::/8 -m icmp6 --icmpv6-type 143 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
450
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
451 # Drop unmatched icmpv6 but log them so we can debug
9
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
452 $IP6TABLES -A INPUT -p ipv6-icmp -m limit --limit 10/minute -j "${FW_LOGDEST[@]}" "DENY=ICMPv6_INPUT "
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
453 $IP6TABLES -A INPUT -p ipv6-icmp -j DROP
9
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
454 $IP6TABLES -A OUTPUT -p ipv6-icmp -m limit --limit 10/minute -j "${FW_LOGDEST[@]}" "DENY=ICMPv6_OUTPUT "
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
455 $IP6TABLES -A OUTPUT -p ipv6-icmp -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
456 [ "$FW_FORWARD" = "1" ] && {
9
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
457 $IP6TABLES -A FORWARD -p ipv6-icmp -m limit --limit 10/minute -j "${FW_LOGDEST[@]}" "DENY=ICMPv6_FORWARD "
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
458 $IP6TABLES -A FORWARD -p ipv6-icmp -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
459 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
460 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
461
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
462 if [ "$CLAMP_MSS_TO_PMTU" = "1" ]; then
13
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
463 # ================ Tables 'filter' and 'mangle', automatic rules
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
464 [ "$FW_FORWARD" = "1" ] && {
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
465 $IPTABLES -t filter -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
466 $IPTABLES -t mangle -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
467 if [ "$USE_IPV6" == "1" ]; then
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
468 $IP6TABLES -t filter -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
469 $IP6TABLES -t mangle -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
470 fi
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
471 }
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
472 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
473
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
474 # Filter all packets that have RH0 header
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
475 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
476 # Filter all packets that have RH0 header
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
477 $IP6TABLES -A OUTPUT -m rt --rt-type 0 -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
478 $IP6TABLES -A INPUT -m rt --rt-type 0 -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
479 [ "$FW_FORWARD" = "1" ] && $IP6TABLES -A FORWARD -m rt --rt-type 0 -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
480
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
481 # Allow Link-Local sddresses
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482 $IP6TABLES -A INPUT -s fe80::/10 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
483 $IP6TABLES -A OUTPUT -s fe80::/10 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
484
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
485 # Allow Multicast
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
486 $IP6TABLES -A INPUT -d ff00::/8 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
487 $IP6TABLES -A OUTPUT -d ff00::/8 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
488 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
489
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
490 # Traceroute
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
491 if [ "$FW_TRACEROUTE" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
492 $IPTABLES -A OUTPUT -p udp -m udp --dport 33434:33524 -m state --state NEW -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
493 $IPTABLES -A INPUT -p udp -m udp --dport 33434:33524 -m state --state NEW -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
494 [ "$FW_FORWARD" = "1" ] && $IPTABLES -A FORWARD -p udp -m udp --dport 33434:33524 -m state --state NEW -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
495 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
496 $IP6TABLES -A OUTPUT -p udp -m udp --dport 33434:33524 -m state --state NEW -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
497 $IP6TABLES -A INPUT -p udp -m udp --dport 33434:33524 -m state --state NEW -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
498 [ "$FW_FORWARD" = "1" ] && $IP6TABLES -A FORWARD -p udp -m udp --dport 33434:33524 -m state --state NEW -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
499 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
500 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
501
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
502 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
503 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
504
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
505
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
506
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
507 fw_start_interface_chain()
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
508 {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
509 local multi iodir IFS=\;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
510
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
511 INTF=$1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
512 FCHAIN=$2
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
513 NCHAIN=$3
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
514 SCHAIN=$4
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
515 CONFFILE="/etc/mbse-firewall/conf.d/${INTF}-${FCHAIN}.conf"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
516 is_external_if4 $1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
517 EXTERN4=$?
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
518 is_external_if6 $1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
519 EXTERN6=$?
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
520
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
521 HOST="$(hostname)"
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
522
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
523 # TODO: use subchains, but we need to do 2 passes on the config
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
524 # files to make it work.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
525
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
526 # Are there rules for this chain?
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
527 if [ -f $CONFFILE ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
528 echo " Start chain ${NCHAIN} on interface ${INTF} is external ipv4: ${EXTERN4} ipv6: ${EXTERN6}" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
529
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
530 # Install auto blacklisting if set for this interface and this is the
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
531 # INPUT or FORWARD chain. In /etc/mbse-firewall/firewall.conf set then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
532 # IF_EXT_AUTO_TO value for the block timeout. Default is 3600 seconds.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
533 # See the end of this function for the actual test.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
534 if [ "$NCHAIN" = "INPUT" -o "$NCHAIN" = "FORWARD" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
535 if [ "$IF_EXT_AUTO_BLOCK" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
536 if [ "$EXTERN4" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
537 echo " Installing IPv4 auto blacklisting on interface ${INTF}" | $LOGGER
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
538 $IPSET create ${HOST}-mbsefw-auto4 hash:ip timeout $IF_EXT_AUTO_TO counters -exist
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
539 $IPTABLES -I $NCHAIN -m set --match-set ${HOST}-mbsefw-auto4 src -j DROP
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
540 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
541 if [ "$EXTERN6" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
542 echo " Installing IPv6 auto blacklisting on interface ${INTF}" | $LOGGER
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
543 $IPSET create ${HOST}-mbsefw-auto6 hash:ip family inet6 timeout $IF_EXT_AUTO_TO counters -exist
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
544 $IP6TABLES -I $NCHAIN -m set --match-set ${HOST}-mbsefw-auto6 src -j DROP
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
545 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
546 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
547 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
548
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
549 # Adjust for the direction of the chain
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
550 if [ "$NCHAIN" = "OUTPUT" -o "$NCHAIN" = "POSTROUTING" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
551 iodir="-o"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
552 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
553 iodir="-i"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
554 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
555
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
556 # Read the configuration
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
557 $GREP -Ev '^#|^\s*$' $CONFFILE | while read L ; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
558 set $L
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
559 # Build command
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
560 if [ "$1" = "6" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
561 CMD=$IP6TABLES
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
562 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
563 CMD=$IPTABLES
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
564 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
565
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
566 if [ -n "$2" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
567 args=("-t" "$2" "-A" "$NCHAIN" "$iodir" "${INTF}")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
568 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
569 args=("-A" "$NCHAIN" "$iodir" "${INTF}")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
570 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
571
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
572 # Protocol
14
654773d80b70 Version 0.0.27 Fix for igmp protocol, do not use -m option.
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
573 [ -n "$3" ] && {
654773d80b70 Version 0.0.27 Fix for igmp protocol, do not use -m option.
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
574 if [ "$3" = "igmp" ]; then
654773d80b70 Version 0.0.27 Fix for igmp protocol, do not use -m option.
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
575 args+=("-p" "$3")
654773d80b70 Version 0.0.27 Fix for igmp protocol, do not use -m option.
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
576 else
654773d80b70 Version 0.0.27 Fix for igmp protocol, do not use -m option.
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
577 args+=("-p" "$3" "-m" "$3")
654773d80b70 Version 0.0.27 Fix for igmp protocol, do not use -m option.
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
578 fi
654773d80b70 Version 0.0.27 Fix for igmp protocol, do not use -m option.
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
579 }
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
580
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
581 # Test for multiport
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
582 multi=0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
583 [ -n "$5$7" ] && {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
584 [[ $5$7 == *","* ]] && multi=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
585 [[ $5$7 == *":"* ]] && multi=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
586 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
587 [ "$multi" = "1" ] && args+=("-m" "multiport")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
588
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
589 # Source address
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
590 [ -n "$4" ] && args+=("-s" "$4")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
591
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
592 # Source port(s)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
593 [ -n "$5" ] && {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
594 multi=0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
595 [[ $5 == *","* ]] && multi=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
596 [[ $5 == *":"* ]] && multi=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
597 if [ "$multi" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
598 args+=("--sports" "$5")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
599 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
600 args+=("--sport" "$5")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
601 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
602 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
603
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
604 # Destination address
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
605 [ -n "$6" ] && args+=("-d" "$6")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
606
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
607 # Destination port(s)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
608 [ -n "$7" ] && {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
609 multi=0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
610 [[ $7 == *","* ]] && multi=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
611 [[ $7 == *":"* ]] && multi=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
612 if [ "$multi" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
613 args+=("--dports" "$7")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
614 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
615 args+=("--dport" "$7")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
616 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
617 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
618
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
619 # Rule options
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
620 [ -n "$9" ] && {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
621 IFS=' '
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
622 for arg in $9; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
623 args+=("$arg")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
624 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
625 IFS=\;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
626 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
627
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
628 # Rule action
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
629 [ -n "$8" ] && {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
630 IFS=' '
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
631 args+=("-j")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
632 for arg in $8; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
633 args+=("$arg")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
634 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
635 IFS=\;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
636 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
637
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
638 $CMD "${args[@]}"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
639 rc=$?
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
640 echo " " $CMD "${args[@]}" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
641 if [ $rc -ne 0 ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
642 echo "Error in $CONFFILE" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
643 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
644 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
645
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
646 # In PREROUTING or POSTROUTING chains we are done here.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
647 if [ "$NCHAIN" = "PREROUTING" -o "$NCHAIN" = "POSTROUTING" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
648 return
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
649 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
650
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
651 # Ignore timing problems with old connections
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
652 $IPTABLES -A $NCHAIN $iodir ${INTF} -p tcp -m tcp --tcp-flags ACK,PSH ACK,PSH -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
653 [ "$USE_IPV6" = "1" ] && $IP6TABLES -A $NCHAIN $iodir ${INTF} -p tcp -m tcp --tcp-flags ACK,PSH ACK,PSH -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
654
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
655 # Install the final autoblock rule if this is the INPUT or FORWARD chain.
3
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
656 # We allow upto 5 probes per minute or a burst of 10 probes. This should be
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
657 # a good balance to catch the real bad guys. Note that until the IP is
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
658 # blocked these systems are logged using the rule below this one.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
659 if [ "$IF_EXT_AUTO_BLOCK" = "1" -a "$NCHAIN" != "OUTPUT" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
660 if [ "${EXTERN4}" = "1" ]; then
3
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
661 # First, ignore these. Can happen after a temporary network problem.
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
662 $IPTABLES -A $NCHAIN $iodir ${INTF} -p tcp -m tcp --tcp-flags ALL ACK -j DROP
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
663 # Now the real rule.
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
664 $IPTABLES -A $NCHAIN $iodir ${INTF} \
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
665 -m hashlimit --hashlimit-above ${IF_EXT_AUTO_LIMIT} --hashlimit-burst ${IF_EXT_AUTO_BURST} --hashlimit-mode srcip --hashlimit-name hash-auto4 \
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
666 -j SET --add-set ${HOST}-mbsefw-auto4 src
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
667 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
668 if [ "${EXTERN6}" = "1" ]; then
3
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
669 # First, ignore these. Can happen after a temporary network problem.
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
670 $IP6TABLES -A $NCHAIN $iodir ${INTF} -p tcp -m tcp --tcp-flags ALL ACK -j DROP
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
671 # Now the real rule.
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
672 $IP6TABLES -A $NCHAIN $iodir ${INTF} \
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
673 -m hashlimit --hashlimit-above ${IF_EXT_AUTO_LIMIT} --hashlimit-burst ${IF_EXT_AUTO_BURST} --hashlimit-mode srcip --hashlimit-name hash-auto6 \
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
674 -j SET --add-set ${HOST}-mbsefw-auto6 src
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
675 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
676 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
677 # deny and log the rest
9
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
678 $IPTABLES -A $NCHAIN $iodir ${INTF} -m limit --limit 10/minute -j "${FW_LOGDEST[@]}" "DENY=$NCHAIN "
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
679 [ "$USE_IPV6" == "1" ] && $IP6TABLES -A $NCHAIN $iodir ${INTF} -m limit --limit 10/minute -j "${FW_LOGDEST[@]}" "DENY=$NCHAIN "
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
680 $IPTABLES -A $NCHAIN $iodir ${INTF} -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
681 [ "$USE_IPV6" == "1" ] && $IP6TABLES -A $NCHAIN $iodir ${INTF} -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
682 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
683 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
684 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
685
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
686
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
687
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
688 fw_start_interface()
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
689 {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
690 fw_start_interface_chain $1 "prerouting" "PREROUTING" "pre"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
691 fw_start_interface_chain $1 "input" "INPUT" "in"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
692 fw_start_interface_chain $1 "output" "OUTPUT" "out"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
693 fw_start_interface_chain $1 "forward" "FORWARD" "fwd"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
694 fw_start_interface_chain $1 "postrouting" "POSTROUTING" "post"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
695 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
696
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
697
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
698
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
699 fw_start_main() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
700 i=0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
701
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
702 [ -n "$IF_EXT" ] && fw_start_interface "$IF_EXT"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
703 [ -n "$IF_EXT6" ] && fw_start_interface "$IF_EXT6"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
704
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
705 while [ $i -lt 50 ];
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
706 do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
707 [ -z "${IF_TRUNK[$i]}" ] && break
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
708 fw_start_interface "${IF_TRUNK[$i]}"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
709 i=$(($i+1))
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
710 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
711 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
712
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
713
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
714
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
715 fw_start_final() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
716 # Deny and log everything else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
717 $IPTABLES -N FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
718 $IPTABLES -A OUTPUT -j FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
719 $IPTABLES -A INPUT -j FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
720 [ "$FW_FORWARD" = "1" ] && $IPTABLES -A FORWARD -j FINAL_RULE
9
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
721 $IPTABLES -A FINAL_RULE -m limit --limit 10/minute -j "${FW_LOGDEST[@]}" "DENY=999 "
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
722 $IPTABLES -A FINAL_RULE -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
723 if [ "$USE_IPV6" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
724 $IP6TABLES -N FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
725 $IP6TABLES -A OUTPUT -j FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
726 $IP6TABLES -A INPUT -j FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
727 [ "$FW_FORWARD" = "1" ] && $IP6TABLES -A FORWARD -j FINAL_RULE
9
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
728 $IP6TABLES -A FINAL_RULE -m limit --limit 10/minute -j "${FW_LOGDEST[@]}" "DENY=999 "
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
729 $IP6TABLES -A FINAL_RULE -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
730 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
731 echo "Firewall installed" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
732 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
733
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
734
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
735
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
736 fw_install() {
13
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
737 echo "Installing $(basename $0) $MBSEFW_VERSION" | $LOGGER
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
738 echo -n "Installing $(basename $0) $MBSEFW_VERSION: "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
739 reset_iptables DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
740 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
741 fw_init_sysctl
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
742 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
743 fw_start_init
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
744 fw_start_main
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
745 fw_start_final
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
746 echo " done."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
747 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
748
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
749
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
750
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
751 fw_start() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
752 if [ -f /etc/mbse-firewall/data/firewall-ipv4.data -a \
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
753 -f /etc/mbse-firewall/data/firewall-ipv6.data -a \
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
754 -f /etc/mbse-firewall/data/firewall-ipset.data ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
755 # Do a full restore of all saved data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
756 echo -n "Starting $(basename $0) $MBSEFW_VERSION: "
13
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
757 echo "Starting $(basename $0) $MBSEFW_VERSION" | $LOGGER
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
758 echo "Start new firewall" | $LOGGER
2
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
759 fw_init_nfacct
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
760 reset_iptables DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
761 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
762 fw_init_sysctl
12
8aaa305805df Make sure ipset tables exist.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
763 $IPSET restore -exist < /etc/mbse-firewall/data/firewall-ipset.data
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
764 echo " Restored /etc/mbse-firewall/data/firewall-ipset.data" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
765 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
766 $IPTABLES_RESTORE < /etc/mbse-firewall/data/firewall-ipv4.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
767 echo " Restored /etc/mbse-firewall/data/firewall-ipv4.data" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
768 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
769 $IP6TABLES_RESTORE < /etc/mbse-firewall/data/firewall-ipv6.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
770 echo " Restored /etc/mbse-firewall/data/firewall-ipv6.data" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
771 echo " done."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
772 echo -n "New firewall active" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
773 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
774 # If there is no saved firewall, install a new one and save it.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
775 fw_install
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
776 fw_save
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
777 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
778 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
779
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
780
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
781
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
782 fw_stop() {
13
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
783 echo "Stopping $(basename $0) $MBSEFW_VERSION" | $LOGGER
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
784 echo -n "Stopping $(basename $0) $MBSEFW_VERSION: "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
785 # Slackware defaults to ACCEPT when no firewall is active.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
786 reset_iptables ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
787 echo "done."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
788 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
789
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
790
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
791
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
792 # If there are blocklist tables, reload them.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
793 fw_reload() {
13
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
794 echo "Reload $(basename $0) $MBSEFW_VERSION" | $LOGGER
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
795 echo -n "Reload $(basename $0) $MBSEFW_VERSION: "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
796 reload_blocklist4
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
797 reload_blocklist6
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
798 echo done.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
799 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
800
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
801
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
802
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
803 fw_save() {
13
06b03eeae540 Version 0.0.26 Add TCPMSS also to the filter table. Log script invocation.
Michiel Broek <mbroek@mbse.eu>
parents: 12
diff changeset
804 echo "Saving $(basename $0) $MBSEFW_VERSION" | $LOGGER
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
805 echo -n "Saving $(basename $0) $MBSEFW_VERSION: "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
806 mkdir -p /etc/mbse-firewall/data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
807 [ -n "$IPTABLES_SAVE" ] && $IPTABLES_SAVE > /etc/mbse-firewall/data/firewall-ipv4.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
808 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
809 [ -n "$IP6TABLES_SAVE" ] && $IP6TABLES_SAVE > /etc/mbse-firewall/data/firewall-ipv6.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
810 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
811
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
812 rm -f /etc/mbse-firewall/data/firewall-ipset.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
813 touch /etc/mbse-firewall/data/firewall-ipset.data
12
8aaa305805df Make sure ipset tables exist.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
814 if [ "$IF_EXT_GLOBAL_BLOCK" == "1" ]; then
8aaa305805df Make sure ipset tables exist.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
815 $IPSET save global-blk4 -t >> /etc/mbse-firewall/data/firewall-ipset.data
8aaa305805df Make sure ipset tables exist.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
816 if [ "$USE_IPV6" == "1" ]; then
8aaa305805df Make sure ipset tables exist.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
817 $IPSET save global-blk6 -t >> /etc/mbse-firewall/data/firewall-ipset.data
8aaa305805df Make sure ipset tables exist.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
818 fi
8aaa305805df Make sure ipset tables exist.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
819 fi
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
820 HOST="$(hostname)"
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
821 SETS="$($IPSET list -n | grep ${HOST})"
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
822 for set in $SETS ; do
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
823 if [ "$set" = "${HOST}-mbsefw-auto4" -o "$set" = "${HOST}-mbsefw-auto6" ]; then
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
824 # Only save structure for auto blocklists
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
825 $IPSET save $set -t >> /etc/mbse-firewall/data/firewall-ipset.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
826 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
827 $IPSET save $set >> /etc/mbse-firewall/data/firewall-ipset.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
828 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
829 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
830 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
831 echo " done."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
832 echo "Save firewall done in /etc/mbse-firewall/data" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
833 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
834
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
835
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
836
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
837 fw_status() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
838
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
839 echo -n "$(basename $0) $MBSEFW_VERSION"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
840
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
841 IP_MODULES=$($LSMOD | $AWK '{print $1}' | $GREP '^ip')
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
842 if [ "${IP_MODULES}x" = "x" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
843 echo " - You do not have any iptables loaded."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
844 return
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
845 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
846 echo " - You have the following ip modules loaded:"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
847 echo -n " "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
848 echo ${IP_MODULES}
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
849 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
850
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
851 if [ ! -z "$( echo $IP_MODULES | $GREP iptable_filter )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
852 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
853 echo ' FILTER TABLE IPv4'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
854 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
855 $IPTABLES -t filter -L -n -v --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
856 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
857
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
858 if [ ! -z "$( echo $IP_MODULES | $GREP ip6table_filter )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
859 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
860 echo ' FILTER TABLE IPv6'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
861 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
862 $IP6TABLES -t filter -L -n -v --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
863 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
864
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
865 if [ ! -z "$( echo $IP_MODULES | $GREP iptable_nat )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
866 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
867 echo ' NAT TABLE IPv4'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
868 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
869 $IPTABLES -t nat -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
870 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
871
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
872 if [ ! -z "$( echo $IP_MODULES | $GREP ip6table_nat )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
873 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
874 echo ' NAT TABLE IPv6'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
875 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
876 $IP6TABLES -t nat -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
877 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
878
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
879 if [ ! -z "$( echo $IP_MODULES | $GREP iptable_raw )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
880 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
881 echo ' RAW TABLE IPv4'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
882 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
883 $IPTABLES -t raw -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
884 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
885
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
886 if [ ! -z "$( echo $IP_MODULES | $GREP ip6table_raw )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
887 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
888 echo ' RAW TABLE IPv6'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
889 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
890 $IP6TABLES -t raw -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
891 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
892
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
893 if [ ! -z "$( echo $IP_MODULES | $GREP iptable_mangle )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
894 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
895 echo ' MANGLE TABLE IPv4'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
896 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
897 $IPTABLES -t mangle -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
898 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
899
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
900 if [ ! -z "$( echo $IP_MODULES | $GREP ip6table_mangle )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
901 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
902 echo ' MANGLE TABLE IPv6'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
903 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
904 $IP6TABLES -t mangle -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
905 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
906
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
907 if [ ! -z "$( echo $IP_MODULES | $GREP iptable_security )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
908 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
909 echo ' SECURITY TABLE IPv4'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
910 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
911 $IPTABLES -t security -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
912 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
913
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
914 if [ ! -z "$( echo $IP_MODULES | $GREP ip6table_security )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
915 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
916 echo ' SECURITY TABLE IPv6'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
917 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
918 $IP6TABLES -t security -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
919 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
920
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
921 HOST="$(hostname)"
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
922 if [ -n "$IPSET" ] && [ ! -z "$($IPSET list -n | grep ${HOST})" ]; then
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
923 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
924 echo ' IPSET listing'
4
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
925 SETS="$(${IPSET} list -n | grep ${HOST})"
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
926 for MySET in ${SETS}; do
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
927 echo
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
928 ${IPSET} list ${MySET}
92045b0e8e17 ipset now adds the hostname to the blocklists so that the firewall scripts works on hosts and Linux Container clients without conflicts. The ipset tables are visible on the host and in the lxc clients. Then, silently drop icmpv6 router sollicitaion and neighbour sollicitation messages that come in with the hoplimit field not set to 255. Some Windows systems do this. Version 0.0.16
Michiel Broek <mbroek@mbse.eu>
parents: 3
diff changeset
929 done
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
930 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
931 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
932
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
933
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
934
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
935 # ---------------------------------------------------------------------------
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
936 #
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
937 # MAIN program part
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
938 #
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
939 # ---------------------------------------------------------------------------
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
940
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
941
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
942 # See how we were called
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
943 cmd=$1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
944
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
945 case "$cmd" in
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
946 start)
9
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
947 [ -x /etc/rc.d/rc.ulogd ] && /etc/rc.d/rc.ulogd start
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
948 fw_start
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
949 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
950
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
951 stop)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
952 fw_stop
9
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
953 [ -x /etc/rc.d/rc.ulogd ] && /etc/rc.d/rc.ulogd stop
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
954 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
955
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
956 restart)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
957 fw_stop
9
2e298d35241f Added options to log to syslog or nflog.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
958 [ -x /etc/rc.d/rc.ulogd ] && /etc/rc.d/rc.ulogd restart
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
959 fw_start
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
960 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
961
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
962 save)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
963 fw_save
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
964 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
965 install)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
966 fw_install
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
967 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
968 reload)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
969 fw_reload
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
970 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
971 status)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
972 fw_status
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
973 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
974
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
975 *)
3
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
976 echo "Usage $0 [start|stop|restart|save|install|reload|status]"
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
977 echo
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
978 echo "start start a saved firewall"
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
979 echo "stop stop firewall and set default ACCEPT state"
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
980 echo "restart stop and start the firewall"
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
981 echo "save save current installed firewall rules"
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
982 echo "install install new firewall from configuration"
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
983 echo "reload reload the blocklists"
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
984 echo "status show the firewall rules and counters"
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
985 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
986 esac
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
987
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
988

mercurial