S
S
Sheryorg2015-01-19 15:12:55
Nginx
Sheryorg, 2015-01-19 15:12:55

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

rule
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.
Question 2:
Is there a virtual host on nginx
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;

        }
...

In iptables I add to the above-mentioned rules iptables -A OUTPUT -p tcp --sport 8080 -j ACCEPT
I try from the server telnet 1.2.3.4 8080I get Trying 1.2.3.4...
Everything works on empty rules.
PS I can't make a forward from 80 to 8080 using iptables. There are also virtual hosts.
I figured out the first question, it works under the following rules:
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

The second question has not yet been resolved.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2015-01-19
@BuriK666

iptables -A OUTPUT -p tcp --dst 1.2.3.4 --dport 8080 -j ACCEPT

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question