{# SPDX-License-Identifier: GPL-3.0-only Derived from ufw conf/before.rules (https://git.launchpad.net/ufw), Copyright 2008-2023 Canonical Ltd., GPL-3.0-only. Modified by Defame1297. #} # Managed by Ansible – UFW before.rules *filter :ufw-before-input - [0:0] :ufw-before-output - [0:0] :ufw-before-forward - [0:0] :ufw-not-local - [0:0] # Allow all traffic on loopback - this file fully replaces the stock # /etc/ufw/before.rules (which always includes this), so without it any # fresh (non-conntrack-established) loopback connection - e.g. DNS queries # to systemd-resolved's 127.0.0.53 stub - is silently dropped by the # default-deny INPUT policy. -A ufw-before-input -i lo -j ACCEPT -A ufw-before-output -o lo -j ACCEPT # Allow established and related connections -A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # drop INVALID packets (logs these in loglevel medium and higher) -A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny -A ufw-before-input -m conntrack --ctstate INVALID -j DROP # The rules in this file mirror stock ufw's before.rules (checked against # ufw 0.36.2); the only deviations are this file's header comments, the # omitted stock "End required lines" markers and the aggregated rules loop # at the end. Since this template fully replaces that file rather than # layering on top of it, dropping the stock rules would silently break # ping/PMTU-discovery and treat broadcast/multicast traffic as spoofed # non-local input on every host, custom aggregated rules or not. # ok icmp codes for INPUT -A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT -A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT -A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT -A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT # ok icmp codes for FORWARD -A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT -A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT -A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT -A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT # allow dhcp client to work -A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT # # ufw-not-local # -A ufw-before-input -j ufw-not-local # if LOCAL, RETURN -A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN # if MULTICAST, RETURN -A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN # if BROADCAST, RETURN -A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN # all other non-local packets are dropped -A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny -A ufw-not-local -j DROP # allow MULTICAST mDNS for service discovery -A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT # allow MULTICAST UPnP for service discovery -A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT {% for rule in ufw_aggregated_before_rules %} # {{ rule.comment | default('before-rule') }} -A ufw-before-input{% if rule.interface is defined %} -i {{ rule.interface }}{% endif %}{% if rule.proto is defined %} -p {{ rule.proto }}{% endif %}{% if rule.port is defined %} --dport {{ rule.port }}{% endif %}{% if rule.from is defined %} -s {{ rule.from }}{% endif %} -j ACCEPT {% endfor %} COMMIT