LinuxQuestions.org
Visit the LQ Articles and Editorials section
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
 
LinkBack Search this Thread
Old 10-28-2002, 10:27 PM   #1
kofi
Member
 
Registered: Aug 2002
Location: Atlanta
Distribution: Redhat Linux 7.2 & 7.3 + 8.0
Posts: 59

Rep: Reputation: 15
Accessing LOCAL FTP Server from Internal fails


Guys,

After a week of twidling with IPTABLES i got it to do the bloody port forarding thing. So i can basically get to my internal. www, dns, smtp, and ftp servers from the external ip address. Funny thing is this, FTP is acting up. I can FTP from a remote location and connect to my internal FTP server and successfully transfer files Ok.

When I try to do this from one of my internal boxes , it concects, authenticate correctly. The moment I type ls or dir or get or any command...BOOM, the connection closes as indicated by the results I have included below: Since it fails after typing a command. I know it has to do with the data port that is being used is gets dropped by the firewall. But my script already has provision for this as indicated also below.. but.the damn thing fails each time.


230-Welcome to FTP Site.
230-Happy FTP'ing
230 User idiot logged in.
Remote system type is Windows_NT.
ftp> dir
227 Entering Passive Mode (192,168,1,50,10,242).
426 Connection closed; transfer aborted.
ftp> bye
221 Thanks for stopping by, come again! Cheers!!!


I have read a lot on passive/active mode and FTP using Ports > 1024. I just dont get why it will work ok for external connections and not allow me to transer files if I choose to come through the external interface from one of my internal mahines,

Here is a snippet of my script and also one indicating where the nating occurs.

# FTP (20, 21) - Allowing incoming access to your local FTP server
#

if [ $FTP_SERVER -gt 0 ]; then

# Incoming request

iptables -A INPUT -i $EXTERNAL_INTERFACE -p TCP \
--sport $UNPRIVPORTS --dport 21 -s $MY_FTP_CLIENTS -d $EXTERNAL_IP -j ACCEPT

iptables -A OUTPUT -o $EXTERNAL_INTERFACE -p TCP -m state --state ESTABLISHED,RELATED \
--sport 21 --dport $UNPRIVPORTS -s $EXTERNAL_IP -d $MY_FTP_CLIENTS -j ACCEPT

# Normal Port mode FTP data channel responses

iptables -A OUTPUT -o $EXTERNAL_INTERFACE -p TCP \
--sport 20 --dport $UNPRIVPORTS -s $EXTERNAL_IP -d $MY_FTP_CLIENTS -j ACCEPT

iptables -A INPUT -i $EXTERNAL_INTERFACE -p TCP -m state --state ESTABLISHED,RELATED \
--sport $UNPRIVPORTS --dport 20 -s $MY_FTP_CLIENTS -d $EXTERNAL_IP -j ACCEPT

# Passive mode FTP data channel responses

iptables -A INPUT -i $EXTERNAL_INTERFACE -p TCP \
--sport $UNPRIVPORTS --dport $UNPRIVPORTS -s $MY_FTP_CLIENTS -d $EXTERNAL_IP -j ACCEPT

iptables -A OUTPUT -o $EXTERNAL_INTERFACE -p TCP -m state --state ESTABLISHED,RELATED \
--sport $UNPRIVPORTS --dport $UNPRIVPORTS -s $EXTERNAL_IP -d $MY_FTP_CLIENTS -j ACCEPT

if [ $VERBOSE -gt 0 ]; then
echo "firewall: Remote clients may access local FTP server"
fi

fi

___________________________________________________________
START NAT
#
# TCP Services on selected ports.
#

#
# DNAT/SNAT Port Forwarding
#

if [ -f firewall.nat ]; then
while read IP_PORT; do
# extract the ips and port
NAT_EXT_PORT=$(echo "$IP_PORT" | awk '{print $1}')
NAT_INT_IP=$(echo "$IP_PORT" | awk '{print $2}')
NAT_INT_PORT=$(echo "$IP_PORT" | awk '{print $3}')

# write the rules!

# this is the prerouting dnat
iptables -A PREROUTING -t nat -p TCP -d $EXTERNAL_IP --dport $NAT_EXT_PORT -j DNAT \
--to-destination $NAT_INT_IP:$NAT_INT_PORT

# This allows packets from external->internal
iptables -A FORWARD -i $EXTERNAL_INTERFACE -o $INTERNAL_INTERFACE -p tcp \
-d $NAT_INT_IP --dport $NAT_INT_PORT -m state \
--state NEW,ESTABLISHED,RELATED -j ACCEPT

# This allows packets from internal->external
iptables -A FORWARD -i $INTERNAL_INTERFACE -o $EXTERNAL_INTERFACE -p tcp \
-s $NAT_INT_IP --sport $NAT_INT_PORT -m state \
--state NEW,ESTABLISHED,RELATED -j ACCEPT

# This enables access to the 'public' server from the internal network
iptables -t nat -A POSTROUTING -d $NAT_INT_IP -s $INTERNAL_NETWORK \
-p tcp --dport $NAT_INT_PORT -j SNAT --to $INTERNAL_IP

echo firewall: dnat: $EXTERNAL_IP:$NAT_EXT_PORT - $NAT_INT_IP:$NAT_INT_PORT

done < /etc/firewall/firewall.nat

# unset some variables
unset IP_PORT
unset NAT_EXT_PORT
unset NAT_INT_IP
unset NAT_INT_PORT
fi


Any ideas will be helpful

Thanks Guys.
 
Old 10-29-2002, 01:49 AM   #2
kofi
Member
 
Registered: Aug 2002
Location: Atlanta
Distribution: Redhat Linux 7.2 & 7.3 + 8.0
Posts: 59

Original Poster
Rep: Reputation: 15
Figured it out - Guys

After a few minutes of staring at the script, i found what was wrong. The script was not implicitly loading the ftp_conntrack and the ftp_nat modules. I alwasys assumed kernel 2.4 loaded them by default.. Anyway, I loaded the manually with the code I got from the IPMASQ HOWTO Script and VOILA it works.

Thanks Guys!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FTP Server Up and running... how do I hide ftp users from local login screen? joe1031 Mandriva 2 03-18-2005 04:24 PM
how? install from LOCAL ftp server? thas Mandriva 1 12-12-2004 11:11 AM
Accessing FTP outside of local network with Suse 9.1 Pro HeX Productions Linux - Security 1 11-08-2004 05:53 PM
routing ftp connections to internal server? steepcreep Linux - Networking 1 02-18-2004 02:29 AM
Accessing a local server with a public IP ganninu Linux - Networking 5 12-29-2003 04:07 AM


All times are GMT -5. The time now is 05:13 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration