LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 11-09-2009, 04:08 AM   #1
MheAd
Member
 
Registered: Jun 2007
Distribution: Ubuntu 14.04
Posts: 186

Rep: Reputation: 36
Iptables and FTP when the server is listening on a non-standard port?


Hi there,
I'm using iptables with modules ip_contrack_ftp to be able to use passive ftp. It works well as long as port 21 is being used as listening port. Is there any way to make it work when I configure my ftp server (vsftpd) to listen on an alternative port, lets say 21001 or something?
The helper module only seems to be working properly with the standard port, so I was wondering whether there was a way to "tell it" that another port is being used? I mean, of course I make a rule in fw to allow traffic to the alternative port, but once it's time to start passive connection, then the iptable module cannot handle it properly. I could solve the problem by making a range of passive ports in the ftp-server configuration and allow the incoming traffic to them, but then using helper modules doesn't make any sense. I just want to allow the traffic to the listening port and then want the ip_contrack_ftp module to take care of the rest. This is what I do today - but only port 21 seems to be working. Is there a way to do this with a non-standard ftp port?

Any ideas?
Thanks in advance!

Last edited by MheAd; 11-09-2009 at 04:21 AM.
 
Old 11-09-2009, 07:36 AM   #2
bhaslinux
Member
 
Registered: Oct 2003
Location: UnitedKingdom
Distribution: Debian Bullseye
Posts: 357

Rep: Reputation: 49
it will be lot more easier if you can give us the iptables rules you have used.
iptables -t nat -L
iptables -L
 
Old 11-09-2009, 08:33 AM   #3
MheAd
Member
 
Registered: Jun 2007
Distribution: Ubuntu 14.04
Posts: 186

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by bhaslinux View Post
it will be lot more easier if you can give us the iptables rules you have used.
iptables -t nat -L
iptables -L
I've not set anything on nat-table.

This is an example of my rules, I may add other stuff, but you can understand the point by reading the rows bellow.

Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT all -- localhost anywhere
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh state NEW
ACCEPT tcp -- anywhere anywhere tcp dpt:ftp state NEW

Chain FORWARD (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Note the last rule in the INPUT, (ftp=21). I want to change my listening port to 21001, then I would, of course, replace that rule with --dport 21001 - but it doesn't work then, the contrack_ftp module works only with passive ftp if 21 is used as the listening port. Is there a way to make it work with 21001 for instance, and how im that case?

So, I simply wonder whether there is a way to use iptables ftp-helper modules with an alternative listening port (instead of port 21).

Last edited by MheAd; 11-09-2009 at 08:43 AM.
 
Old 11-09-2009, 12:29 PM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Specify the port you want the module to use when you load it. Example:
Code:
modprobe ip_conntrack_ftp ports=21001
 
Old 11-09-2009, 01:41 PM   #5
MheAd
Member
 
Registered: Jun 2007
Distribution: Ubuntu 14.04
Posts: 186

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by win32sux View Post
Specify the port you want the module to use when you load it. Example:
Code:
modprobe ip_conntrack_ftp ports=21001
Thanks for the reply!
However, it doesn't seem to be working.
Perhaps another module needs a similar option.
ip_conntrack_ftp is not the only one iptables module I'm loading. I'm even loading ip_conntrack_netbios_ns and ip_nat_ftp.

Also, is there any way I could put these options to be automatically loaded (these modules are loaded by IPTABLES_MODULES variable in /etc/sysconfig/iptables_config). I was hoping that something like

options ip_conntrack_ftp ports=21001

in /etc/modprobe.conf would do it, but obviously does not.

Either way, even when manually loaded, ip_conntrack_ftp with ports=21001 option is not enough for proper function of iptables against listening port 21001.

Any more ideas?

Thanks in advance!

Last edited by MheAd; 11-09-2009 at 01:42 PM.
 
Old 11-11-2009, 05:16 PM   #6
shizzles
LQ Newbie
 
Registered: Jun 2005
Location: Chicago
Distribution: Ubuntu Server & Debian 6
Posts: 23

Rep: Reputation: 1
Hey,


So as of right now your iptables are allowing traffic on port 22 and port 21. You need to add rules so that it also allow passive ftp traffic (RELATED).

http://www.sns.ias.edu/~jns/wp/2006/...-tracking-ftp/

Those rules should help.
 
  


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
sshd server not listening to port 22 apulu Linux - Newbie 17 02-25-2008 05:16 AM
Find the port on which Apache server is listening sharathkv Programming 5 04-14-2007 02:11 PM
Howto do Secured ssh from port https or port80(standard) to ssh d listening port 22 ? Xeratul Linux - General 4 11-23-2006 06:09 AM
How to change listening port of echo server [RH9]? immer Linux - Networking 5 11-29-2003 04:30 PM
X server crashing - port listening time112852 Linux - Software 9 10-06-2003 12:20 PM

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

All times are GMT -5. The time now is 09:14 AM.

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