Skip to content

Instantly share code, notes, and snippets.

@aurelmegn
Last active June 2, 2018 13:59
Show Gist options
  • Save aurelmegn/390500ce3cebfca0a60f877a5011e8eb to your computer and use it in GitHub Desktop.
Save aurelmegn/390500ce3cebfca0a60f877a5011e8eb to your computer and use it in GitHub Desktop.
#!/bin/bash
# Flush iptables.
iptables -F
iptables -X
# /!\ ne pas rejeter une connexion existante entrante
iptables -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
# bloquer le traffic entrant par défaut
iptables -P INPUT DROP
# bloquer le traffic sortant par défaut
iptables -P OUTPUT DROP
# /!\ ne pas rejeter une connexion existante sortante
iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
# bloquer la redirection de traffic
iptables -P FORWARD DROP
# tout autoriser sur l'interface loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# autoriser le ssh
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# autoriser le http + https
iptables -A OUTPUT -p tcp -m multiport --dports 80,443 -j ACCEPT
# autoriser les serveur postfix + dovecot
iptables -A INPUT -p tcp -m multiport --dports 25,587,993 -j ACCEPT
# autoriser les résolutions de nom
iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
# ouvir le port ntp
iptables -A OUTPUT -p udp --dport 123 -j ACCEPT
iptables -A INPUT -p udp --sport 123 -j ACCEPT
# tout loger
iptables -A INPUT -j LOG
iptables -A OUTPUT -j LOG
iptables -A FORWARD -j LOG
# ref: https://gist.github.com/azlux/6a70bd38bb7c525ab26efe7e3a7ea8ac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment