Many mail servers such as Qmail or Postfix, when activating port 587, also enable secure access. Connections to port 25 can be made without that type of security, which avoids problems when setting up email accounts in certain mail clients.
To make this redirection, we will connect to our server via SSH and run:
# iptables -t nat -A PREROUTING -p tcp -m tcp --dport 587 -j REDIRECT --to-ports 25
To prevent this change from being lost after rebooting our server, we’ll locate the iptables path:
# which iptables
It usually returns results such as:
/usr/sbin/iptables
/sbin/iptables
Considering the path found above, we’ll edit the following file:
# vi /etc/rc.local
We must add this line before exit 0:
/usr/sbin/iptables -t nat -A PREROUTING -p tcp -m tcp --dport 587 -j REDIRECT --to-ports 25
or
/sbin/iptables -t nat -A PREROUTING -p tcp -m tcp --dport 587 -j REDIRECT --to-ports 25
Note
In some control panels such as Plesk or VestaCP, there is an option to enable port 587. You should disable it since we are going to create a redirection.