Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- IPTABLES = "iptables"
- SERVICE = "iptables"
- ssh_port = 22 unless ARGV[0] then ssh_port = ARGV[0]
- puts "Flushing rules..."
- `#{IPTABLES} -F`
- puts "Settings loopback rules..."
- `#{IPTABLES} -A INPUT -i lo -j ACCEPT`
- `#{IPTABLES} -A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT`
- puts "Accepting all established inbound connections..."
- `#{IPTABLES} -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT`
- puts "Allowing all outbound traffic..."
- `#{IPTABLES} -A OUTPUT -j ACCEPT`
- puts "Allowing HTTP and HTTPS connections..."
- `#{IPTABLES} -A INPUT -p tcp --dport 80 -j ACCEPT`
- `#{IPTABLES} -A INPUT -p tcp --dport 443 -j ACCEPT`
- puts "Allowing SSH on port #{ssh_port}..."
- `#{IPTABLES} -A INPUT -p tcp -m state --state NEW --dport #{ssh_port} -j ACCEPT`
- puts "Allowing ping..."
- `#{IPTABLES} -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT`
- puts "Logging denied connections..."
- `#{IPTABLES} -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7`
- puts "Rejecting all other inbound connections..."
- `#{IPTABLES} -A INPUT -j REJECT`
- `#{IPTABLES} -A FORWARD -j REJECT`
- puts "Saving..."
- `service #{SERVICE} save`
Add Comment
Please, Sign In to add comment