#!/usr/sbin/nft -f flush ruleset table inet filter { # Track established and related connections globally, ct = connection tracker chain global_checks { ct state established,related accept ct state invalid drop } chain input { type filter hook input priority 0; policy drop; # Allow loopback interface iifname "lo" accept # Allow returning traffic to the router itself jump global_checks # Allow internal ICMP and rate-limit external WAN pings iifname != "ens1f0" ip protocol icmp accept iifname "ens1f0" icmp type echo-request limit rate 5/second accept # Allow SSH management access STRICTLY from Trusted LAN and the Switch Mgmt port iifname { "ens1f1.10", "ens3f1" } tcp dport 22 accept } chain forward { type filter hook forward priority 0; policy drop; # Always allow returning internet and inter-zone traffic jump global_checks # Allow incoming WAN port forwards defined in the NAT prerouting chain iifname "ens1f0" ct status dnat accept # Zone Interfaces: # ens1f0 = WAN DHCP Assigned # ens1f1.10 = Trusted LAN 10.10.10.1/24 # ens1f1.20 = IoT Network 10.10.20.1/24 # ens1f1.30 = Guest Network 10.10.30.1/24 # ens3f1 = Switch Management 192.168.10.1/24 # 1. Trusted LAN Zone: Allowed to initiate connections anywhere iifname "ens1f1.10" accept # 2. Switch Management Zone: Only allowed out to WAN (for firmware/updates) iifname "ens3f1" oifname "ens1f0" accept # 3. IoT Zone: Only allowed out to WAN (Blocked from Trusted LAN / Switch Mgmt) iifname "ens1f1.20" oifname "ens1f0" accept # 4. Guest Zone: Only allowed out to WAN (Isolated completely) iifname "ens1f1.30" oifname "ens1f0" accept } chain output { type filter hook output priority 0; policy accept; } } table ip nat { chain prerouting { type nat hook prerouting priority 0; # Forward external WAN port 22222 -> 10.10.10.52:22 (SSH) iifname "ens1f0" tcp dport 22222 dnat to 10.10.10.52:22 # Forward external WAN port 443 -> 10.10.10.250:443 (HTTPS) iifname "ens1f0" tcp dport 443 dnat to 10.10.10.250:443 } chain postrouting { type nat hook postrouting priority 100; # Execute dynamic masquerade NAT only on traffic exiting your true WAN port oifname "ens1f0" masquerade } }