Networking HowTos
Networking HowTos

Run Postfix on multiple ports

February 14, 2012 Linux

The default port for SMTP is port 25, but there may be some scenarios where you may need Postfix to listen on another port as well (or instead of). For example, if you want to send emails via your own mail server, from your work computer, but the work network may be blocking all port 25 traffic out onto the internet from all PC’s but the mail server.
You can get around this by setting up Postfix on another port number, for example 10025.
This configuration is done in the master.cf configuration file. Edit it in your editor of choice.

$ sudo nano /etc/postfix/master.cf

This file is in the following format:

# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (yes)   (never) (100)
# ==========================================================================

The first column is the port number that you want to listen on. The default SMTP port 25 line will read as follows:

smtp      inet  n       -       -       -       -       smtpd

To allow listening on port 10025 as well, its simply a matter of copying this line, pasting it below the smtp line, and changing smtp to ‘10025’.
For example:

smtp      inet  n       -       -       -       -       smtpd
10025     inet  n       -       -       -       -       smtpd

If you dont want to listen on port 25, you can simply change ‘smtp’ to your new port number.
Save the file and exit the editor.
Restart Postfix for the changes to take effect.

$ sudo /etc/init.d/postfix restart

You can now issue the ‘netstat -an’ command and see that it is listening on port 25 and port 10025.
The netstat output would look something like this for my example:

$ netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:10025           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN

Be aware that if you are running a mail server on the internet, and you are not listening on port 25, you won’t receive external emails. If you are setting up a new server, make sure your configuration doesn’t allow your mail server to be an open relay.

You Might Also Like