how to change port number of ftp (vsftpd, ProFTPd) in linux

One of the most popular methods of transferring files between machines is using a FTP server and client. There are quite a few FTP servers out there, and almost all of the Linux distros comes with one by default. If you are not happy with the one that is installed by default, you can always install another one.

By default, all FTP servers use port 21. This port is also known as the FTP command port. There are several other ports that the server will use during the file transfer process, but FTP command port is the one that the client use explicitly to initiate a connection and to perform actions or commands.

Usually, under normal circumstances there is no reason you will need to change the default port. But sometimes you might have to do it. If you want to run multiple servers on the same machines, then you will need to configure each of the servers such that none of the ports collide when running simultaneously.

We will take a look at some of the most popular FTP servers that are used and how you can configure the default port for each of them. You will find that almost all servers read their configuration from a specific file in the file system. The generic process to change the port involves these steps:

  1. Identify the path or location of the configuration file used by the server.
  2. Open the file for editing (usually with superuser permissions).
  3. Modify the line or configuration that is usually named Port or something similar in the file to a unique port.
  4. Save the configuration file.
  5. Start or Restart the FTP server.

vsftpd

vsftpd is a very popular server, known mostly for security and speed.  By default, vsftpd uses the configuration file /etc/vsftpd.conf. In some distros, you might find the file under /etc/vsftpd/vsftpd.conf. The configuration file is pretty simple, each line is a comment or a directive.

The lines that start with # (hash or pound) are comments and are ignored. The directive follow the simple format of key = value.

Open the configuration file in a text editor of your choice, and search for the directive (or line) that is named listen_port. This is the variable that controls the listening port of the server. In some cases, you may not find one. You can go ahead and create new line in that case. The directive should look like this:

listen_port=324

Now, you can save the file and restart the server. The following command will restart the server in almost all distros.

bash$ /etc/init.d/vsftpd restart

The restarted server should now listen on port 324 (from the example above) or whichever port you have changed it to.

ProFTPD

ProFTPD is another commonly used FTP server that is heavily configurable. The modification process follows the same pattern as vsftpd or the generic pattern enumerated above.

The configuration file is located at /etc/proftpd.conf. The directive that controls the port is called Port. Open the configuration file and look for an entry with the name Port. You can now modify the port in this line to the new value. A sample entry will look like this:

Port 423

And you can restart the server after saving the configuration file. The following command will restart the server

$ /etc/init.d/proftpd restart

The server should now listen on port 423 or whichever port you specified in the file.

Pure-FTPd

Another popular server is Pure FTPd. Unlike the other FTP servers, the Pure server does not use a default configuration file. This makes it a little harder to configure it. However you can use a wrapper configuration to specify a configuration file. You can refer to the server documentation if you need to do this.

In order to modify the default port, you can specify the new port in the command line when you startup the server. You use the command line option -S to specify the port. So, a modified startup command will look something like this:

$ /usr/local/bin/pure-ftpd -S 52

There is no saving the configuration or restarting the server involved here. If you use a script to start the server, then modify the script to add the command line arguments.

If you have a firewall in front of the server, then do not forget to open up the newly configure port in the firewall. You will also need to inform the clients of the new port number so that it can be used. The default port (which was 21) will no longer work.