Skip to content

Instantly share code, notes, and snippets.

@raulanatol
Created November 27, 2016 10:13
Show Gist options
  • Save raulanatol/47f849bca17ad9bb800ad0b02c1df185 to your computer and use it in GitHub Desktop.
Save raulanatol/47f849bca17ad9bb800ad0b02c1df185 to your computer and use it in GitHub Desktop.
IpTablesConfig
#!/bin/bash
iptables -F
# Defautlt policy
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
# drop invalid packets
iptables -A INPUT -m state --state INVALID -j DROP
# see http://www.faqs.org/docs/iptables/newnotsyn.html
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
# accept anything on localhost
iptables -A INPUT -i lo -j ACCEPT
# accept ICMP packets
iptables -A INPUT -p icmp -j ACCEPT
# allow specific ports
iptables -A INPUT -p tcp -s 0/0 --dport 22 -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 --dport 80 -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 --dport 443 -j ACCEPT
# allow establishment of connections initialised by my outgoing packets
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment