Guest User

Untitled

a guest
Aug 23rd, 2014
231
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # fail on error
  4. set -e
  5.  
  6. # Clean any old rules
  7. iptables -F
  8. iptables -X
  9.  
  10. # set defult rules drop input and accept output.
  11. iptables -P FORWARD DROP
  12. iptables -P INPUT DROP
  13. iptables -P OUTPUT ACCEPT
  14.  
  15. # custom chains
  16. iptables -N TCP
  17. iptables -N UDP
  18.  
  19. # handle input
  20. iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
  21. iptables -A INPUT -i lo -j ACCEPT
  22. iptables -A INPUT -m conntrack --ctstate INVALID -j DROP
  23. iptables -A INPUT -p icmp --icmp-type 8 -m conntrack --ctstate NEW -j ACCEPT
  24.  
  25. iptables -A INPUT -p udp -m conntrack --ctstate NEW -j UDP
  26. iptables -A INPUT -p tcp --syn -m conntrack --ctstate NEW -j TCP
  27.  
  28. iptables -A INPUT -p udp -j REJECT --reject-with icmp-port-unreachable
  29. iptables -A INPUT -p tcp -j REJECT --reject-with tcp-rst
  30.  
  31. iptables -A INPUT -j REJECT --reject-with icmp-proto-unreachable
  32.  
  33. # finished
  34. echo 'Finished setting rules
RAW Paste Data