LinuxQuestions.org
Visit Jeremy's Blog.
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 05-20-2008, 05:51 AM   #1
the_gripmaster
Member
 
Registered: Jul 2004
Location: VIC, Australia
Distribution: RHEL, CentOS, Ubuntu Server, Ubuntu
Posts: 364

Rep: Reputation: 38
iptables: connect to a FTP server


On my mail server I am running iptables with a default policy of DROP:

Code:
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT DROP
/sbin/iptables -P FORWARD DROP
Now I am trying to connect to my FTP server (192.168.100.12) from my mail server using the rules below:

Code:
/sbin/iptables -A INPUT -i eth0 -p tcp -s 192.168.100.12 --sport ftp -m state --state NEW,ESTABLISHED -j ACCEPT
/sbin/iptables -A OUTPUT -o eth0 -p tcp -d 192.168.100.12 --dport ftp -m state --state NEW,ESTABLISHED -j ACCEPT
/sbin/iptables -A INPUT -i eth0 -p tcp -s 192.168.100.12 --sport ftp-data -m state --state NEW,ESTABLISHED -j ACCEPT
/sbin/iptables -A OUTPUT -o eth0 -p tcp -d 192.168.100.12 --dport ftp-data -m state --state NEW,ESTABLISHED -j ACCEPT
I can connect fine. But when I run any command like dir, I get the following error after a long delay:

Code:
ftp> dir
227 Entering Passive Mode (192,168,100,12,113,135)
ftp: connect: Connection timed out
Turning passive mode off, I get (after a long delay):

Code:
ftp> passive
Passive mode off.
ftp> dir
200 PORT command successful. Consider using PASV.
425 Failed to establish connection.
Do I have to add any additional rule for iptables?
 
Old 05-20-2008, 06:05 AM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
For an FTP server you just need something like this:
Code:
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

iptables -A INPUT -p TCP -i eth0 --dport 21 \
-m state --state NEW -j ACCEPT

iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
If that doesn't work, you need to check whether you have the FTP connection tracking module loaded, which you will need unless you have FTP connection tracking support compiled into your kernel. IIRC it's called ip_conntrack_ftp.


EDIT: I re-read your post and it seems you are talking about the iptables rules on the box which would be the FTP client instead of the server. In that case, you'd use this instead:
Code:
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

iptables -A OUTPUT -p TCP -o eth0 --dport 21 \
-m state --state NEW -j ACCEPT
The need for FTP connection tracking still applies, though.

Last edited by win32sux; 05-20-2008 at 12:49 PM.
 
  


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
iptables dropping responses from web, dns, ftp servers I try to connect to? Calab Linux - Security 6 10-16-2007 10:58 AM
can't connect via ftp on my lan....this is my iptables config.... loboautoma Linux - Security 8 01-28-2005 01:14 AM
Suddenly unable to connect to my web server and my ftp server. HELP! Silly22 Linux - Software 4 05-23-2004 04:42 PM
FTP server w/ IPTables clergykid Linux - Security 2 02-09-2003 02:49 PM

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

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