Error
As you can see, the only difference between the working and the not working configuration is -m conntrack --ctstate NEW,ESTABLISHED,RELATED
. If I use -m conntrack --ctstate NEW,ESTABLISHED
it does not work either... But Why?!
After few tests, I have noticed that every rules using conntrack
does not work...
Can you explain me why is SSH blocked by iptables
only when I use conntrack
?
Thanks :-)
Working configuration
#!/bin/bash SERVER_IP="X.X.X.X" iptables -F iptables -X # Setting default filter policy iptables -P INPUT DROP iptables -P OUTPUT ACCEPT iptables -P FORWARD DROP # Allow previous connections iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT iptables -A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # Allow unlimited traffic on loopback iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT # Allow incoming ssh only iptables -A INPUT -p tcp -s 0/0 -d ${SERVER_IP} --dport 22 -j ACCEPT iptables -A INPUT -p tcp -s 0/0 -d ${SERVER_IP} --dport 22 -j LOG --log-prefix "[ACCEPT INPUT][SSH] " # make sure nothing comes or goes out of this box iptables -A INPUT -j LOG --log-prefix "[DROP INPUT][DEFAULT] " iptables -A INPUT -j DROP
Not working configuration
#!/bin/bash SERVER_IP="X.X.X.X" iptables -F iptables -X # Setting default filter policy iptables -P INPUT DROP iptables -P OUTPUT ACCEPT iptables -P FORWARD DROP # Allow previous connections iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT iptables -A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # Allow unlimited traffic on loopback iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT # Allow incoming ssh only iptables -A INPUT -p tcp -s 0/0 -d ${SERVER_IP} --dport 22 -m conntrack --ctstate NEW,ESTABLISHED,RELATED -j ACCEPT iptables -A INPUT -p tcp -s 0/0 -d ${SERVER_IP} --dport 22 -m conntrack --ctstate NEW,ESTABLISHED,RELATED -j LOG --log-prefix "[ACCEPT INPUT][SSH] " # make sure nothing comes or goes out of this box iptables -A INPUT -j LOG --log-prefix "[DROP INPUT][DEFAULT] " iptables -A INPUT -j DROP
[EDIT]
How am I sure that conntrack is involved?
Because in the log file I can see something like this :
[DROP][INPUT] IN=eth0 OUT= MAC=0c:c4:...:00 SRC=X.X.X.X DST=X.X.X.X LEN=67 TOS=0x08 PREC=0x20 TTL=41 ID=39550 DF PROTO=TCP SPT=51093 DPT=22 WINDOW=229 RES=0x00 ACK PSH URGP
[DROP][INPUT]
is the last rule in my iptables configuration file.
[DROP][INPUT]
, so this is my default rule.