Sunday, March 22, 2020

Change outbound connections IP for Mail

Hello admins, The server will start to send the Spam mails due to malicious code or compromised mail box. In that case, our outgoing IP address will get blocked by several spam filters including Gmail and other mail services.

In this case, we have to wait for a long time to get whitelisted or have to pay to be whitelisted. But if you have secondary IP addresses for your server, we can do this trick to send emails and let the main IP to whitelist automatically.

This means we will change to outbound connections from the main IP to the secondary IP address.

Important: Before proceeding with this, make sure that you have fixed the compromised code or application or mailbox. Else, your secondary IP address will also get blocked on Spam filters.

Default IP for outgoing connections can be set using ‘ip’ utility.
First of all, check how routing is configured on the server:

You can check this by the following command:-
[root@premiersrvr ~]# /sbin/ip route dev bond1 proto kernel scope link src dev bond0 proto kernel scope link src dev bond0 scope link metric 1006 dev bond1 scope link metric 1007 via dev bond0
default via dev bond1
If no ‘src’ listed in ‘ip’ output for the default route, then the main IP on the interface is used for outgoing connections. You can change it using:
# /sbin/ip route change default via dev bond1 src
# /sbin/ip route dev eth1 proto kernel scope link src dev eth1 scope link
default via dev eth1 src

Note: be careful, if you set the wrong IP as the source you lose the connection to the server.