Answer the question
In order to leave comments, you need to log in
How to make friends with Iptables+connlimit rules?
First question:
I close all ports and open the necessary ones.
#!/bin/bash
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -p icmp -j ACCEPT
iptables -A OUTPUT -p icmp -j ACCEPT
# ssh
iptables -A INPUT -p tcp -m tcp --dport 2222 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 2222 -m state --state ESTABLISHED,RELATED -j ACCEPT
# http
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 80 --tcp-flags FIN,SYN,RST,ACK SYN -m connlimit --connlimit-above 20 --connlimit-mask 32 -j REJECT --reject-with tcp-reset
# https
iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 443 --tcp-flags FIN,SYN,RST,ACK SYN -m connlimit --connlimit-above 20 --connlimit-mask 32 -j REJECT --reject-with tcp-reset
iptables -A OUTPUT -p tcp --sport 443 -m state --state ESTABLISHED,RELATED -j ACCEPT
# ftp 201
iptables -A INPUT -p tcp -m tcp --dport 201 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 201 -m state --state ESTABLISHED,RELATED -j ACCEPT
# post
iptables -A INPUT -p tcp -m multiport --dport 143,465,25,110,993,995 -j ACCEPT
iptables -A OUTPUT -p tcp -m multiport --sport 143,465,25,110,993,995 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 80 --tcp-flags FIN,SYN,RST,ACK SYN -m connlimit --connlimit-above 20 --connlimit-mask 32 -j REJECT --reject-with tcp-reset
does not work. If you do not set the above rules, this rule works. Please tell me how to make them friends. server {
listen 80;
server_name example.ru;
location / {
proxy_pass http://1.2.3.4:8080;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
...
iptables -A OUTPUT -p tcp --sport 8080 -j ACCEPT
telnet 1.2.3.4 8080
I get Trying 1.2.3.4...
iptables -A INPUT -p tcp -m tcp --dport 80 --tcp-flags FIN,SYN,RST,ACK SYN -m connlimit --connlimit-above 20 --connlimit-mask 32 -j REJECT --reject-with tcp-reset
iptables -A INPUT -p tcp --syn --dport 80 -m connlimit ! --connlimit-above 2 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question