Sometimes you want to temporarily use a secondary IP of your Linux server to connect to a remote server on a particular port.
It can be useful, for instance, if your SMTP server IP has been blacklisted for a temporary spam problem (caused by virus, account hacking, web exploit etc.).
After solving the problem, you may use a secondary IP in your server to bypass blacklists, giving time to main IP to “clean up”. To do so you can configure source NAT with iptables command.
iptables -t nat -A POSTROUTING -p tcp --dport 25 -j SNAT --to-source xx.xx.xx.xx
where xx.xx.xx.xx is a secondary IP of the server.
Now your mail will appear to originate from the secondary IP, without changing mail server configuration.
In the case of SMTP, it is important to be sure that the secondary IP has correct DNS resolutions, both inverse and direct, otherwise your mail may not be accepted by remote servers.