I am using vsftpd with active ftp. I have module "ip_conntrack_ftp" (in /etc/sysconfig/iptables-config) on and port 21 is open. Connecting with FTP works, but FTPS doesn't. I can login but get no listing:
227 Entering Passive Mode
LIST -a
When stopping the firewall it works (I mean iptables on the ftp server itself). I read in http://www.experts-exchange.com/Software/Server_Software/File_Servers/FTP/Q_22418222.html that it's not possible to use FTPS with active FTP. Is this true?
My iptables configuration:
*filter
:INPUT DROP [15:2752]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [132:159725]
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/255.0.0.0 -i ! lo -j REJECT --reject-with icmp-port-unreachable
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 21 -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m tcp --dport 990 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 989 -j ACCEPT
COMMIT
I have run in to this issue. It looks like you need to open up the ftp data transfer range of ports when using FTP with explicit TLS/SSL. Try the following:
You need to explicitly allow access to ftp-data incoming port range. Nic's answer recommends statically opening the full range, but that might be too open. Besides,
RELATED
is useless in this case because conntrack_ftp module can't snoop an encrypted control connection.My recommendation is to use the recent match. Try the following:
The
--set
rule will be matched by control connection and will add the source ip toftpdata
recent list. The--update
rule will do most of the interesting work:ftpdata
list (--update
) and the source addres was seen within the last 1800 seconds (--seconds 1800
).--update
).ftpdata
list not seen in the last 1800 will be removed (--reap
).So, after the control connection was
ACCEPT
ed, you have 1800 seconds to initiate data connections. After that time you will need to reopen the control connection to get the source address re-added to theftpdata
list.An inconvenience of this solution if that ftp clients would not be able to initiate data connections after 1800 seconds of their last control connection establisment time. You could use 24h if you like, it will be less opened anyways than having the full port range permanently opened. You can also have a sequence like:
to refresh the source address whenever an established control connection packet comes in but I prefer to have the
--state RELATED,ESTABLISHED
rule near the top.Check also
accept_timeout
,data_connection_timeout
andidle_session_timeout
params of vsftpd.conf.Add the below line into
/etc/sysconfig/iptables
Restart the
iptables