|
| 1 | +#!/usr/sbin/nft -f |
| 2 | + |
| 3 | +table inet filter |
| 4 | +delete table inet filter |
| 5 | + |
| 6 | +table inet filter { |
| 7 | + chain inet-pre { |
| 8 | + type filter hook prerouting priority 0; policy drop; |
| 9 | + ct state invalid counter drop # Drop invalid and faulty packets |
| 10 | + iif != lo ip daddr 127.0.0.0/8 counter drop |
| 11 | + iif != lo ip6 daddr ::1 counter drop |
| 12 | + counter accept |
| 13 | + } |
| 14 | + |
| 15 | + chain inet-in { |
| 16 | + type filter hook input priority 0; policy drop; |
| 17 | + ct state { established,related } counter accept # Allow traffic from established and related packets |
| 18 | + iif lo accept # Allow loopback traffic |
| 19 | + ip protocol icmp counter limit rate 10/second accept # Allow all ICMP and IGMP traffic, but enforce a rate limit |
| 20 | + ip protocol igmp counter limit rate 10/second accept |
| 21 | + ip6 nexthdr icmpv6 counter limit rate 10/second accept |
| 22 | + tcp dport 22 counter accept # Allow SSH traffic |
| 23 | + include "/etc/nftables/inet-in-*.conf" # Include roles rules |
| 24 | + counter {% if nftables_firewall_log_rejected is defined and nftables_firewall_log_rejected %}log prefix "nftables inet-in rejected " {% endif %}reject with icmpx type port-unreachable # Reject |
| 25 | + } |
| 26 | + |
| 27 | + chain inet-fwd { |
| 28 | + type filter hook forward priority 0; policy drop; |
| 29 | + ct state { established,related } counter accept # Allow traffic from established and related packets |
| 30 | + ip protocol icmp counter accept # Allow all ICMP and IGMP traffic, but do NOT enforce a rate limit |
| 31 | + ip protocol igmp counter accept |
| 32 | + ip6 nexthdr icmpv6 counter accept |
| 33 | + include "/etc/nftables/inet-fwd-*.conf" # Include roles rules |
| 34 | + counter {% if nftables_firewall_log_rejected is defined and nftables_firewall_log_rejected %}log prefix "nftables inet-fwd rejected " {% endif %}reject with icmpx type host-unreachable # Reject |
| 35 | + } |
| 36 | + |
| 37 | + chain inet-out { |
| 38 | + type filter hook output priority 0; policy drop; |
| 39 | + ct state { established,related } counter accept # Allow traffic from established and related packets |
| 40 | + oif lo counter accept |
| 41 | + ip protocol icmp counter accept # Allow all ICMP and IGMP traffic, but do NOT enforce a rate limit |
| 42 | + ip protocol igmp counter accept |
| 43 | + ip6 nexthdr icmpv6 counter accept |
| 44 | + udp dport 53 counter accept # Allow DNS traffic |
| 45 | + tcp dport 53 counter accept |
| 46 | + udp dport 123 counter accept # Allow NTP traffic |
| 47 | + tcp dport 80 counter accept # Allow HTTP traffic |
| 48 | + tcp dport 443 counter accept # Allow HTTPS traffic |
| 49 | + tcp dport 22 counter accept # Allow SSH traffic |
| 50 | + include "/etc/nftables/inet-out-*.conf" # Include roles rules |
| 51 | + counter {% if nftables_firewall_log_rejected is defined and nftables_firewall_log_rejected %}log prefix "nftables inet-out rejected " {% endif %}reject with icmpx type admin-prohibited # Reject |
| 52 | + } |
| 53 | + |
| 54 | + chain inet-post { |
| 55 | + type filter hook postrouting priority 0; policy drop; |
| 56 | + ct state invalid counter drop # Drop invalid and faulty packets |
| 57 | + oif != lo ip daddr 127.0.0.0/8 counter drop |
| 58 | + oif != lo ip6 daddr ::1 counter drop |
| 59 | + counter accept |
| 60 | + } |
| 61 | + |
| 62 | + include "/etc/nftables/inet-chain-*.conf" # Include roles chains |
| 63 | +} |
0 commit comments