3 # nftables ruleset for an End Node acting as a workstation in a LAN.
5 # Copyright (C) 2018 Antonio Ospite <ao2@ao2.it>
6 # SPDX-License-Identifier: MIT
9 # https://wiki.nftables.org/wiki-nftables/index.php/Quick_reference-nftables_in_10_minutes#Simple_IP.2FIPv6_Firewall
10 # https://wiki.archlinux.org/index.php/Nftables#Workstation
11 # https://stosb.com/blog/explaining-my-configs-nftables/
17 define common_open_ports = {
20 5298, # Link-local XMPP, for backward compatibility, XEP-0174
42 type filter hook input priority 0
45 ct state established,related accept
47 ct state new jump in-new
51 ip protocol icmp icmp type {
56 destination-unreachable
59 # ICMPv6 configuration based on:
60 # https://github.com/intel/intel-iot-refkit/blob/master/meta-refkit-core/recipes-security/nftables-settings-default/files/firewall.template
61 ip6 nexthdr ipv6-icmp icmpv6 type {
66 destination-unreachable,
70 # Allow auto configuration support.
71 ip6 nexthdr ipv6-icmp icmpv6 type {
76 } ip6 hoplimit 255 accept
78 # Allow multicast listener discovery on link-local addresses.
79 # RFC2710 specifies that a Hop-by-Hop Options header is used.
80 hbh nexthdr ipv6-icmp icmpv6 type {
83 mld-listener-reduction
84 } ip6 saddr fe80::/10 accept
86 # Allow multicast router discovery messages on link-local addresses (hop limit 1).
87 ip6 nexthdr ipv6-icmp icmpv6 type {
90 } ip6 hoplimit 1 ip6 saddr fe80::/10 accept
92 # Allow IGMPv3 queries.
93 ip protocol igmp ip daddr 224.0.0.1 accept
95 # Silently drop other incoming broadcast and multicast traffic.
96 meta pkttype {broadcast, multicast} drop
98 limit rate 3/minute burst 10 packets log prefix "[INPUT]: "
103 # Silently drop DHCPv4 Discover and Request packets from other clients.
104 ip saddr 0.0.0.0 ip daddr 255.255.255.255 udp sport bootpc udp dport bootps drop
106 # Silently drop DHCPv6 from other clients.
107 ip6 saddr fe80::/64 ip6 daddr fe80::/64 udp sport dhcpv6-client udp dport dhcpv6-server drop
109 # mDNS (ZeroConf/Bonjour)
110 ip daddr 224.0.0.251 udp dport mdns accept
111 ip6 daddr ff02::fb udp dport mdns accept
113 # SSDP: https://en.wikipedia.org/wiki/Simple_Service_Discovery_Protocol
114 ip daddr 239.255.255.250 udp dport 1900 accept
120 } udp dport 1900 accept
122 tcp dport @tcp_open_ports tcp flags & (fin | syn | rst | ack) == syn accept
123 udp dport @udp_open_ports accept
127 type filter hook forward priority 0
130 limit rate 3/minute burst 10 packets log prefix "[FORWARD]: "
135 type filter hook output priority 0