An external IP is connecting to my mailserver VM every second and I just want to block this IP immediately without dropping existing connections.
So I apply a DROP rule. I even reloaded all the iptables rules, but the external IP is still connecting to the mail server.
I used conntrack to stop existing connections.
iptables -F
iptables -X
iptables -t nat -F
echo 1 > /proc/sys/net/ipv4/ip_forward
for IP in <IP_LIST> ; do
iptables -I INPUT -s $IP -j DROP
conntrack -D -s $IP
done
# Other rules follow (rule on INPUT are all specified to ports other than the mail ports)
# last rule
iptables -A INPUT -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
The result of conntrack -L -s <ATTACKERIP>
is
tcp 6 10 TIME_WAIT src=<ATTACKERIP> dst=<MYIP> sport=23305 dport=587 src=10.0.1.109 dst=10.0.0.5 sport=587 dport=23305 [ASSURED] mark=0 use=1
Relevant output from
iptables -L
iptables -L -t nat
is
iptables -t nat -D PREROUTING -i vmbr0 -p tcp -d <MYPUBLICIP> --dport 587 -j DNAT --to 10.0.1.109:587
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP all -- <ATTACKERIP> anywhere
DNAT tcp -- anywhere <MYDOMAIN> tcp dpt:submission to:10.0.1.109:587
What else should I do to DROP new connections immediately?