-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathminimal-firewall.sh
28 lines (21 loc) · 923 Bytes
/
minimal-firewall.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh
# This script provides the minimal firewall rules necessary to run
# knockknock. Essentially, no connections are allowed, unless they
# are authenticated with knockknock.
#
# Courtesy: Jake Appelbaum
IPTABLES="/sbin/iptables"
# We want to allow open connections
$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# Allow everything out
$IPTABLES -A OUTPUT -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -A OUTPUT -j ACCEPT
# We want to reject any attempts to forward
$IPTABLES -A FORWARD -j REJECT
# Add the knock knock rules
$IPTABLES -N REJECTLOG
$IPTABLES -A REJECTLOG -j LOG --log-level debug --log-tcp-sequence --log-tcp-options --log-ip-options -m limit --limit 3/s --limit-burst 8 --log-prefix "REJECT "
$IPTABLES -A REJECTLOG -p tcp -j REJECT --reject-with tcp-reset
$IPTABLES -A REJECTLOG -j REJECT
# Reject all other incoming traffic:
$IPTABLES -A INPUT -j REJECTLOG