When unable to retrieve directory listing, most probably because of passive mode inaccesible

Many people report problems with ftp sessions hanging or throwing errors after the ftp login session is successful. Frequently this is because the ftp-data port is blocked by a firewall or not forwarded by a router. This section describes the configuration of vsftpd to enable passive mode data transfers, along with the accompanying changes to iptables and your router to allow ftp-data connections to pass.

Ftp sessions consist of two channels: a command channel and a data channel, and they each use a different port. While the command channel is (usually) fixed at server port 21, the data channel employs varying ephemeral ports, and this can be problematic in the presence of a firewall since you don’t know from session to session which port the ftp server will use for the data transfer. To get around this, you need to constrain the range of ports used by the server for ftp-data connections, and you need to modify your firewall and, if necessary, your router to enable traffic on that port range.

First, make sure that passive mode is enabled; vsftpd enables it by default, but it doesn’t hurt to set it explicitly. Let’s also restrict the data channel to ports 11000 through 11010. Depending upon the number of concurrent sessions you anticipate on your server, you can increase or decrease the port range by modifying the min and max values. You can also use any port range; I chose 11000 through 11010 at random. Just make sure the min port is greater than 1024. Add these lines to /etc/vsftpd/vsftpd.conf.


Restart vsftpd (or xinetd if you’re running vsftpd under xinetd) to make the changes take effect.

service vsftpd restart

Now modify the server’s firewall to unblock the ftp-data port range by adding the following rule to /etc/sysconfig/iptables before the line that contains “icmp-host-prohibited”. (This assumes you haven’t radically modified /etc/sysconfig/iptables. If you have, you know enough about iptables already to know where to insert this rule.)

NOTE: Newer versions of Fedora (starting with at least F11) use a different iptables input chain name called “INPUT” rather than “RH-Firewall-1-INPUT”. Look at the other rules in your existing /etc/sysconfig/iptables file to see which name your version uses and modify the rule below accordingly. (Just delete the “RH-Firewall-1-” portion of the rule string if your input string is named “INPUT”.)


-A RH-Firewall-1-INPUT -p tcp –dport 11000:11010 -j ACCEPT

Restart the firewall.

service iptables restart

If you have a router, you need to configure it to forward ports 11000 through 11010 if you want external users to be able to transfer data to and from your server. The instructions to do this vary according to your router, but often it can be done through a web interface to the router itself.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: