Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. # Flush rules
  2. iptables -F
  3. iptables -X
  4. iptables -t nat -F
  5. iptables -t nat -X
  6. iptables -t mangle -F
  7. iptables -t mangle -X
  8. iptables -t raw -F PREROUTING
  9. iptables -t raw -F OUTPUT
  10.  
  11. # List policies first
  12. iptables -P INPUT DROP; iptables -P FORWARD ACCEPT; iptables -P OUTPUT ACCEPT;
  13.  
  14. # Enable connection tracking
  15. iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
  16.  
  17. # Disable connection tracking on OpenVPN port - Should be tested, not sure if this is possible. Remarked for now.
  18. #iptables -A PREROUTING -t raw -p udp --dport 41100 -j NOTRACK
  19.  
  20. # Allow TCP SSH inbound - Prevent SSH brute force attacks
  21. iptables -I INPUT -p tcp -m state --state NEW --dport 22 -m recent --set
  22. iptables -I INPUT -p tcp -m state --state NEW --dport 22 -m recent --update --seconds 60 --hitcount 4 -j DROP
  23. iptables -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
  24.  
  25. # Drop invalid size UDP
  26. iptables -A PREROUTING -t raw -p udp --dport 1:65535 -m length --length 0:32 -j DROP
  27. iptables -A PREROUTING -t raw -p udp --dport 1:65535 -m length --length 2521:65535 -j DROP
  28.  
  29. # Allow OpenVPN Forwarding
  30. iptables -A FORWARD -s 10.8.0.0/24 -j ACCEPT
  31.  
  32. # Allow OpenVPN UDP inbound with connection tracking (enabled now):
  33. iptables -A INPUT -m state --state NEW --dport 41100 -j ACCEPT
  34.  
  35. # Without connection tracking (disabled now):
  36. #iptables -A INPUT -p udp --dport 41100 -j ACCEPT
  37.  
  38. # Allow ICMP
  39. iptables -A INPUT -p icmp -j ACCEPT
  40.  
  41. # Attempt to limit outgoing RST if under TCP SYN attack. (Review if useless)
  42. # Syn would be something like this but you need to test and tweak the values.
  43. iptables -A INPUT -p tcp --syn -m limit --limit 1/s --limit-burst 3 -j RETURN
  44.  
  45. # Allow all localhost
  46. iptables -A INPUT -i lo -j ACCEPT
  47. iptables -A OUTPUT -o lo -j ACCEPT
  48.  
  49. service iptables-persistent save
  50. service iptables-persistent start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement