Utilisation d'iptable

Contenu

Voici un exemple commenté, cela est plus simple que de longue explications 😉

#!/bin/bash

# Vider les tables actuelles
iptables -t filter -F
iptables -t filter -X

# Autoriser SSH
iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT

# Ne pas casser les connexions etablies
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

# Monitoring Dedibox
iptables -A INPUT -i eth0 -s 88.191.254.0/24 -p tcp --dport 161 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -s 88.191.254.0/24 -p udp --dport 161 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -d 88.191.254.0/24 -p tcp --sport 161 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -d 88.191.254.0/24 -p udp --sport 161 -m state --state ESTABLISHED -j ACCEPT

# Interdire toute connexion entrante
iptables -t filter -P INPUT DROP
iptables -t filter -P FORWARD DROP

# Interdire toute connexion sortante
iptables -t filter -P OUTPUT DROP

# Autoriser les requetes DNS, FTP, HTTP, NTP (pour les mises a jour)
iptables -t filter -A OUTPUT -p tcp --dport 21 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -t filter -A OUTPUT -p udp --dport 123 -j ACCEPT

# Autoriser loopback
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A OUTPUT -o lo -j ACCEPT

# Autoriser ping
iptables -t filter -A INPUT -p icmp -j ACCEPT
iptables -t filter -A OUTPUT -p icmp -j ACCEPT

# HTTP
iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT

# FTP
modprobe ip_conntrack_ftp
iptables -t filter -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -t filter -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# DNS
iptables -t filter -A INPUT -p tcp --dport 53 -j ACCEPT
iptables -t filter -A INPUT -p udp --dport 53 -j ACCEPT

# Mail
iptables -t filter -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 110 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 25 -j ACCEPT

# Steamcast
iptables -t filter -A INPUT -p tcp --dport 8000 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 8001 -j ACCEPT

# Syn-Flood
iptables -A FORWARD -p tcp --syn -m limit --limit 1/second -j ACCEPT
iptables -A FORWARD -p udp -m limit --limit 1/second -j ACCEPT

# Spoofing
iptables -N SPOOFED
iptables -A SPOOFED -s 127.0.0.0/8 -j DROP
iptables -A SPOOFED -s 169.254.0.0/12 -j DROP
iptables -A SPOOFED -s 172.16.0.0/12 -j DROP
iptables -A SPOOFED -s 192.168.0.0/16 -j DROP
iptables -A SPOOFED -s 10.0.0.0/8 -j DROP

comments powered by Disqus