LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 01-27-2007, 11:25 AM   #1
gabsik
Member
 
Registered: Dec 2005
Location: This planet
Distribution: Debian,Xubuntu
Posts: 567

Rep: Reputation: 30
iptables and passive ftp


I'm using proftpd and i set in proftpd.conf as passive ports 65520-65535 15 ports.i could set iptables to just accept connections on those 15 ports , but i wouldn't open a hole of 15 ports on the firewall .My question is :can i consider those 15 ports in a state of ESTABLISHED,RELATED or are they in a state of NEW ?Or what would you advice to do ???Thanks !!!!
 
Old 01-27-2007, 01:27 PM   #2
chort
Senior Member
 
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660

Rep: Reputation: 76
Quote:
Originally Posted by gabsik
My question is :can i consider those 15 ports in a state of ESTABLISHED,RELATED or are they in a state of NEW ?Or what would you advice to do ???Thanks !!!!
No, not unless there's a module for iptables that can inspect FTP traffic at layer7 and decode PORT/PASV commands to determine which data channels are related to which command channels.

Also, you need a much bigger port range than 15 ports. Most FTP daemons will bind to a new socket for each data transmission, so a single FTP login can easily use multiple ports for passive connections if the client is doing lots of directory listings or downloads. I'd use a minimum of 100 ports for the passive range.
 
Old 01-27-2007, 06:29 PM   #3
TheRealDeal
Member
 
Registered: Jun 2003
Location: Central Coast, NSW, Australia
Distribution: Gentoo
Posts: 438

Rep: Reputation: 30
Hi,

The modules you can use are called ip_conntrack and ip_conntrack_ftp.

If you modprobe these two iptables will track and allow the ports that your ftp client wants to use.

>Craig
 
Old 01-27-2007, 08:32 PM   #4
chort
Senior Member
 
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660

Rep: Reputation: 76
Quote:
Originally Posted by TheRealDeal
Hi,

The modules you can use are called ip_conntrack and ip_conntrack_ftp.

If you modprobe these two iptables will track and allow the ports that your ftp client wants to use.

>Craig
As long as you don't encrypt the command channel
 
Old 01-27-2007, 11:27 PM   #5
gabsik
Member
 
Registered: Dec 2005
Location: This planet
Distribution: Debian,Xubuntu
Posts: 567

Original Poster
Rep: Reputation: 30
I had increase the passive ftp port range in proftpd configuration file with directive PasssivePorts 65500 65535 and in i accept them in iptables just if they are in a state of ESTABLISHED,RELATED .... that's right isn'it ????(all modules are loaded)
 
Old 01-27-2007, 11:33 PM   #6
TheRealDeal
Member
 
Registered: Jun 2003
Location: Central Coast, NSW, Australia
Distribution: Gentoo
Posts: 438

Rep: Reputation: 30
Should be it, this is how I start mine on my ftp server...

modprobe iptables
modprobe ip_conntrack
modprobe ip_conntrack_ftp

then my iptables rule for ftp is basically -m multiport --dport 20,21 for both tcp and udp. Then I have the ESTABLISHED,RELATED rule. Works a treat.

>Craig
 
Old 01-28-2007, 12:51 AM   #7
gabsik
Member
 
Registered: Dec 2005
Location: This planet
Distribution: Debian,Xubuntu
Posts: 567

Original Poster
Rep: Reputation: 30
Yeah that's right i do accept ESTABLISHED,RELATED in the first place as well .... a ftp connection is not going to start up on those unprivileged ports so ....
 
Old 01-28-2007, 12:57 AM   #8
TheRealDeal
Member
 
Registered: Jun 2003
Location: Central Coast, NSW, Australia
Distribution: Gentoo
Posts: 438

Rep: Reputation: 30
As long as your server is setup to listen on a certain port and your client attempts to hit that certain port it should be fine. Obviously allowing the initial ports through the firewall.

For example, my ftp server uses the default ports 20 & 21 to do the initial connect, the ftp server then uses the random high ports as it does. My firewall allows ACCEPT's ports 20,21, and ESTABLISHED,RELATED is applied. The modules ip_conntrack and ip_conntrack_ftp allows the firewall to track which random high ports are being used, and 'tracks' it so the firewall doesn't block any traffic that it isn't meant to.

Is this what u mean?

Craig
 
Old 01-28-2007, 04:15 AM   #9
chort
Senior Member
 
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660

Rep: Reputation: 76
Quote:
Originally Posted by TheRealDeal
For example, my ftp server uses the default ports 20 & 21 to do the initial connect, the ftp server then uses the random high ports as it does.
Sorry, but this is wrong.

Port 21/tcp is the listener on the FTP server that accepts command channel connections. The protocol knows how to multiplex many command sessions on the same port. When a client establishes a connection, they do it solely over the command channel. If they client needs to send or receive data (remember that directory listing output is considered data) then one of two things happens:

1.) FTP client is using Active mode FTP and sends a PORT command to the server. The server than connects back to the client on the client's port 20/tcp and delivers the data. This socket is used for all the other data that is transfered (unless the client requests passive mode).
2.) FTP client is using Passive mode FTP, in which case the server sends a PASV command telling the client what IP and port to connect to. The client then connects to this new IP/port on the server and uses this socket for the current data transfer. Depending on the server implementation this may (not sure if RFCs allow this) reuse the socket, or might send the client a new PASV command for the next input or output.

FTP servers do not need port 20/tcp to be open, and presumably the contrack_ftp module will detect when a client (on your machine) issues a PORT command and automatically allow the inbound connection from the server.
 
  


Reply



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
FTP server stuck in passive with iptables running. TheRealDeal Linux - Security 5 02-24-2005 04:57 PM
How do I set my FTP server to accept passive FTP? imsam Linux - Newbie 3 12-12-2004 06:22 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
iptables and passive FTP behind the nat radix Linux - Security 5 09-16-2003 07:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:14 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration