Advertisement
Luticus

nftables example

Feb 16th, 2023
1,532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.60 KB | Cybersecurity | 0 0
  1. # this is a reference file that serves as an example, it is not something that will necessarily work for you.
  2. # This will require interpretations and updates based on your own environment and situation. You will need
  3. # to use your own judgement and be prepared to make changes if you are going to build off of this.
  4.  
  5. # This file is based on my video: https://www.youtube.com/watch?v=v15ac5ssoco
  6.  
  7. # --- /etc/nftables.conf
  8. #!/usr/sbin/nft -f
  9. #local = enp2s0
  10. #wan = enp1s0
  11. #
  12. #
  13. flush ruleset
  14.  
  15. table inet filter {
  16. chain input {
  17. type filter hook input priority 0;
  18. iif enp1s0 tcp dport {ssh} counter accept comment "allow ssh"
  19. iif enp2s0 accept comment "allow local packets"
  20. iif enp1s0 ct state {established, related} counter accept comment "allow esablished wan packets"
  21. iif enp1s0 drop
  22. }
  23. chain forward {
  24. type filter hook forward priority 0;
  25. iif enp1s0 oif enp2s0 ct state {established, related} counter accept comment "allow wan est, relat"
  26. iif enp2s0 oif enp1s0 counter accept comment "allow lan to wan"
  27. iif enp1s0 ip daddr 192.168.100.190 tcp dport {https} counter accept comment "forward https"
  28. iif enp1s0 drop
  29. }
  30. chain output {
  31. type filter hook output priority 0;
  32. }
  33. }
  34.  
  35. table nat {
  36. chain output {
  37. type nat hook output priority -100;
  38. }
  39. chain prerouting {
  40. type nat hook prerouting priority -100;
  41. iif enp1s0 tcp dport {https} counter dnat to 192.168.100.190 comment "forward https to 190"
  42. }
  43. chain postrouting {
  44. type nat hook postrouting priority 100;
  45. oif enp1s0 counter masquerade comment "masquerade"
  46. #ip saddr 191.168.100.0/24 oif enp1s0 counter snat 0.0.0.0 comment "snat - no dynamic ips!!!!"
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement