LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 07-21-2004, 04:24 AM   #1
kola
Member
 
Registered: Jul 2004
Location: Christchurch, New Zealand
Distribution: FC2, Debian 'Sarge'
Posts: 64

Rep: Reputation: 15
ftp server ports - conntrack


Hi, just trying to get my head around ftp and how to allow connections to a server. I have an ftp deamon running which looks for connections on port 21.

So, I figure i need to at least accept connections on this port? Then i need to enable another port(s) for the data channel, yes? This depends on whether we are using active or passive transfers....this is where i get confused.

Passive is more dangerous to the server but more client-friendly from what i can make out. I also read i think that the ip_conntrack_ftp module can read what ports the clients want to use and open them accordingly, instead of having to open the whole upper range. Is this correct?

It would be great if someone with an ftp server could show me just the few lines that are used for ftp connections. My firewall is still basic but im building on it slowly and this would help get the low stumbling blocks out the way.

cheers

ps: the ftp server is on the gateway machine, using iptables. 1.2.5
 
Old 07-21-2004, 04:53 AM   #2
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
This link was posted by Capt_Caveman. I think it will answer all your queries. It is for client connections but you would be able to modify those rules for your ftp server connections.

Last edited by ppuru; 07-21-2004 at 04:55 AM.
 
Old 07-21-2004, 06:07 AM   #3
kola
Member
 
Registered: Jul 2004
Location: Christchurch, New Zealand
Distribution: FC2, Debian 'Sarge'
Posts: 64

Original Poster
Rep: Reputation: 15
I have to admit i dont completely understand everything hes writing here.

Whats the difference between an sport and a dport?
 
Old 07-21-2004, 06:26 AM   #4
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
sport is the source port - the port from where the packet originates
dport is the destination port - the port that the packet si destined for.

Your iptable rule to allow passive ftp-data should be like
Code:
iptables -A INPUT -i <external interface> -p tcp --dport 1024: -j ACCEPT -m state --state RELATED,ESTABLISHED
iptables -A OUTPUT -o <external interface> -p tcp --dport 1024: -j ACCEPT
 
Old 07-21-2004, 06:42 AM   #5
kola
Member
 
Registered: Jul 2004
Location: Christchurch, New Zealand
Distribution: FC2, Debian 'Sarge'
Posts: 64

Original Poster
Rep: Reputation: 15
Ah ok, so before that i need something for the port 21 too?
Code:
iptables -A INPUT -i ppp0 -p tcp --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o ppp0 -p tcp --dport 21 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
Something like that?
 
Old 07-23-2004, 03:10 AM   #6
kola
Member
 
Registered: Jul 2004
Location: Christchurch, New Zealand
Distribution: FC2, Debian 'Sarge'
Posts: 64

Original Poster
Rep: Reputation: 15
Well, i got passive ftp working with this:
Code:
$IPTABLES -A INPUT -i ppp0 -p tcp --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT
$IPTABLES -A OUTPUT -o ppp0 -p tcp --dport 21 -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -i ppp0 -p tcp --dport 1024: -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A OUTPUT -o ppp0 -p tcp --dport 1024: -j ACCEPT
The third line is apparently supposed to work without the NEW according to the link posted above,but, well it doesnt
So as far as i can tell, what this is doing is showing all ports > 1024 as closed? How safe is this? Will it let any NEW packet in, or does it only allow NEW packets that have previously been ok'd through port 21?

If someone could clear up my confusion or post something that works better that would be great

thanks
 
Old 07-23-2004, 07:14 AM   #7
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
you are right kola, the NEW state is required.

If you are using vsftpd, you can set the pasv_max_port and pasv_min_port to regulate data connections to those ports and fine tune your firewall rules like
Code:
$IPTABLES -A INPUT -i ppp0 -p tcp --dport 54776:54875 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
 
  


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 and SSH server ports IBall Linux - Networking 1 12-01-2005 04:29 AM
configuring it as a router ftp, my sql,web server, and open and close ports with masq digitalf Mandriva 1 09-04-2004 04:43 AM
how do i change ports for ftp server Kertais909 Linux - Networking 3 07-21-2004 04:18 AM
FTP Server..... opening of ports and all that Daniel Linux - Networking 2 12-12-2002 09:43 AM
ipchains, ftp from client to non-ftp ports atari303 Linux - Networking 2 11-08-2002 02:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 08:20 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