URL: https://www.opennet.me/cgi-bin/openforum/vsluhboard.cgi
Форум: vsluhforumID1
Нить номер: 80993
[ Назад ]

Исходное сообщение
"iptables для почты (Exim + dovecot)"

Отправлено Hazer , 02-Июл-08 15:16 
Здравствуйте. Есть в связке Exim, dovecot и MySQL на одной машине. А также два скрипта с правилами для iptables.
Первый вариант, с которым почта ходит нормально, при выводе iptables -L, выглядит так :

Chain INPUT (policy DROP)
target     prot opt source               destination        
bad_tcp_packets  tcp  --  anywhere             anywhere            
ACCEPT     0    --  0.0.168.192.in-addr.arpa/24  anywhere            
ACCEPT     0    --  localhost.localdomain  anywhere            
ACCEPT     0    --  domain.ru             anywhere            
ACCEPT     0    --  XX.XXX.XX.XX.in-addr.arpa  anywhere            
ACCEPT     udp  --  anywhere             anywhere            udp spt:bootpc dpt:bootps
ACCEPT     0    --  anywhere             XX.XXX.XX.XX.in-addr.arpa state RELATED,ESTABLISHED
tcp_packets  tcp  --  anywhere             anywhere            
udp_packets  udp  --  anywhere             anywhere            
icmp_packets  icmp --  anywhere             anywhere            
LOG        0    --  anywhere             anywhere            limit: avg 3/min burst 3 LOG level debug prefix `IPT INPUT packet died: '

Chain FORWARD (policy DROP)
target     prot opt source               destination        
bad_tcp_packets  tcp  --  anywhere             anywhere            
ACCEPT     0    --  anywhere             anywhere            
ACCEPT     0    --  anywhere             anywhere            state RELATED,ESTABLISHED
LOG        0    --  anywhere             anywhere            limit: avg 3/min burst 3 LOG level debug prefix `IPT FORWARD packet died: '

Chain OUTPUT (policy DROP)
target     prot opt source               destination        
bad_tcp_packets  tcp  --  anywhere             anywhere            
ACCEPT     0    --  localhost.localdomain  anywhere            
ACCEPT     0    --  domain.ru             anywhere            
ACCEPT     0    --  XX.XXX.XX.XX.in-addr.arpa  anywhere            
LOG        0    --  anywhere             anywhere            limit: avg 3/min burst 3 LOG level debug prefix `IPT OUTPUT packet died: '

Chain allowed (21 references)
target     prot opt source               destination        
ACCEPT     tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/SYN
ACCEPT     tcp  --  anywhere             anywhere            state RELATED,ESTABLISHED
DROP       tcp  --  anywhere             anywhere            

Chain bad_tcp_packets (3 references)
target     prot opt source               destination        
REJECT     tcp  --  anywhere             anywhere            tcp flags:SYN,ACK/SYN,ACK state NEW reject-with tcp-reset
LOG        tcp  --  anywhere             anywhere            tcp flags:!FIN,SYN,RST,ACK/SYN state NEW LOG level warning prefix `New not syn:'
DROP       tcp  --  anywhere             anywhere            tcp flags:!FIN,SYN,RST,ACK/SYN state NEW

Chain icmp_packets (1 references)
target     prot opt source               destination        
ACCEPT     icmp --  anywhere             anywhere            icmp echo-request
ACCEPT     icmp --  anywhere             anywhere            icmp time-exceeded

Chain tcp_packets (1 references)
target     prot opt source               destination        
allowed    tcp  --  anywhere             anywhere            tcp dpt:ftp
allowed    tcp  --  anywhere             anywhere            tcp dpt:ssh
allowed    tcp  --  anywhere             anywhere            tcp dpt:smtp
allowed    tcp  --  anywhere             anywhere            tcp dpt:pop3
allowed    tcp  --  anywhere             anywhere            tcp dpt:domain
allowed    tcp  --  anywhere             anywhere            tcp dpt:www
allowed    tcp  --  anywhere             anywhere            tcp dpt:3128
allowed    tcp  --  anywhere             anywhere            tcp dpt:ldap
allowed    tcp  --  anywhere             anywhere            tcp dpt:kerberos
allowed    tcp  --  anywhere             anywhere            tcp dpt:loc-srv
allowed    tcp  --  anywhere             anywhere            tcp dpt:3268
allowed    tcp  --  anywhere             anywhere            tcp dpt:openvpn
allowed    tcp  --  anywhere             anywhere            tcp dpt:1723
allowed    tcp  --  anywhere             anywhere            tcp dpt:l2f
allowed    tcp  --  anywhere             anywhere            tcp dpt:1021
allowed    tcp  --  anywhere             anywhere            tcp dpt:8001
allowed    tcp  --  anywhere             anywhere            tcp dpt:rplay
allowed    tcp  --  anywhere             anywhere            tcp dpt:1000
allowed    tcp  --  anywhere             anywhere            tcp dpt:1721
allowed    tcp  --  anywhere             anywhere            tcp dpt:1721
allowed    tcp  --  anywhere             anywhere            tcp dpt:sip

Chain udp_packets (1 references)
target     prot opt source               destination        
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain
ACCEPT     udp  --  anywhere             anywhere            udp dpt:2074
ACCEPT     udp  --  anywhere             anywhere            udp dpt:4000
ACCEPT     udp  --  anywhere             anywhere            udp dpt:kerberos
ACCEPT     udp  --  anywhere             anywhere            udp dpt:loc-srv
ACCEPT     udp  --  anywhere             anywhere            udp dpt:3268
ACCEPT     udp  --  anywhere             anywhere            udp dpt:openvpn
ACCEPT     udp  --  anywhere             anywhere            udp dpt:1723
ACCEPT     udp  --  anywhere             anywhere            udp dpt:l2f
ACCEPT     udp  --  anywhere             anywhere            udp dpt:1021
ACCEPT     udp  --  anywhere             anywhere            udp dpt:8001
ACCEPT     udp  --  anywhere             anywhere            udp dpt:1721
ACCEPT     udp  --  anywhere             anywhere            udp dpt:sip


Второй вариант, мною откорректированный, и с которым почта НЕ приходит, выглядит так :

Chain INPUT (policy DROP)
target     prot opt source               destination        
ACCEPT     udp  --  0.0.168.192.in-addr.arpa/24  anywhere            udp dpts:10000:20000
ACCEPT     udp  --  YYY.YY.YYY.YYY       anywhere            udp dpts:10000:20000
ACCEPT     udp  --  ZZZ.ZZ.ZZZ.ZZZ       anywhere            udp dpts:10000:20000
bad_tcp_packets  tcp  --  anywhere             anywhere            
ACCEPT     0    --  0.0.168.192.in-addr.arpa/24  anywhere            
ACCEPT     0    --  localhost.localdomain  anywhere            
ACCEPT     0    --  domain.ru             anywhere            
ACCEPT     0    --  XX.XXX.XX.XX.in-addr.arpa  anywhere            
ACCEPT     0    --  anywhere             XX.XXX.XX.XX.in-addr.arpa state RELATED,ESTABLISHED
tcp_packets  tcp  --  anywhere             anywhere            
udp_packets  udp  --  anywhere             anywhere            
icmp_packets  icmp --  anywhere             anywhere            
REJECT     tcp  --  anywhere             anywhere            tcp dpt:www limit: avg 10/sec burst 5 reject-with icmp-port-unreachable
LOG        0    --  anywhere             anywhere            limit: avg 3/min burst 3 LOG level debug prefix `IPT INPUT packet died: '

Chain FORWARD (policy DROP)
target     prot opt source               destination        
bad_tcp_packets  tcp  --  anywhere             anywhere            
ACCEPT     0    --  anywhere             anywhere            
ACCEPT     0    --  anywhere             anywhere            state RELATED,ESTABLISHED
LOG        0    --  anywhere             anywhere            limit: avg 3/min burst 3 LOG level debug prefix `IPT FORWARD packet died: '

Chain OUTPUT (policy DROP)
target     prot opt source               destination        
bad_tcp_packets  tcp  --  anywhere             anywhere            
ACCEPT     0    --  localhost.localdomain  anywhere            
ACCEPT     0    --  domain.ru             anywhere            
ACCEPT     0    --  XX.XXX.XX.XX.in-addr.arpa  anywhere            
LOG        0    --  anywhere             anywhere            limit: avg 3/min burst 3 LOG level debug prefix `IPT OUTPUT packet died: '

Chain allowed (11 references)
target     prot opt source               destination        
syn_flood  tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/SYN
ACCEPT     tcp  --  anywhere             anywhere            state RELATED,ESTABLISHED
DROP       tcp  --  anywhere             anywhere            

Chain bad_tcp_packets (3 references)
target     prot opt source               destination        
REJECT     tcp  --  anywhere             anywhere            tcp flags:SYN,ACK/SYN,ACK state NEW reject-with tcp-reset
LOG        tcp  --  anywhere             anywhere            tcp flags:!FIN,SYN,RST,ACK/SYN state NEW LOG level warning prefix `New not syn:'
DROP       tcp  --  anywhere             anywhere            tcp flags:!FIN,SYN,RST,ACK/SYN state NEW

Chain icmp_packets (1 references)
target     prot opt source               destination        
DROP       tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,PSH,ACK,URG
DROP       tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,PSH,ACK,URG/NONE
ACCEPT     icmp --  anywhere             anywhere            icmp destination-unreachable
ACCEPT     icmp --  anywhere             anywhere            icmp time-exceeded
ACCEPT     icmp --  anywhere             anywhere            icmp echo-reply
ACCEPT     icmp --  anywhere             anywhere            icmp echo-request
ACCEPT     icmp --  anywhere             anywhere            limit: avg 1/sec burst 1
LOG        icmp --  anywhere             anywhere            limit: avg 1/sec burst 1 LOG level warning prefix `PING-DROP: '
DROP       icmp --  anywhere             anywhere            

Chain syn_flood (1 references)
target     prot opt source               destination        
RETURN     0    --  anywhere             anywhere            limit: avg 1/sec burst 3
DROP       0    --  anywhere             anywhere            

Chain tcp_packets (1 references)
target     prot opt source               destination        
allowed    tcp  --  0.0.168.192.in-addr.arpa/24  anywhere            tcp dpt:1021
allowed    tcp  --  anywhere             anywhere            tcp dpt:ssh
allowed    tcp  --  anywhere             anywhere            tcp dpt:smtp
allowed    tcp  --  0.0.168.192.in-addr.arpa/24  anywhere            tcp dpt:pop3 state NEW,ESTABLISHED
allowed    tcp  --  0.0.168.192.in-addr.arpa/24  anywhere            tcp dpt:imap2 state NEW,ESTABLISHED
allowed    tcp  --  anywhere             anywhere            tcp dpt:domain
allowed    tcp  --  anywhere             anywhere            tcp dpt:www
allowed    tcp  --  anywhere             anywhere            tcp dpt:https
allowed    tcp  --  0.0.168.192.in-addr.arpa/24  anywhere            tcp dpt:sip
allowed    tcp  --  YYY.YY.YYY.YYY       anywhere            tcp dpt:sip
allowed    tcp  --  ZZZ.ZZ.ZZZ.ZZZ       anywhere            tcp dpt:sip

Chain udp_packets (1 references)
target     prot opt source               destination        
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain
ACCEPT     udp  --  0.0.168.192.in-addr.arpa/24  anywhere            udp dpt:ntp
ACCEPT     udp  --  anywhere             anywhere            udp dpt:www
ACCEPT     udp  --  anywhere             anywhere            udp dpt:https
ACCEPT     udp  --  0.0.168.192.in-addr.arpa/24  anywhere            udp dpt:1021
ACCEPT     udp  --  anywhere             anywhere            udp dpt:sip


Подскажите, где тут могут быть грабли ?


Содержание

Сообщения в этом обсуждении
"iptables для почты (Exim + dovecot)"
Отправлено ALex_hha , 02-Июл-08 19:26 
А второй вариант мы должны угадать сами? ;)

"iptables для почты (Exim + dovecot)"
Отправлено Hazer , 03-Июл-08 07:57 
>А второй вариант мы должны угадать сами? ;)

Я прописал его. :-)
В середине поста есть предложение "Второй вариант, мною откорректированный, и с которым почта НЕ приходит, выглядит так :".
:-)


"iptables для почты (Exim + dovecot)"
Отправлено skgennady , 04-Июл-08 09:47 
Если политику в цепочках INPUT и OUTPUT попробовать по очереди поменять на ACCEPT, наблюдая, что происходит, то можно наверное выяснить, в какой цепочке блокируются пакеты.

"iptables для почты (Exim + dovecot)"
Отправлено Hazer , 04-Июл-08 10:39 
Всё, разобрался. У меня там было

$IPTABLES -A syn_flood -m limit --limit 100/seconds --limit-burst 150 -j RETURN
$IPTABLES -A syn_flood -j LOG --log-prefix "SYN flood: "
$IPTABLES -A syn_flood -j DROP

$IPTABLES -A allowed -p TCP --syn -j syn_flood
$IPTABLES -A allowed -p TCP -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A allowed -p TCP -j DROP

$IPTABLES -A tcp_packets -p TCP -s 0/0 --dport 25 -j allowed

И в цепочке syn_flood всё обрывалось.
Когда вместо

$IPTABLES -A allowed -p TCP --syn -j syn_flood

поставил

$IPTABLES -A allowed -p TCP --syn -j ACCEPT

всё стало нормально.
Но так и не понял, почему же не работало... :-(