Use Static IP for Outgoing Port 25 Traffic

Posted May 19, 2020 791 views
WordPressNetworkingUbuntu 18.04


I recently discovered droplet hasn’t been sending out emails from a Contact Us page on my Wordpress website. I confirmed outgoing port 25 wasn’t blocked by the firewall, so submitted a ticket to Support. Here was their response:

I am sorry to hear that you are facing issue with the SMTP on the Droplet. It looks like you trying to use Floating IP address for the SMTP.

In order to curb abuse, sending mail through SMTP is not supported with Floating IPs. You can use the static Droplet IP address for the SMTP.

Is there a single command I can run on my Ubuntu 18.04 server to only route my outgoing port 25 traffic through my static IP?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @Niomar,

You can do this with iptables, which is part of the Linux kernel. On your droplet, run:

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 25 -j DNAT --to XXX.XXX.XX.XX:25

iptables -A INPUT -p tcp -m state --state NEW --dport 25 -i eth0 -j ACCEPT

where XXX.XXX.XX.XX is the IP address of the server you want to forward to. You may need to change “eth0” to whatever your device is called and the IP on it.This can be checked by running the command

ip a

The first rule sets up the forwarding, and the second rule makes sure that connections to port 25 are accepted on the droplet the application is on.

Disclaimer: Please make sure to backup your droplet or at least your IPTables so that if this doesn’t work you can revert the changes!!