LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-15-2009, 10:13 PM   #1
DBabo
Member
 
Registered: Feb 2003
Distribution: Fedora {latest}
Posts: 568

Rep: Reputation: 40
iptables and ftp


Hello,
i'm a bit puzzled. It appears that i can't connect from the same machine where my ftp server runs to self ( ftp server), if i'm going through the external ip. In other words:
server> ftp server - works fine.
server> ftp 68.197.XXX.XXX:210 opens the connection, i can log in but can't retrieve any data from the dirs.

At the same time i can connect to the external ip from another machine on my local network.

Setup:
Ports 200 and 210 are forwarded to 20 and 21 on the server.
vsftpd is running as a separate service on the server.
"server" is the name of the machine.

iptables:
in /etc/sysconfig/iptables-config, last line :
Code:
# To support passive FTP
IPTABLES_MODULES="ip_conntrack_ftp"
snip from the iptables rules:
Code:
#!/bin/sh -x
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp

IPT="/sbin/iptables"

$IPT -P INPUT DROP
$IPT -P FORWARD DROP
$IPT -P OUTPUT DROP

$IPT -t nat -P PREROUTING ACCEPT
$IPT -t nat -P POSTROUTING ACCEPT
$IPT -t nat -P OUTPUT ACCEPT

$IPT -t mangle -P PREROUTING ACCEPT
$IPT -t mangle -P INPUT ACCEPT
$IPT -t mangle -P FORWARD ACCEPT
$IPT -t mangle -P OUTPUT ACCEPT
$IPT -t mangle -P POSTROUTING ACCEPT

$IPT -t raw -P PREROUTING ACCEPT
$IPT -t raw -P OUTPUT ACCEPT


$IPT -F
$IPT -F -t nat
$IPT -F -t mangle
$IPT -F -t raw

$IPT -X
$IPT -X -t nat
$IPT -X -t mangle
$IPT -X -t raw

$IPT -Z
$IPT -Z -t nat
$IPT -Z -t mangle
$IPT -Z -t raw

$IPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

$IPT -A INPUT -i lo -j ACCEPT

#FTP
$IPT -A INPUT -p TCP -i eth0 --dport 21 -m state --state NEW -j ACCEPT
$IPT -A INPUT -p TCP -i eth0 --dport 20 -m state --state NEW -j ACCEPT

<skip>

$IPT -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

$IPT -A OUTPUT -o lo -j ACCEPT

<skip>

$IPT -A OUTPUT -p TCP -o eth0 --dport 200:210 -m state --state NEW -j ACCEPT
<skip>
$IPT -A OUTPUT -j ULOG --ulog-prefix "OUTPUT DROP: "
all this works wonderfully when i connect from another machine on the local net.
once i try to go to the server's ftp using ftp client or firefox (pointing to the external IP)
Code:
...
Dec 15 23:07:42 server OUTPUT DROP:  IN= OUT=eth0 MAC= SRC=192.168.1.204 DST=68.197.XXX.XXX LEN=52 TOS=00 PREC=0x00 TTL=64 ID=38587 CE DF PROTO=TCP SPT=50649 DPT=210 SEQ=1325421182 ACK=1331453252 WINDOW=46 ACK PSH FIN URGP=0
and after i start the service:
Code:
smod | grep conn*
ip_conntrack_ftp       11569  0
ip_conntrack           53281  4 ip_conntrack_ftp,iptable_nat,ip_nat,xt_state
nfnetlink              10713  2 ip_nat,ip_conntrack
I'm not sure why...

Last edited by DBabo; 12-15-2009 at 10:15 PM.
 
Old 12-16-2009, 01:05 AM   #2
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
This should fix it.

change
Code:
$IPT -A OUTPUT -p TCP -o eth0 --dport 200:210 -m state --state NEW -j ACCEPT
to
Code:
$IPT -A OUTPUT -p TCP -o eth0 -m multiport --dports 200,210 -m state --state NEW -j ACCEPT
 
Old 12-24-2009, 05:18 PM   #3
DBabo
Member
 
Registered: Feb 2003
Distribution: Fedora {latest}
Posts: 568

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by datopdog View Post
This should fix it.

change
Code:
$IPT -A OUTPUT -p TCP -o eth0 --dport 200:210 -m state --state NEW -j ACCEPT
to
Code:
$IPT -A OUTPUT -p TCP -o eth0 -m multiport --dports 200,210 -m state --state NEW -j ACCEPT
Datopdog,
thank you for pointing out! i just got to this -sorry about delay. I'll ask my friend to test.
Thank you and Merry Christmas.
 
Old 12-24-2009, 05:35 PM   #4
elsheepo
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Slackware
Posts: 90

Rep: Reputation: 20
http://connie.slackware.com/~alien/efg/
 
1 members found this post helpful.
Old 12-24-2009, 06:25 PM   #5
DBabo
Member
 
Registered: Feb 2003
Distribution: Fedora {latest}
Posts: 568

Original Poster
Rep: Reputation: 40
elsheepo - that's one kick a$$ script. Thank you!
 
Old 12-24-2009, 08:46 PM   #6
elsheepo
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Slackware
Posts: 90

Rep: Reputation: 20
Dbabo, please, thank the Author, he is a really cool dude. irc.freenode.net / ##slackware look for AlienBOB
and btw, yea that script dose kick a$$. Chalk one up for the slackware users :P


SLACKWARE FTW!!
 
Old 08-11-2010, 08:16 PM   #7
DBabo
Member
 
Registered: Feb 2003
Distribution: Fedora {latest}
Posts: 568

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by elsheepo View Post
Dbabo, please, thank the Author, he is a really cool dude. irc.freenode.net / ##slackware look for AlienBOB
and btw, yea that script dose kick a$$. Chalk one up for the slackware users :P


SLACKWARE FTW!!

Just did. thank you
 
  


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 and FTP aq_mishu Linux - Networking 1 09-20-2007 10:57 AM
iptables and ftp Ammad Linux - Networking 3 12-19-2005 05:56 PM
ftp and iptables eantoranz Linux - Networking 1 07-04-2005 11:24 AM
IPTables and FTP - ftp on LAN adamgedde Linux - Newbie 6 10-16-2003 08:11 PM
ftp and ftp port forwarding with IPtables?? FunkFlex Linux - Security 3 04-24-2002 03:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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