#!/sbin/nft -f flush ruleset # ----- IPv4 ----- table ip filter { chain input { type filter hook input priority 0; policy drop; ct state invalid counter drop comment "early drop of invalid packets" ct state {established, related} counter accept comment "accept all connections related to connections made by us" iif lo accept comment "accept loopback" iif != lo ip daddr 127.0.0.1/8 counter drop comment "drop connections to loopback not coming from loopback" ip protocol icmp counter accept comment "accept all ICMP types" tcp dport 22 counter accept comment "accept SSH" counter comment "count dropped packets" } chain forward { type filter hook forward priority 0; policy drop; counter comment "count dropped packets" } # If you're not counting packets, this chain can be omitted. chain output { type filter hook output priority 0; policy accept; counter comment "count accepted packets" } } # ----- IPv6 ----- table ip6 filter { chain input { type filter hook input priority 0; policy drop; ct state invalid counter drop comment "early drop of invalid packets" ct state {established, related} counter accept comment "accept all connections related to connections made by us" iif lo accept comment "accept loopback" iif != lo ip6 daddr ::1/128 counter drop comment "drop connections to loopback not coming from loopback" ip6 nexthdr icmpv6 counter accept comment "accept all ICMP types" tcp dport 22 counter accept comment "accept SSH" counter comment "count dropped packets" } chain forward { type filter hook forward priority 0; policy drop; counter comment "count dropped packets" } # If you're not counting packets, this chain can be omitted. chain output { type filter hook output priority 0; policy accept; counter comment "count accepted packets" } }