sbin/mbse-firewall

Thu, 18 Dec 2014 16:56:55 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 18 Dec 2014 16:56:55 +0100
changeset 4
92045b0e8e17
parent 3
6b45cf9df8cf
child 5
2340826a516b
permissions
-rwxr-xr-x

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

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 # ---------------------------------------------------------------------------
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 # Copyright (C) 2013-2014 by Michiel Broek.
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
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
25 MBSEFW_VERSION="0.0.16"
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
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
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
2
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
279 fw_init_nfacct
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
280 echo -n "."
7c794ae9f4de Added support for nfacct objects. Version 0.0.13
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
281
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 # accept established and related connections
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 $IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 $IPTABLES -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 [ "$FW_FORWARD" = "1" ] && $IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 $IP6TABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288 $IP6TABLES -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 [ "$FW_FORWARD" = "1" ] && $IP6TABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 # drop packets that do not match any valid state. This also blocks invalid
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293 # flag combinations that are used by portscans.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 $IPTABLES -A OUTPUT -m state --state INVALID -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295 $IPTABLES -A INPUT -m state --state INVALID -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 [ "$FW_FORWARD" = "1" ] && $IPTABLES -A FORWARD -m state --state INVALID -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 $IP6TABLES -A OUTPUT -m state --state INVALID -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299 $IP6TABLES -A INPUT -m state --state INVALID -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300 [ "$FW_FORWARD" = "1" ] && $IP6TABLES -A FORWARD -m state --state INVALID -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
302
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
303 # Allow everything on the loopback interface
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
304 $IPTABLES -A INPUT -i lo -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
305 $IPTABLES -A OUTPUT -o lo -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307 $IP6TABLES -A INPUT -i lo -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 $IP6TABLES -A OUTPUT -o lo -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 # Anti spoofing on the external interface. Methods since the 3.3 kernel!
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312 if [ -n "$IF_EXT" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313 for f in $(ls /proc/sys/net/ipv4/conf/*/rp_filter); do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314 echo 1 > $f
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316 $IPTABLES -A PREROUTING -t raw -i $IF_EXT -m rpfilter --invert -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 if [ -n "$IF_EXT6" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319 $IP6TABLES -A PREROUTING -t raw -i $IF_EXT6 -m rpfilter --invert -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
321 $IP6TABLES -A PREROUTING -t raw -i $IF_EXT -m rpfilter --invert -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322 fi
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 # Manual anti spoofing on the interfaces is configured using the
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
325 # interfaces configuration and only if the system is a router.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
326 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
327
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328 # IPv4 ssh backdoor
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329 if [ -n "$IPV4_BACKDOOR_SSH" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
330 $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
331 $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
332 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333 # IPv6 ssh backdoor
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334 if [ "$USE_IPV6" == "1" ] && [ -n "$IPV6_BACKDOOR_SSH" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335 $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
336 $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
337 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
338
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339 # Usefull ICMPv4
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340 $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
341 $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
342 $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
343 $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
344 $IPTABLES -A INPUT -p icmp -m icmp --icmp-type 11/1 -m hashlimit --hashlimit 15/second --hashlimit-mode srcip --hashlimit-name icmp -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 $IPTABLES -A INPUT -p icmp -m limit --limit 10/minute -j LOG --log-level info --log-prefix "DENY=ICMPv4_INPUT "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346 $IPTABLES -A INPUT -p icmp -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347 $IPTABLES -A OUTPUT -p icmp -m icmp --icmp-type 3 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348 $IPTABLES -A OUTPUT -p icmp -m icmp --icmp-type 0/0 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349 $IPTABLES -A OUTPUT -p icmp -m icmp --icmp-type 8/0 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 $IPTABLES -A OUTPUT -p icmp -m icmp --icmp-type 11/0 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 $IPTABLES -A OUTPUT -p icmp -m icmp --icmp-type 11/1 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352 $IPTABLES -A OUTPUT -p icmp -m limit --limit 10/minute -j LOG --log-level info --log-prefix "DENY=ICMPv4_OUTPUT "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353 $IPTABLES -A OUTPUT -p icmp -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 if [ "$FW_FORWARD" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
355 $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
356 $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
357 $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
358 $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
359 $IPTABLES -A FORWARD -p icmp -m icmp --icmp-type 11/1 -m hashlimit --hashlimit 15/second --hashlimit-mode srcip --hashlimit-name icmp -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
360 $IPTABLES -A FORWARD -p icmp -m limit --limit 10/minute -j LOG --log-level info --log-prefix "DENY=ICMPv4_FORWARD "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
361 $IPTABLES -A FORWARD -p icmp -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
362 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
363
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
364 # If this system has enabled IPv6 ...
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
365 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
366 # ICMPv6
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
367 $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
368 $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
369 $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
370 $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
371 $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
372 $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
373 $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
374 $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
375 if [ "$FW_FORWARD" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376 $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
377 $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
378 $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
379 $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
380 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
382 # Rate limited icmpv6
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
383 $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
384 $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
385 $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
386 $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
387 if [ "$FW_FORWARD" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
388 $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
389 $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
390 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
391
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
392 # rules to permit IPv6 Neighbor discovery
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
393 $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
394 $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
395 $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
396 $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
397 $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
398 $IP6TABLES -A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type neighbour-advertisement -m hl --hl-eq 255 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 $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
400 $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
401 $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
402 $IP6TABLES -A OUTPUT -p ipv6-icmp -m icmp6 --icmpv6-type neighbour-advertisement -m hl --hl-eq 255 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
403
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
404 # MLD messages. DROP on external interface, but ACCEPT on others.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
405 if [ -n "$IF_EXT6" -a "$IF_EXT_IS_BORDER_GW" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
406 $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
407 elif [ -n "$IF_EXT" -a "$IF_EXT_IS_BORDER_GW" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408 $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
409 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
410 $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
411
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412 # Drop unmatched icmpv6 but log them so we can debug
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413 $IP6TABLES -A INPUT -p ipv6-icmp -m limit --limit 10/minute -j LOG --log-level info --log-prefix "DENY=ICMPv6_INPUT "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
414 $IP6TABLES -A INPUT -p ipv6-icmp -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
415 $IP6TABLES -A OUTPUT -p ipv6-icmp -m limit --limit 10/minute -j LOG --log-level info --log-prefix "DENY=ICMPv6_OUTPUT "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
416 $IP6TABLES -A OUTPUT -p ipv6-icmp -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
417 [ "$FW_FORWARD" = "1" ] && {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
418 $IP6TABLES -A FORWARD -p ipv6-icmp -m limit --limit 10/minute -j LOG --log-level info --log-prefix "DENY=ICMPv6_FORWARD "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
419 $IP6TABLES -A FORWARD -p ipv6-icmp -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
420 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
421 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
422
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
423 if [ "$CLAMP_MSS_TO_PMTU" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
424 # ================ Table 'mangle', automatic rules
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
425 [ "$FW_FORWARD" = "1" ] && $IPTABLES -t mangle -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
426 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
427 [ "$FW_FORWARD" = "1" ] && $IP6TABLES -t mangle -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
428 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
429 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
430
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
431 # Filter all packets that have RH0 header
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
432 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
433 # Filter all packets that have RH0 header
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
434 $IP6TABLES -A OUTPUT -m rt --rt-type 0 -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
435 $IP6TABLES -A INPUT -m rt --rt-type 0 -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
436 [ "$FW_FORWARD" = "1" ] && $IP6TABLES -A FORWARD -m rt --rt-type 0 -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
437
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
438 # Allow Link-Local sddresses
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
439 $IP6TABLES -A INPUT -s fe80::/10 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
440 $IP6TABLES -A OUTPUT -s fe80::/10 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
441
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
442 # Allow Multicast
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
443 $IP6TABLES -A INPUT -d ff00::/8 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
444 $IP6TABLES -A OUTPUT -d ff00::/8 -j ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
445 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
446
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
447 # Traceroute
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
448 if [ "$FW_TRACEROUTE" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
449 $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
450 $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
451 [ "$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
452 if [ "$USE_IPV6" == "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
453 $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
454 $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
455 [ "$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
456 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
457 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
458
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
459 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
460 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
461
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
462
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
463
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
464 fw_start_interface_chain()
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
465 {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
466 local multi iodir IFS=\;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
467
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
468 INTF=$1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
469 FCHAIN=$2
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
470 NCHAIN=$3
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
471 SCHAIN=$4
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
472 CONFFILE="/etc/mbse-firewall/conf.d/${INTF}-${FCHAIN}.conf"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
473 is_external_if4 $1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
474 EXTERN4=$?
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
475 is_external_if6 $1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
476 EXTERN6=$?
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
477
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
478 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
479
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
480 # TODO: use subchains, but we need to do 2 passes on the config
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
481 # files to make it work.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
483 # Are there rules for this chain?
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
484 if [ -f $CONFFILE ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
485 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
486
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
487 # Install auto blacklisting if set for this interface and this is the
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
488 # INPUT or FORWARD chain. In /etc/mbse-firewall/firewall.conf set then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
489 # IF_EXT_AUTO_TO value for the block timeout. Default is 3600 seconds.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
490 # See the end of this function for the actual test.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
491 if [ "$NCHAIN" = "INPUT" -o "$NCHAIN" = "FORWARD" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
492 if [ "$IF_EXT_AUTO_BLOCK" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
493 if [ "$EXTERN4" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
494 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
495 $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
496 $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
497 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
498 if [ "$EXTERN6" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
499 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
500 $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
501 $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
502 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
503 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
504 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
505
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
506 # Adjust for the direction of the chain
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
507 if [ "$NCHAIN" = "OUTPUT" -o "$NCHAIN" = "POSTROUTING" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
508 iodir="-o"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
509 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
510 iodir="-i"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
511 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
512
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
513 # Read the configuration
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
514 $GREP -Ev '^#|^\s*$' $CONFFILE | while read L ; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
515 set $L
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
516 # Build command
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
517 if [ "$1" = "6" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
518 CMD=$IP6TABLES
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
519 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
520 CMD=$IPTABLES
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
521 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
522
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
523 if [ -n "$2" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
524 args=("-t" "$2" "-A" "$NCHAIN" "$iodir" "${INTF}")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
525 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
526 args=("-A" "$NCHAIN" "$iodir" "${INTF}")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
527 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
528
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
529 # Protocol
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
530 [ -n "$3" ] && args+=("-p" "$3" "-m" "$3")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
531
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
532 # Test for multiport
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
533 multi=0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
534 [ -n "$5$7" ] && {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
535 [[ $5$7 == *","* ]] && multi=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
536 [[ $5$7 == *":"* ]] && multi=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
537 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
538 [ "$multi" = "1" ] && args+=("-m" "multiport")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
539
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
540 # Source address
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
541 [ -n "$4" ] && args+=("-s" "$4")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
542
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
543 # Source port(s)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
544 [ -n "$5" ] && {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
545 multi=0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
546 [[ $5 == *","* ]] && multi=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
547 [[ $5 == *":"* ]] && multi=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
548 if [ "$multi" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
549 args+=("--sports" "$5")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
550 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
551 args+=("--sport" "$5")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
552 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
553 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
554
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
555 # Destination address
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
556 [ -n "$6" ] && args+=("-d" "$6")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
557
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
558 # Destination port(s)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
559 [ -n "$7" ] && {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
560 multi=0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
561 [[ $7 == *","* ]] && multi=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
562 [[ $7 == *":"* ]] && multi=1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
563 if [ "$multi" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
564 args+=("--dports" "$7")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
565 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
566 args+=("--dport" "$7")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
567 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
568 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
569
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
570 # Rule options
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
571 [ -n "$9" ] && {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
572 IFS=' '
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
573 for arg in $9; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
574 args+=("$arg")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
575 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
576 IFS=\;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
577 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
578
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
579 # Rule action
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
580 [ -n "$8" ] && {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
581 IFS=' '
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
582 args+=("-j")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
583 for arg in $8; do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
584 args+=("$arg")
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
585 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
586 IFS=\;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
587 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
588
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
589 $CMD "${args[@]}"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
590 rc=$?
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
591 echo " " $CMD "${args[@]}" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
592 if [ $rc -ne 0 ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
593 echo "Error in $CONFFILE" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
594 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
595 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
596
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
597 # In PREROUTING or POSTROUTING chains we are done here.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
598 if [ "$NCHAIN" = "PREROUTING" -o "$NCHAIN" = "POSTROUTING" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
599 return
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
600 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
601
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
602 # Ignore timing problems with old connections
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
603 $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
604 [ "$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
605
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
606 # 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
607 # 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
608 # 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
609 # blocked these systems are logged using the rule below this one.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
610 if [ "$IF_EXT_AUTO_BLOCK" = "1" -a "$NCHAIN" != "OUTPUT" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
611 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
612 # 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
613 $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
614 # Now the real rule.
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
615 $IPTABLES -A $NCHAIN $iodir ${INTF} \
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
616 -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
617 -j SET --add-set ${HOST}-mbsefw-auto4 src
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
618 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
619 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
620 # 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
621 $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
622 # Now the real rule.
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
623 $IP6TABLES -A $NCHAIN $iodir ${INTF} \
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
624 -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
625 -j SET --add-set ${HOST}-mbsefw-auto6 src
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
626 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
627 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
628 # deny and log the rest
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
629 $IPTABLES -A $NCHAIN $iodir ${INTF} -m limit --limit 10/minute -j LOG --log-level info --log-prefix "DENY=$NCHAIN "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
630 [ "$USE_IPV6" == "1" ] && $IP6TABLES -A $NCHAIN $iodir ${INTF} -m limit --limit 10/minute -j LOG --log-level info --log-prefix "DENY=$NCHAIN "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
631 $IPTABLES -A $NCHAIN $iodir ${INTF} -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
632 [ "$USE_IPV6" == "1" ] && $IP6TABLES -A $NCHAIN $iodir ${INTF} -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
633 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
634 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
635 }
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
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
639 fw_start_interface()
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
640 {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
641 fw_start_interface_chain $1 "prerouting" "PREROUTING" "pre"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
642 fw_start_interface_chain $1 "input" "INPUT" "in"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
643 fw_start_interface_chain $1 "output" "OUTPUT" "out"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
644 fw_start_interface_chain $1 "forward" "FORWARD" "fwd"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
645 fw_start_interface_chain $1 "postrouting" "POSTROUTING" "post"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
646 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
647
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
648
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
649
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
650 fw_start_main() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
651 i=0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
652
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
653 [ -n "$IF_EXT" ] && fw_start_interface "$IF_EXT"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
654 [ -n "$IF_EXT6" ] && fw_start_interface "$IF_EXT6"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
655
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
656 while [ $i -lt 50 ];
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
657 do
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
658 [ -z "${IF_TRUNK[$i]}" ] && break
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
659 fw_start_interface "${IF_TRUNK[$i]}"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
660 i=$(($i+1))
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
661 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
662 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
663
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
664
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
665
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
666 fw_start_final() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
667 # Deny and log everything else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
668 $IPTABLES -N FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
669 $IPTABLES -A OUTPUT -j FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
670 $IPTABLES -A INPUT -j FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
671 [ "$FW_FORWARD" = "1" ] && $IPTABLES -A FORWARD -j FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
672 $IPTABLES -A FINAL_RULE -m limit --limit 10/minute -j LOG --log-level info --log-prefix "DENY=999 "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
673 $IPTABLES -A FINAL_RULE -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
674 if [ "$USE_IPV6" = "1" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
675 $IP6TABLES -N FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
676 $IP6TABLES -A OUTPUT -j FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
677 $IP6TABLES -A INPUT -j FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
678 [ "$FW_FORWARD" = "1" ] && $IP6TABLES -A FORWARD -j FINAL_RULE
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
679 $IP6TABLES -A FINAL_RULE -m limit --limit 10/minute -j LOG --log-level info --log-prefix "DENY=999 "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
680 $IP6TABLES -A FINAL_RULE -j DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
681 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
682 echo "Firewall installed" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
683 }
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 fw_install() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
688 echo -n "Installing $(basename $0) $MBSEFW_VERSION: "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
689 reset_iptables DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
690 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
691 fw_init_sysctl
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
692 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
693 fw_start_init
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
694 fw_start_main
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
695 fw_start_final
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
696 echo " done."
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
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
700
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
701 fw_start() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
702 if [ -f /etc/mbse-firewall/data/firewall-ipv4.data -a \
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
703 -f /etc/mbse-firewall/data/firewall-ipv6.data -a \
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
704 -f /etc/mbse-firewall/data/firewall-ipset.data ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
705 # Do a full restore of all saved data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
706 echo -n "Starting $(basename $0) $MBSEFW_VERSION: "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
707 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
708 fw_init_nfacct
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
709 reset_iptables DROP
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
710 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
711 fw_init_sysctl
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
712 $IPSET restore < /etc/mbse-firewall/data/firewall-ipset.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
713 echo " Restored /etc/mbse-firewall/data/firewall-ipset.data" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
714 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
715 $IPTABLES_RESTORE < /etc/mbse-firewall/data/firewall-ipv4.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
716 echo " Restored /etc/mbse-firewall/data/firewall-ipv4.data" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
717 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
718 $IP6TABLES_RESTORE < /etc/mbse-firewall/data/firewall-ipv6.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
719 echo " Restored /etc/mbse-firewall/data/firewall-ipv6.data" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
720 echo " done."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
721 echo -n "New firewall active" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
722 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
723 # If there is no saved firewall, install a new one and save it.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
724 fw_install
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
725 fw_save
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
726 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
727 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
728
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
729
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
730
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
731 fw_stop() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
732 echo -n "Stopping $(basename $0) $MBSEFW_VERSION: "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
733 # Slackware defaults to ACCEPT when no firewall is active.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
734 reset_iptables ACCEPT
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
735 echo "done."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
736 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
737
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
738
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
739
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
740 # If there are blocklist tables, reload them.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
741 fw_reload() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
742 echo -n "Reload $(basename $0) $MBSEFW_VERSION: "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
743 reload_blocklist4
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
744 reload_blocklist6
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
745 echo done.
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
746 }
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 fw_save() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
751 echo -n "Saving $(basename $0) $MBSEFW_VERSION: "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
752 echo "Saving firewall" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
753 mkdir -p /etc/mbse-firewall/data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
754 [ -n "$IPTABLES_SAVE" ] && $IPTABLES_SAVE > /etc/mbse-firewall/data/firewall-ipv4.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
755 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
756 [ -n "$IP6TABLES_SAVE" ] && $IP6TABLES_SAVE > /etc/mbse-firewall/data/firewall-ipv6.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
757 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
758
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
759 rm -f /etc/mbse-firewall/data/firewall-ipset.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
760 touch /etc/mbse-firewall/data/firewall-ipset.data
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
761 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
762 SETS="$($IPSET list -n | grep ${HOST})"
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
763 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
764 if [ "$set" = "${HOST}-mbsefw-auto4" -o "$set" = "${HOST}-mbsefw-auto6" ]; then
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
765 # Only save structure for auto blocklists
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
766 $IPSET save $set -t >> /etc/mbse-firewall/data/firewall-ipset.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
767 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
768 $IPSET save $set >> /etc/mbse-firewall/data/firewall-ipset.data
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
769 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
770 echo -n "."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
771 done
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
772 echo " done."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
773 echo "Save firewall done in /etc/mbse-firewall/data" | $LOGGER
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
774 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
775
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
776
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
777
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
778 fw_status() {
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
779
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
780 echo -n "$(basename $0) $MBSEFW_VERSION"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
781
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
782 IP_MODULES=$($LSMOD | $AWK '{print $1}' | $GREP '^ip')
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
783 if [ "${IP_MODULES}x" = "x" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
784 echo " - You do not have any iptables loaded."
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
785 return
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
786 else
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
787 echo " - You have the following ip modules loaded:"
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
788 echo -n " "
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
789 echo ${IP_MODULES}
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
790 fi
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 [ ! -z "$( echo $IP_MODULES | $GREP iptable_filter )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
793 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
794 echo ' FILTER TABLE IPv4'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
795 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
796 $IPTABLES -t filter -L -n -v --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
797 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
798
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
799 if [ ! -z "$( echo $IP_MODULES | $GREP ip6table_filter )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
800 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
801 echo ' FILTER TABLE IPv6'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
802 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
803 $IP6TABLES -t filter -L -n -v --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
804 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
805
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
806 if [ ! -z "$( echo $IP_MODULES | $GREP iptable_nat )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
807 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
808 echo ' NAT TABLE IPv4'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
809 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
810 $IPTABLES -t nat -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
811 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
812
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
813 if [ ! -z "$( echo $IP_MODULES | $GREP ip6table_nat )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
814 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
815 echo ' NAT TABLE IPv6'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
816 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
817 $IP6TABLES -t nat -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
818 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
819
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
820 if [ ! -z "$( echo $IP_MODULES | $GREP iptable_raw )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
821 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
822 echo ' RAW TABLE IPv4'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
823 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
824 $IPTABLES -t raw -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
825 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
826
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
827 if [ ! -z "$( echo $IP_MODULES | $GREP ip6table_raw )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
828 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
829 echo ' RAW TABLE IPv6'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
830 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
831 $IP6TABLES -t raw -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
832 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
833
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
834 if [ ! -z "$( echo $IP_MODULES | $GREP iptable_mangle )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
835 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
836 echo ' MANGLE TABLE IPv4'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
837 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
838 $IPTABLES -t mangle -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
839 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
840
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
841 if [ ! -z "$( echo $IP_MODULES | $GREP ip6table_mangle )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
842 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
843 echo ' MANGLE TABLE IPv6'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
844 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
845 $IP6TABLES -t mangle -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
846 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
847
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
848 if [ ! -z "$( echo $IP_MODULES | $GREP iptable_security )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
849 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
850 echo ' SECURITY TABLE IPv4'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
851 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
852 $IPTABLES -t security -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
853 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
854
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
855 if [ ! -z "$( echo $IP_MODULES | $GREP ip6table_security )" ]; then
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
856 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
857 echo ' SECURITY TABLE IPv6'
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
858 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
859 $IP6TABLES -t security -L -v -n --line-numbers
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
860 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
861
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
862 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
863 if [ -n "$IPSET" ] && [ ! -z "$($IPSET list -n | grep ${HOST})" ]; then
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
864 echo
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
865 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
866 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
867 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
868 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
869 ${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
870 done
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
871 fi
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
872 }
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
873
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
874
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
875
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
876 # ---------------------------------------------------------------------------
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
877 #
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
878 # MAIN program part
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
879 #
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
880 # ---------------------------------------------------------------------------
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
881
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
882
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
883 # See how we were called
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
884 cmd=$1
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
885
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
886 case "$cmd" in
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
887 start)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
888 fw_start
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
889 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
890
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
891 stop)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
892 fw_stop
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
893 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
894
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
895 restart)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
896 fw_stop
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
897 fw_start
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
898 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
899
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
900 save)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
901 fw_save
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
902 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
903 install)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
904 fw_install
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
905 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
906 reload)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
907 fw_reload
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
908 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
909 status)
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
910 fw_status
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
911 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
912
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
913 *)
3
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
914 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
915 echo
6b45cf9df8cf Upgrades to version 0.0.14 and 0.0.15
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
916 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
917 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
918 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
919 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
920 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
921 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
922 echo "status show the firewall rules and counters"
0
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
923 ;;
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
924 esac
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
925
d4d23e51be4f Initial import
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
926

mercurial