Bonjour,
J'ai un problème avec ma config Iptables sur mon serveur; j'ai des soucis avec le port 51413 que je n'arrive pas à ouvrir en sortie pour transmission-daemon :
Voila mon fichier config Iptables :
cat /etc/init.d/firewall
#!/bin/sh
#
# Simple Firewall configuration.
#
# Author: Nicolargo
#
# chkconfig: 2345 9 91
# description: Activates/Deactivates the firewall at boot time
#
### BEGIN INIT INFO
# Provides: firewall.sh
# Required-Start: $syslog $network
# Required-Stop: $syslog $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start firewall daemon at boot time
# Description: Custom Firewall scrip.
### END INIT INFO
PATH=/bin:/sbin:/usr/bin:/usr/sbin
if ! [ -x /sbin/iptables ]; then
exit 0
fi
##########################
# Start the Firewall rules
##########################
fw_start () {
# Réinitialise les règles
iptables -t filter -F
iptables -t filter -X
# Bloque tout le trafic
iptables -t filter -P INPUT DROP
iptables -t filter -P FORWARD DROP
iptables -t filter -P OUTPUT DROP
# Autorise les connexions déjà établies et localhost
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A OUTPUT -o lo -j ACCEPT
# relance fail2ban si installe
if [ -x /usr/bin/fail2ban-server ]; then
service fail2ban restart
fi
# ICMP (Ping)
iptables -t filter -A INPUT -p icmp -j ACCEPT
iptables -t filter -A OUTPUT -p icmp -j ACCEPT
# SSH
iptables -t filter -A INPUT -p tcp --dport 2222 -j ACCEPT # Attention, si vous avez changé le port SSH dans le fichier /etc/ssh/sshd_config, indiquez le à la place de 22
iptables -t filter -A OUTPUT -p tcp --dport 2222 -j ACCEPT
# DNS
iptables -t filter -A OUTPUT -p tcp --dport 53 -j ACCEPT
iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 53 -j ACCEPT
iptables -t filter -A INPUT -p udp --dport 53 -j ACCEPT
# NTP (horloge du serveur)
iptables -t filter -A OUTPUT -p udp --dport 123 -j ACCEPT
# HTTP
iptables -t filter -A OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
# HTTP Caldav
iptables -t filter -A OUTPUT -p tcp --dport 8008 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 8008 -j ACCEPT
# HTTPS
iptables -t filter -A OUTPUT -p tcp --dport 443 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT
# HTTPS Caldav
iptables -t filter -A OUTPUT -p tcp --dport 8008 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 8443 -j ACCEPT
# FTP
iptables -t filter -A OUTPUT -p tcp --dport 20:21 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 20:21 -j ACCEPT
# TRANSMISSION DAEMON
iptables -t filter -A OUTPUT -p tcp --dport 9091 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 9091 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 51413 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 51413 -j ACCEPT
iptables -t filter -A OUTPUT -m owner --gid-owner debian-transmission -j ACCEPT # transmission
# Mail SMTP
iptables -t filter -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 25 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 587 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 587 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 465 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 465 -j ACCEPT
# Mail POP3
iptables -t filter -A INPUT -p tcp --dport 110 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 110 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 995 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 995 -j ACCEPT
# Mail IMAP
iptables -t filter -A INPUT -p tcp --dport 993 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 993 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 143 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 143 -j ACCEPT
# Anti Flood / Deni de service / scan de port
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
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/second -j ACCEPT
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
# All other connections are registered in syslog
/sbin/iptables -A OUTPUT -j LOG
/sbin/iptables -A OUTPUT -j REJECT
/sbin/iptables -P OUTPUT DROP
# Other network protections
# (some will only work with some kernel versions)
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo 0 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo 1 > /proc/sys/net/ipv4/conf/all/log_martians
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
}
##########################
# Stop the Firewall rules
##########################
fw_stop () {
/sbin/iptables -F
/sbin/iptables -t nat -F
/sbin/iptables -t mangle -F
/sbin/iptables -P INPUT DROP
/sbin/iptables -P FORWARD DROP
/sbin/iptables -P OUTPUT ACCEPT
}
##########################
# Clear the Firewall rules
##########################
fw_clear () {
/sbin/iptables -F
/sbin/iptables -t nat -F
/sbin/iptables -t mangle -F
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables -P OUTPUT ACCEPT
# relance fail2ban si installe
if [ -x /usr/bin/fail2ban-server ]; then
service fail2ban restart
fi
}
##########################
# Test the Firewall rules
##########################
fw_save () {
/sbin/iptables-save > /etc/iptables.backup
}
fw_restore () {
if [ -e /etc/iptables.backup ]; then
/sbin/iptables-restore < /etc/iptables.backup
fi
}
fw_test () {
fw_save
sleep 30 && echo "Restore previous Firewall rules..." && fw_restore
fw_stop
fw_start
}
##########################
# Get the Firewall status
##########################
fw_status () {
iptables -L --line-numbers
}
case "$1" in
start|restart)
echo -n "Starting firewall.."
fw_stop
fw_start
echo "done."
;;
stop)
echo -n "Stopping firewall.."
fw_stop
echo "done."
;;
clear)
echo -n "Clearing firewall rules.."
fw_clear
echo "done."
;;
test)
echo -n "Test Firewall rules...\n"
echo -n "Previous configuration will be restored in 30 seconds\n"
fw_test
;;
status)
echo -n "Firewall status :\n"
fw_status
echo "done."
;;
*)
echo "Usage: $0 {start|stop|restart|clear|test|status}"
echo "Be aware that stop drop all incoming/outgoing traffic !!!"
exit 1
;;
esac
exit 0
et le résultat :
service firewall status
Firewall status :
Chain INPUT (policy DROP)
num target prot opt source destination
1 fail2ban-recidive tcp -- anywhere anywhere
2 fail2ban-vsftpd tcp -- anywhere anywhere multiport dports ftp,ftp-data,ftps,ftps-data
3 fail2ban-ssh tcp -- anywhere anywhere multiport dports 2222
4 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
5 ACCEPT all -- anywhere anywhere
6 ACCEPT icmp -- anywhere anywhere
7 ACCEPT tcp -- anywhere anywhere tcp dpt:2222
8 ACCEPT tcp -- anywhere anywhere tcp dpt:domain
9 ACCEPT udp -- anywhere anywhere udp dpt:domain
10 ACCEPT tcp -- anywhere anywhere tcp dpt:http
11 ACCEPT tcp -- anywhere anywhere tcp dpt:8008
12 ACCEPT tcp -- anywhere anywhere tcp dpt:https
13 ACCEPT tcp -- anywhere anywhere tcp dpt:8443
14 ACCEPT tcp -- anywhere anywhere tcp dpts:ftp-data:ftp
15 ACCEPT tcp -- anywhere anywhere tcp dpt:9091
16 ACCEPT tcp -- anywhere anywhere tcp dpt:51413
17 ACCEPT tcp -- anywhere anywhere tcp dpt:smtp
18 ACCEPT tcp -- anywhere anywhere tcp dpt:submission
19 ACCEPT tcp -- anywhere anywhere tcp dpt:urd
20 ACCEPT tcp -- anywhere anywhere tcp dpt:pop3
21 ACCEPT tcp -- anywhere anywhere tcp dpt:pop3s
22 ACCEPT tcp -- anywhere anywhere tcp dpt:imaps
23 ACCEPT tcp -- anywhere anywhere tcp dpt:imap2
Chain FORWARD (policy DROP)
num target prot opt source destination
1 ACCEPT tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,ACK/SYN limit: avg 1/sec burst 5
2 ACCEPT udp -- anywhere anywhere limit: avg 1/sec burst 5
3 ACCEPT icmp -- anywhere anywhere icmp echo-request limit: avg 1/sec burst 5
4 ACCEPT tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,ACK/RST limit: avg 1/sec burst 5
Chain OUTPUT (policy DROP)
num target prot opt source destination
1 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
2 ACCEPT all -- anywhere anywhere
3 ACCEPT icmp -- anywhere anywhere
4 ACCEPT tcp -- anywhere anywhere tcp dpt:2222
5 ACCEPT tcp -- anywhere anywhere tcp dpt:domain
6 ACCEPT udp -- anywhere anywhere udp dpt:domain
7 ACCEPT udp -- anywhere anywhere udp dpt:ntp
8 ACCEPT tcp -- anywhere anywhere tcp dpt:http
9 ACCEPT tcp -- anywhere anywhere tcp dpt:8008
10 ACCEPT tcp -- anywhere anywhere tcp dpt:https
11 ACCEPT tcp -- anywhere anywhere tcp dpt:8008
12 ACCEPT tcp -- anywhere anywhere tcp dpts:ftp-data:ftp
13 ACCEPT tcp -- anywhere anywhere tcp dpt:9091
14 ACCEPT tcp -- anywhere anywhere tcp dpt:51413
15 ACCEPT all -- anywhere anywhere owner GID match debian-transmission
16 ACCEPT tcp -- anywhere anywhere tcp dpt:smtp
17 ACCEPT tcp -- anywhere anywhere tcp dpt:submission
18 ACCEPT tcp -- anywhere anywhere tcp dpt:urd
19 ACCEPT tcp -- anywhere anywhere tcp dpt:pop3
20 ACCEPT tcp -- anywhere anywhere tcp dpt:pop3s
21 ACCEPT tcp -- anywhere anywhere tcp dpt:imaps
22 ACCEPT tcp -- anywhere anywhere tcp dpt:imap2
23 LOG all -- anywhere anywhere LOG level warning
24 REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
Chain fail2ban-recidive (1 references)
num target prot opt source destination
1 RETURN all -- anywhere anywhere
Chain fail2ban-ssh (1 references)
num target prot opt source destination
1 RETURN all -- anywhere anywhere
Chain fail2ban-vsftpd (1 references)
num target prot opt source destination
1 RETURN all -- anywhere anywhere
done.
Si quelqu'un peut m'aider, le port 51413 reste bloqué en TCP...
Merci d'avance !