1

When I start the iptables service, there is no ftp access because of a connection timeout. When I stop the iptables service, ftp works fine.

This is the current iptables data:

Update: replaced ESTABLISHED for NEW in p21 rule. The problem is still happening.

# Generated by iptables-save v1.4.7 on Sun Dec 14 23:48:26 2014
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4:2848]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP 
-A INPUT -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j DROP 
-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,PSH,ACK,URG -j DROP 
-A INPUT -i lo -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 22 -j ACCEPT 
-A INPUT -p tcp -m tcp --sport 21 -m state --state NEW -j ACCEPT 
-A INPUT -p tcp -m tcp --sport 20 -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A INPUT -p tcp -m tcp --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT 
-A OUTPUT -p tcp -m tcp --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT 
-A OUTPUT -p tcp -m tcp --dport 20 -m state --state ESTABLISHED -j ACCEPT 
-A OUTPUT -p tcp -m tcp --sport 1024:65535 --dport 1024:65535 -m state --state RELATED,ESTABLISHED -j ACCEPT 
COMMIT
# Completed on Sun Dec 14 23:48:26 2014

Could any of these lines causing this strange behavior?

-A INPUT -p tcp -m tcp --sport 21 -m state --state ESTABLISHED -j ACCEPT 
-A INPUT -p tcp -m tcp --sport 20 -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A INPUT -p tcp -m tcp --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT 
-A OUTPUT -p tcp -m tcp --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT 
-A OUTPUT -p tcp -m tcp --dport 20 -m state --state ESTABLISHED -j ACCEPT 
-A OUTPUT -p tcp -m tcp --sport 1024:65535 --dport 1024:65535 -m state --state RELATED,ESTABLISHED -

I've tried connecting to the ftp server in both passive and active modes.

3
  • Is this box an ftp client or ftp server. It isn't clear from your question? If it is a server then look closer at your rules. An incoming connection will be new.
    – Zoredache
    Dec 15, 2014 at 6:26
  • @Zoredache just tried that. Update ESTABLISHED for NEW, but it is still timing out when trying to connect with an ftp client. Dec 15, 2014 at 22:25
  • check my answer on configuring iptables for ftp. stackoverflow.com/questions/10400672/…
    – Sathish
    Dec 21, 2014 at 7:45

1 Answer 1

3

Typically where you have

-A INPUT -p tcp -m tcp --sport 21 -m state --state ESTABLISHED -j ACCEPT 

On a FTP server I would expect

-A INPUT -p tcp -m tcp --dport 21 -m state --state NEW -j ACCEPT 

to accept incoming FTP connections, which are NEW, as existing connections are already accepted by an earlier rule.

Second you'll need to ensure the FTP connection tracking module is enabled. Offhand : insmod nf_conntrack_ftp and made persistent by:

# /etc/sysconfig/iptables-config 
# Space separated list of nat helpers (e.g. 'ip_nat_ftp ip_nat_irc'), which
# are loaded after the firewall rules are applied. Options for the helpers are
# stored in /etc/modprobe.conf.
IPTABLES_MODULES="nf_conntrack_ftp"
6
  • Thanks, I'll try that in a moment. Quick question, what's the difference with that and nf_conntrack_netbios? (that's what im using right now) Dec 15, 2014 at 12:48
  • 1
    netbios is a different protocol from FTP and they each have their own helper module.
    – HBruijn
    Dec 15, 2014 at 13:04
  • Hi! Sorry for the delay, just tested your recommendation, still this is the ftp client response: Connection timed out - any ideas? Dec 15, 2014 at 22:24
  • it seems it was an order issue. I moved the 21 port rule before the 80 port rule and it worked. Any ideas? Dec 16, 2014 at 2:39
  • When you changed the configuration the first time (i.e., --sport 21 to --dport 21), did you remember to reload the iptables rules?
    – pepoluan
    Dec 17, 2014 at 5:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .