LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-07-2008, 05:45 PM   #1
bk2008
LQ Newbie
 
Registered: Apr 2008
Posts: 4

Rep: Reputation: 0
IPTABLES configuration for Passive FTP connection


Hello Everyone,

My FTP users can login but can not send/receive data when I use the below iptables configuration.
Can someone make any recommendation to resolve the FTP connection issue.
Thanks for your help.

:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [131962:7397220]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
-A RH-Firewall-1-INPUT -p ipv6-crypt -j ACCEPT
-A RH-Firewall-1-INPUT -p ipv6-auth -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
 
Old 04-07-2008, 06:17 PM   #2
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 98
You ned to turn on FTP connection tracking. Here is a quick howto:

http://www.cyberciti.biz/faq/iptable...s-not-working/

HTH

Forrest
 
Old 04-07-2008, 06:17 PM   #3
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569

Rep: Reputation: 54
Are you loading the correct connection tracking modules in your /etc/sysconfig/iptables-config file? Something like this:-
IPTABLES_MODULES="ip_conntrack_ftp nf_conntrack_netbios_ns"
 
Old 04-07-2008, 06:19 PM   #4
win32sux
Moderator
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
Quote:
Originally Posted by bk2008 View Post
My FTP users can login but can not send/receive data when I use the below iptables configuration.
Can someone make any recommendation to resolve the FTP connection issue.
Thanks for your help.

:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [131962:7397220]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
-A RH-Firewall-1-INPUT -p ipv6-crypt -j ACCEPT
-A RH-Firewall-1-INPUT -p ipv6-auth -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
The rule you have for port 20 is not necessary (only port 21 is). The RELATED,ESTABLISHED rule will pick-up the client's data connection, which won't happen on port 20 anyway (not in passive mode). Your issue is most likely caused by not having FTP connection tracking support in your kernel, or not having the FTP connection tracking module loaded. Try doing a:
Code:
modprobe ip_conntrack_ftp
BTW, I'm moving this to Networking, as it isn't a security issue.

Last edited by win32sux; 04-07-2008 at 06:29 PM.
 
Old 04-07-2008, 06:23 PM   #5
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 98
Sorry, pasted the wrong URL. That one may help, but this one is better:

http://www.cyberciti.biz/tips/how-do...g-feature.html

HTH

Forrest
 
Old 04-07-2008, 06:51 PM   #6
bk2008
LQ Newbie
 
Registered: Apr 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Adding: ESTABLISHED,RELATED -m tcp --sport 1024: ...

I was reading on the net and I see suggestions for opening ports greater than 1024.

Do you think adding this iptables line will resolve this FTP connection issue?

iptables -I RH-Firewall-1-INPUT 9 -p tcp -m state --state ESTABLISHED,RELATED -m tcp --sport 1024: --dport 1024: -j ACCEPT

Thanks for your help.
 
Old 04-07-2008, 07:10 PM   #7
win32sux
Moderator
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
Quote:
Originally Posted by bk2008 View Post
I was reading on the net and I see suggestions for opening ports greater than 1024.
That definitely made sense like 10 years ago when we didn't have connection tracking. Today, such a rule would be completely insane. Connection tracking makes this sort of security nightmare totally unnecessary. As has already been said, for FTP services you only need port 21 open.

Quote:
Do you think adding this iptables line will resolve this FTP connection issue?

iptables -I RH-Firewall-1-INPUT 9 -p tcp -m state --state ESTABLISHED,RELATED -m tcp --sport 1024: --dport 1024: -j ACCEPT
No, at least not without FTP connection tracking. See, for Netfilter to know that the state of those FTP data connection packets is RELATED or ESTABLISHED it would need to have FTP connection tracking support enabled in the first place - which you apparently don't have AFAICT. Note that if this rule would work, it would be redundant, as it would imply that your current RELATED,ESTABLISHED rule was working originally. You won't need to make any additional RELATED,ESTABLISHED rules once you've got FTP connection tracking working.

You could remove the state matches from the rule and do it like we're in 1998 like:
Code:
iptables -I RH-Firewall-1-INPUT -p tcp -m tcp --sport 1024: --dport 1024: -j ACCEPT
And that should work - but it's a terrible way to address your problem, and is NOT recommended.

Your issue is best addressed by tracking the FTP connections, not by poking giant holes in your firewall.

Last edited by win32sux; 04-07-2008 at 07:36 PM.
 
Old 04-07-2008, 11:17 PM   #8
bk2008
LQ Newbie
 
Registered: Apr 2008
Posts: 4

Original Poster
Rep: Reputation: 0
FTP connection tracking module

Thank you for your help.

I was not familiar with FTP connection tracking module. As soon as I typed:

modprobe ip_conntrack_ftp


FTP starts working - no problem.

Do I need to reload this module or retype this command every time I restart the server?

Is there some entry level resources about tracking module that I can read on the net?

Thanks again - I appreciate everyone's help.
 
Old 04-07-2008, 11:25 PM   #9
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569

Rep: Reputation: 54
As I posted earlier, add this to your /etc/sysconfig/iptables.conf file:-
Code:
IPTABLES_MODULES="ip_conntrack_ftp"
This will ensure that connection tracking is loaded when your firewall starts.
 
Old 04-08-2008, 12:37 AM   #10
bk2008
LQ Newbie
 
Registered: Apr 2008
Posts: 4

Original Poster
Rep: Reputation: 0
iptables.conf

I'm running CentOS 5 and the file /etc/sysconfig/iptables.conf does not exist.

Should I create a new file?

Is there a default configuration file I can look for?

Thanks
 
Old 04-08-2008, 12:43 AM   #11
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569

Rep: Reputation: 54
Sorry, the file is called iptables-conf, not .conf. Just look for files in /etc/sysconfig starting with iptables.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables / Passive FTP Jay_Drummond Linux - Software 2 02-20-2012 04:53 PM
IPTables :: Allowing passive FTP Swakoo Linux - Security 4 04-19-2007 10:26 PM
iptables and passive ftp gabsik Linux - Networking 8 01-28-2007 04:15 AM
iptables and passive ftp behind NAT radix Linux - Security 7 10-21-2003 02:06 PM
IPtables and Passive FTP MatrixIII007 Linux - Security 2 10-16-2003 08:10 AM


All times are GMT -5. The time now is 02:36 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration