blob: 92adec570fdd2003c43eb861670afc1bde3fdc94 [file] [log] [blame]
Matteo Scandoloaca86652017-08-08 13:05:27 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15
Scott Baker761e1062016-06-20 17:18:17 -070016#
17# rules.before
18#
19# Rules that should be run before the ufw command line added rules. Custom
20# rules should be added to one of these chains:
21# ufw-before-input
22# ufw-before-output
23# ufw-before-forward
24#
25
26# nat Table rules
27*nat
28:POSTROUTING ACCEPT [0:0]
29
30# Forward traffic from eth1 through eth0.
31-A POSTROUTING -o eth0 -j MASQUERADE
32
33# Set up NAT for CDN services
34-A POSTROUTING -o eth2 -j MASQUERADE
35
36# DNS safe browsing
37{% if safe_browsing %}
38{% for mac in safe_browsing %}
39-A PREROUTING -i eth1 -m mac --mac-source {{ mac }} -p udp --dport 53 -j REDIRECT --to-port 5353
40-A PREROUTING -i eth1 -m mac --mac-source {{ mac }} -p tcp --dport 53 -j REDIRECT --to-port 5353
41{% endfor %}
42{% endif %}
43
44{% if status != "enabled" %}
45-A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 8000
46{% endif %}
47
48# don't delete the 'COMMIT' line or these nat table rules won't be processed
49COMMIT
50
51# Don't delete these required lines, otherwise there will be errors
52*filter
53:ufw-before-input - [0:0]
54:ufw-before-output - [0:0]
55:ufw-before-forward - [0:0]
56:ufw-not-local - [0:0]
57# End required lines
58
59# allow all on loopback
60-A ufw-before-input -i lo -j ACCEPT
61-A ufw-before-output -o lo -j ACCEPT
62
63# quickly process packets for which we already have a connection
64-A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
65-A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
66-A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
67
68# drop INVALID packets (logs these in loglevel medium and higher)
69-A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny
70-A ufw-before-input -m conntrack --ctstate INVALID -j DROP
71
72# ok icmp codes for INPUT
73-A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT
74-A ufw-before-input -p icmp --icmp-type source-quench -j ACCEPT
75-A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT
76-A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT
77-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT
78
79# ok icmp code for FORWARD
80-A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT
81-A ufw-before-forward -p icmp --icmp-type source-quench -j ACCEPT
82-A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT
83-A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT
84-A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT
85
86# allow dhcp client to work
87-A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT
88
89#
90# ufw-not-local
91#
92-A ufw-before-input -j ufw-not-local
93
94# if LOCAL, RETURN
95-A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN
96
97# if MULTICAST, RETURN
98-A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN
99
100# if BROADCAST, RETURN
101-A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN
102
103# all other non-local packets are dropped
104-A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny
105-A ufw-not-local -j DROP
106
107# allow MULTICAST mDNS for service discovery (be sure the MULTICAST line above
108# is uncommented)
109-A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT
110
111# allow MULTICAST UPnP for service discovery (be sure the MULTICAST line above
112# is uncommented)
113-A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT
114
115# don't delete the 'COMMIT' line or these rules won't be processed
116COMMIT