Skip to content

Commit 81838e0

Browse files
Block all incoming traffic but
1 parent 57b60c1 commit 81838e0

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

0x13-firewall/0-block_all_incoming_traffic_but

100644100755
File mode changed.

0x13-firewall/100-port_forwarding

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#
2+
# rules.before
3+
#
4+
# Rules that should be run before the ufw command line added rules. Custom
5+
# rules should be added to one of these chains:
6+
# ufw-before-input
7+
# ufw-before-output
8+
# ufw-before-forward
9+
#
10+
11+
*nat
12+
:PREROUTING ACCEPT [0:0]
13+
-A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80
14+
COMMIT
15+
16+
# Don't delete these required lines, otherwise there will be errors
17+
*filter
18+
:ufw-before-input - [0:0]
19+
:ufw-before-output - [0:0]
20+
:ufw-before-forward - [0:0]
21+
:ufw-not-local - [0:0]
22+
# End required lines
23+
24+
25+
# allow all on loopback
26+
-A ufw-before-input -i lo -j ACCEPT
27+
-A ufw-before-output -o lo -j ACCEPT
28+
29+
# quickly process packets for which we already have a connection
30+
-A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
31+
-A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
32+
-A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
33+
34+
# drop INVALID packets (logs these in loglevel medium and higher)
35+
-A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny
36+
-A ufw-before-input -m conntrack --ctstate INVALID -j DROP
37+
38+
# ok icmp codes for INPUT
39+
-A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT
40+
-A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT
41+
-A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT
42+
-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT
43+
44+
# ok icmp code for FORWARD
45+
-A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT
46+
-A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT
47+
-A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT
48+
-A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT
49+
50+
# allow dhcp client to work
51+
-A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT
52+
53+
#
54+
# ufw-not-local
55+
#
56+
-A ufw-before-input -j ufw-not-local
57+
58+
# if LOCAL, RETURN
59+
-A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN
60+
61+
# if MULTICAST, RETURN
62+
-A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN
63+
64+
# if BROADCAST, RETURN
65+
-A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN
66+
67+
# all other non-local packets are dropped
68+
-A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny
69+
-A ufw-not-local -j DROP
70+
71+
# allow MULTICAST mDNS for service discovery (be sure the MULTICAST line above
72+
# is uncommented)
73+
-A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT
74+
75+
# allow MULTICAST UPnP for service discovery (be sure the MULTICAST line above
76+
# is uncommented)
77+
-A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT
78+
79+
# don't delete the 'COMMIT' line or these rules won't be processed
80+
COMMIT

0 commit comments

Comments
 (0)