nftables.conf 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. flush ruleset
  2. # @link: https://fishilico.github.io/generic-config/etc/nftables-server.conf.raw.html
  3. table inet firewall {
  4. # allow all outbound traffic
  5. chain outbound {
  6. type filter hook output priority 0; policy accept;
  7. }
  8. # accept ip4 icmp with rate limit
  9. chain inbound_ipv4 {
  10. icmp type echo-request limit rate 5/second accept
  11. }
  12. # accept neighbor discovery and ip6 icmp with rate limit
  13. chain inbound_ipv6 {
  14. icmpv6 type { nd-neighbor-solicit, nd-router-advert, nd-neighbor-advert } accept
  15. icmpv6 type echo-request limit rate 5/second accept
  16. }
  17. # drop all inbound traffic that does not pass filters
  18. chain inbound {
  19. type filter hook input priority 0; policy drop;
  20. # Allow traffic from established and related packets, drop invalid
  21. ct state vmap { established: accept, related: accept, invalid: drop }
  22. # Allow loopback traffic
  23. iifname lo accept
  24. # Jump to chain according to layer 3 protocol using a verdict map
  25. meta protocol vmap { ip: jump inbound_ipv4, ip6: jump inbound_ipv6 }
  26. # silence some noisy crap
  27. meta pkttype broadcast counter drop comment "silently drop unsollicited broadcast"
  28. meta pkttype multicast counter drop comment "silently drop unsollicited multicast"
  29. ip daddr 255.255.255.255/32 counter drop comment "really drop unsollicited IPv4 broadcast"
  30. # allow http and https traffic
  31. tcp dport { 80, 443 } accept
  32. # rate limit new ssh connections
  33. tcp dport ssh ct state new limit rate 4/minute accept
  34. # log all denied traffic (including ssh)
  35. log prefix "[nftables] Inbound Denied: " counter drop
  36. }
  37. # do not act as a router; drop all forward requests
  38. chain forward {
  39. type filter hook forward priority 0; policy drop;
  40. }
  41. }