Guest User

Untitled

a guest
Jun 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. IPTABLES = "iptables"
  4. SERVICE = "iptables"
  5.  
  6. ssh_port = 22 unless ARGV[0] then ssh_port = ARGV[0]
  7.  
  8. puts "Flushing rules..."
  9. `#{IPTABLES} -F`
  10.  
  11. puts "Settings loopback rules..."
  12. `#{IPTABLES} -A INPUT -i lo -j ACCEPT`
  13. `#{IPTABLES} -A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT`
  14.  
  15. puts "Accepting all established inbound connections..."
  16. `#{IPTABLES} -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT`
  17.  
  18. puts "Allowing all outbound traffic..."
  19. `#{IPTABLES} -A OUTPUT -j ACCEPT`
  20.  
  21. puts "Allowing HTTP and HTTPS connections..."
  22. `#{IPTABLES} -A INPUT -p tcp --dport 80 -j ACCEPT`
  23. `#{IPTABLES} -A INPUT -p tcp --dport 443 -j ACCEPT`
  24.  
  25. puts "Allowing SSH on port #{ssh_port}..."
  26. `#{IPTABLES} -A INPUT -p tcp -m state --state NEW --dport #{ssh_port} -j ACCEPT`
  27.  
  28. puts "Allowing ping..."
  29. `#{IPTABLES} -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT`
  30.  
  31. puts "Logging denied connections..."
  32. `#{IPTABLES} -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7`
  33.  
  34. puts "Rejecting all other inbound connections..."
  35. `#{IPTABLES} -A INPUT -j REJECT`
  36. `#{IPTABLES} -A FORWARD -j REJECT`
  37.  
  38. puts "Saving..."
  39. `service #{SERVICE} save`
Add Comment
Please, Sign In to add comment