Ubuntu – PureFTPd is using ports above 50000 even with PassivePortRange specified

configurationfirewallftppureftpdUbuntu

I have installed the pure-ftpd package with PureFTP 1.0.24 on Ubuntu 10.04 using apt-get.

Even though, this is the default port range, I've added the file /etc/pure-ftpd/conf/PassivePortRange containing:

30000 50000

This does add the correct option to the command as it is run (-p 30000:50000), but for some reason, I still get connections trying to use ports above 50000. I think the problem is that these are active ftp sessions, but what's the point of specifying a port range if it only works for passive mode? Then I still need to open all the ports in my firewall…

Is there a way to specify a port range for all connections (rather than just passive ones)?

Best Answer

In active mode the server initiates a connection to a client defined ip address, so the server has no way of affecting the port number being used. In this case you don't need to open other incoming ports than 21 because the server initiates the data connection towards the client.

In passive mode the client opens a connection to a server defined port, and that's the spot where passive port range comes into play. Server chooses a free port within the range and hands it to the client. This of course means that the entire port range needs to be open in the server firewall, which has security implications.

Linux has a neat feature to mitigate the effects of opening a large port range for passive FTP - iptables connection tracking. To take advantage of it, you need to make sure ip_conntrack_ftp module is loaded, and then you can permit traffic like this # iptables -A your_chain -i your_iface -m state --state RELATED -m helper --helper ftp -j ACCEPT (you could include your port range if necessary). That tells iptables to accept related connections managed by conntrack FTP helper. So, if any other service would be listening on a socket in your passive port range, iptables would deny access to the port because it cannot recognize it being FTP related.