C
C
CraSS2014-03-21 18:57:12
Debian
CraSS, 2014-03-21 18:57:12

Strange behavior of iptables -F - what is the reason?

Colleagues, I seem to have a VPS with Desbian, iptables rules are written there when raising the network interface. those. the script with the rules is here: /etc/network/if-up.d.

Here's what's in the script:

#!/bin/sh
### Скрипт конфигурации IPTables ###
# Очищаем предыдущие записи
iptables -F
# Установка политик по умолчанию
iptables -P INPUT DROP
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
# Разрешаем локальный интерфейс
iptables -A INPUT -i lo -j ACCEPT
# Простая защита от DoS-атаки
iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
# Защита от спуфинга
iptables -I INPUT -m conntrack --ctstate NEW,INVALID -p tcp --tcp-flags SYN,ACK SYN,ACK -j REJECT --reject-wit
h tcp-reset
# Защита от попытки открыть входящее соединение TCP не через SYN
iptables -I INPUT -m conntrack --ctstate NEW -p tcp ! --syn -j DROP
# Закрываемся от кривого icmp
iptables -I INPUT -p icmp -f -j DROP
# REL, ESTB allow
iptables -A INPUT -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p udp -m state --state RELATED,ESTABLISHED -j ACCEPT
# Разрешаем рабочие порты
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A INPUT -p udp --sport 53 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 110 -j ACCEPT
iptables -A INPUT -p tcp --dport 143 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# Разрешение главных типов протокола ICMP
iptables -A INPUT -p icmp --icmp-type 3 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 11 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 12 -j ACCEPT

Everything seems to be good and working. However, there was a need for me to experiment, for this I wanted to reset all the rules. It seems that there is nothing simpler: iptables -F and everything is ready...
However, when executing this command from the console, the droplet either hangs or simply does not let anyone in. ssh falls off, the site is not reachable... It only helps to disable/enable the droplet from the hoster's panel
Actually, the question. What's happening? And how then to clear the iptables rules?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vlad Zhivotnev, 2014-03-21
@inkvizitor68sl

# Установка политик по умолчанию
iptables -P INPUT DROP

What did you expect?)
When you do -F with this default policy, all incoming traffic starts dropping.

K
kresska, 2014-08-15
@kresska

The policy remains, but the rules do not. As a result, "Kill everyone, spare no one!"

K
Kamil, 2019-09-25
@Lakika

Well, or like this:
iptables -P INPUT ACCEPT; iptables -F

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question