iptables está bloqueando apenas algumas conexões para a porta 80

0

Estou executando um servidor Ubuntu 15.10 com um servidor nginx nele. Eu usei a seguinte configuração do iptables para permitir as conexões da porta 80 e da porta 443:

*filter

# Allow all loopback (lo0) traffic and reject traffic
# to localhost that does not originate from lo0.
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -s 127.0.0.0/8 -j REJECT

# Allow ping.
-A INPUT -p icmp -m state --state NEW --icmp-type 8 -j ACCEPT

# Allow SSH connections.
-A INPUT -p tcp --dport 950 -m state --state NEW -j ACCEPT

# Allow HTTP and HTTPS connections from anywhere
# (the normal ports for web servers).
-A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
-A INPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT

# Allow mail
-A INPUT -p tcp --dport 25 -m state --state NEW -j ACCEPT

# Allow inbound traffic from established connections.
# This includes ICMP error returns.
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Log what was incoming but denied (optional but useful).
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables_INPUT_denied: " --log-level 7

# Reject all other inbound.
-A INPUT -j REJECT

# Log any traffic which was sent to you
# for forwarding (optional but useful).
-A FORWARD -m limit --limit 5/min -j LOG --log-prefix "iptables_FORWARD_denied: " --log-level 7

Como confirmado por iptables -L :

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
REJECT     all  --  127.0.0.0/8          anywhere             reject-with icmp-port-unreachable
ACCEPT     icmp --  anywhere             anywhere             state NEW icmp echo-request
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:950 state NEW
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http state NEW
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https state NEW
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:smtp state NEW
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
LOG        all  --  anywhere             anywhere             limit: avg 5/min burst 5 LOG level debug prefix "iptables_INPUT_denied: "
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
LOG        all  --  anywhere             anywhere             limit: avg 5/min burst 5 LOG level debug prefix "iptables_FORWARD_denied: "
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Isso funciona ... geralmente. Algumas conexões para a porta 80 estão bloqueadas de qualquer maneira ( /var/log/kern.log ):

Apr 15 11:50:47 while kernel: [6038916.249973] iptables_INPUT_denied: IN=eth0 OUT= MAC=04:01:a4:e4:4d:01:84:b5:9c:fa:10:30:08:00 SRC=82.101.237.77 ST=xxx.xxx.xxx.xxx LEN=40 TOS=0x08 PREC=0x00 TTL=54 ID=2368 DF PROTO=TCP SPT=51182 DPT=80 WINDOW=0 RES=0x00 RST URGP=0

Por que o iptables está fazendo isso?

    
por Overv 15.04.2016 / 17:52

1 resposta

0

Sua entrada de log de exemplo é para um pacote TCP com o sinalizador de redefinição declarado.

Para conexões TCP, o Linux tende a usar uma sequência fechada "semi-duplex" onde cada lado da sessão pode iniciar a terminação de conexão através de um único handshake FIN-ACK de 2 vias (que coloca a conexão no estado CLOSE_WAIT) de um aperto de mão FIN-ACK completo de 4 vias.

É provável, e muito comum, que o seu lado pense que uma sessão TCP anterior foi fechada e esqueceu-se disso. Em seguida, 82.101.237.77 tentou redefinir a conexão, que acabou sendo "iptables_INPUT_denied".

Resumo: não há nada errado.

    
por Doug Smythies 22.04.2016 / 23:15