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