Search blogs
Did you find a problem ? Tell us about it! Get a blog Report blog Random blog

pure-ftpd on openWRT and passive mode

Posted on 25/10/2006

In the tutorial below I will show how to install pure-ftpd to work behind a NAT box in passive mode.
I use this server on my Asus WL-500gP router at home. This tutorial can also be used to install this server on another machine behind the main router.

Below is my /etc/init.d/S70pure-ftpd

#!/bin/sh

# -Z --customerproof
# -Y 1
# -Y 0 (default) disables SSL/TLS security mechanisms.
# -Y 1 Accept both normal sessions and SSL/TLS ones.
# -Y 2 refuses connections that aren't using SSL/TLS security mechanisms, including
# -w
# Enable support for the FXP protocol, for non-anonymous users only.
# -B
# Start the standalone server in background (daemonize).
# -A
# Chroot() everyone, but root.
# -c 3
# -c clients Allow a maximum of clients to be connected
# -C 2
# -C max connection per ip
# -E
# Only allow authenticated login. Anonymous users are prohibited.
# -I 1
# -I timeout The timeout is in minutes, and defaults to 15.
# -j
# If the home directory of an user doesn't exist, automatically create it.
# -O stats:/opt/var/log/pure-ftpd/pure-ftpd.log
# Record all file transfers into a specific log file
# -O clf:/var/log/pureftpd.log
# -O stats:/var/log/pureftpd.log
# -O w3c:/var/log/pureftpd.log
# -p 65100:65150
# first:last Use only ports in the range first to last inclusive for passive-mode downloads
# -P 209.85.129.147
# Force the specified IP address in reply to a PASV/EPSV/SPSV command
# -T 12:32
# T upload bandwidth:download bandwidth Enable process priority lowering and bandwidth throttling for *ALL* users
# -l unix
# -l authentication:file
# -S 10.0.0.1,21
# -S [{ip address|hostname}] [,{port|service name}]This option is only effective when the server is launched as a standalone server. Connections are accepted on the specified IP and port.

BIN=/opt/usr/sbin/pure-ftpd
OPTIONS="-Z -Y 1 -w -B -A -c 3 -C 2 -E -I 1 -j -O stats:/opt/var/log/pure-ftpd/pure-ftpd.log -p 65100:65150 -P 209.85.129.147 -T 12:32 -l unix -S 10.0.0.1,21"

case $1 in
start)
$BIN $OPTIONS
;;
stop)
killall pure-ftpd
;;
restart)
killall pure-ftpd
sleep 1
$BIN $OPTIONS
;;
*)
echo "usage: $0 (start|stop|restart)"
exit 1
esac

exit $?

Here are my iptables rules for pure-ftpd to work in both active an passive mode behind NAT.
On the example below, 10.0.0.1 is the router. So, if you have the FTP server on another internal computer you need to use forwarding_rule instead of input_rule.
I will also change the default 21 port to 30021, for security reasons. This is done from iptables only for the WAN. Inside the network, port 21 will be used.

Below are the rules for iptables

#!/bin/sh

$LANIP=10.0.0.1

# redirect incoming FTP control connections from port 30021 to 21
iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 30021 -j DNAT --to $LANIP:21
iptables -t filter -A input_rule -i $WAN -p tcp --dport 21 -d $LANIP -j ACCEPT

# accept return traffic on active FTP data connections
iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 20 -j DNAT --to $LANIP:20
iptables -t filter -A input_rule -i $WAN -p tcp --dport 20 -d $LANIP -j ACCEPT

# accept FTP data passive connections
iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 65100:65150 -j DNAT --to $LANIP
iptables -t filter -A input_rule -i $WAN -p tcp --dport 65100:65150 -d $LANIP -j ACCEPT
Tags: openwrt , ftp , wl-500gp , ssh , iptables
These icons link to social bookmarking sites where readers can share and discover new web pages. Bookmark page
  • digg
  • del.icio.us
  • YahooMyWeb
  • Furl
  • Fark
  • Ma.gnolia
  • Reddit
  • Smarking
  • Spurl
  • NewsVine
  • blinkbits
  • Yahoo Messenger
Razvan @ 09:39
Filed under: software

1 Comment for 'pure-ftpd on openWRT and passive mode' »

  1.  
    Web developers Web developers's home page
    November 03 2009 | 17:21
     
    Humm... interesting, This is really helpful, Keep up the good work, Anyway, thanks for the post

No trackbacks have been added to this post yet.

Leave a comment





Human test

Information for comment users
Your e-mail address is never displayed. Please consider what you're posting.