LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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
 
Search this Thread
Old 11-21-2012, 05:16 PM   #1
superkikim
LQ Newbie
 
Registered: Aug 2006
Posts: 8

Rep: Reputation: 0
Question iptables rules for inbound and outbound FTP connections


Hi,

I know iptables is a lot discussed here around, but I couldn't quite find the global answer to my problem yet.

First:

Can anyone explain to me how does FTP request get out from FTP client, and get in to FTP Server, and then how they get back out from server back in to client ? On what ports and why ?

Second:

That explained will help a lot I'm sure. Because to define the correct rules, it seems essential to understand how the protocol works.

These are the rules I set for my FTP server, and for this server to get out with its ftp client for backup purpose:

Let's say this rules are on SERVER A, and my backup server is SERVER B:
Code:
# Allow incoming FTP connections
iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d $SERVER_IP --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -s $SERVER_IP --sport 21 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT

iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d $SERVER_IP --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -p tcp -s $SERVER_IP --sport 1024:65535 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT

iptables -A OUTPUT -p tcp -s $SERVER_IP --sport 20 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d $SERVER_IP --dport 20 -m state --state ESTABLISHED -j ACCEPT

# Allow outgoing FTP connections
iptables -A OUTPUT -p tcp -s $SERVER_IP --dport 21 -d 0/0 --sport 1024:65535 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 --dport 1024:65535 -d $SERVER_IP --sport 21 -m state --state ESTABLISHED -j ACCEPT

iptables -A OUTPUT -p tcp -s $SERVER_IP --dport 20 -d 0/0 --sport 1024:65535 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 --dport 1024:65535 -d $SERVER_IP --sport 20 -m state --state ESTABLISHED,RELATED -j ACCEPT
My problem is that I can connect from SERVER A to SERVER B with FTP, and I can login successfully.

But then, if I do an "ls" for example, the reply does not get in. If I remove all rules and accept all, it works. Therefore, these rules are wrong somewhere.... But I can't figure out where. If anyone can help ? and most of all, explain, for me to learn.

Note that my default policy is DROP for INPUT, OUTPUT and FORWARD.
 
Old 11-22-2012, 10:03 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
you really want to look at using connection tracking proeprly here, it makes it pretty simple:

http://rackerhacker.com/2007/07/01/a...ough-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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] inbound/outbound connections required for NTP? borgy95 Linux - Networking 8 02-08-2013 09:33 AM
Adjust iptables to only inbound syn connections guga0001 Linux - Security 1 04-07-2011 08:02 PM
Iptables Control Outbound Connections - need help xoros Linux - Networking 5 04-29-2009 06:30 AM
No Shorewall/IPtables: not inbound connections allowed psychobyte Mandriva 3 05-25-2005 02:29 AM
cannot make outbound anonymous ftp connections kvankawala Linux - Software 1 03-23-2004 01:30 PM


All times are GMT -5. The time now is 05:12 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 Google+: linuxquestions
Open Source Consulting | Domain Registration