I love emails, it fascinates me! I am still frequently surprised and intrigued by the various algorithms and procedures that mail servers follow to look up, identify, read and process emails. Working with emails and making sure that headers, identification, content, etc. are all appropriate can get tricky. At least we can reduce the stress caused by blacklisted IP addresses!

Let’s get started!

cPanel/WHM uses Exim mail server by default. This guide is specific to Exim though so if you’re using Exim as your SMTP server, you can follow or reference this.

Also see the cPanel documentation How to configure Exim’s outgoing IP address.

What IP does Exim use?

By default, Exim uses the IP address of the primary hostname on the server or alternatively the dedicated IP address on a domain if it is configured that way in Exim Configuration.

Why change the IP address?

For an existing server setup one of the main reasons for changing out the IP address of the Exim mail server would be due to blacklisting. Either to prevent blacklisting on an IP address used for specific domains or to swap out an IP address if it has been blacklisted.

How to change Exim mail server IP address

So this is relatively quick and easy.

Please note that the setup will differ a bit depending on your network setup. Either NAT or bridged. If you’re on NAT you’ll simply use the local IP address throughout whereas you’ll use the direct, remote IP address if you’re in virtual, bridged mode. I’m using NAT mode in this guide at the moment. My NAT IP address is 10.0.0.1, it’s remote IP is 192.168.1.1 and the PTR/reverse DNS is host.hostname.tld

Reference /etc/mailips in Exim

You can edit the network interface on /etc/exim.conf directly but you don’t want to do that since the changes will be overwritten with updates and configuration builds. Instead, you want to use the external /etc/mailips file.

To tell Exim to use the /etc/mailips file, go to Service Configuration > Exim Configuration Manager > Basic Editor and search for “mailips” and turn On the setting to reference /etc/mailips. Then click “Save“. Exim will rebuild it’s configuration and restart the mail server.

Create/edit the /etc/mailips file

If the /etc/mailips file doesn’t exist (which it most likely doesn’t unless there are already custom interface rules created), you can simply create a blank file.

vi /etc/mailips

Put the following line in the file to globally set the outgoing IP address for the Exim mail server:

*: 10.0.0.1

Allow the IP on reverse DNS

Next, you want to specify this IP for your hostname for lookup purposes, reverse DNS. You’ll do this in /etc/mail_reverse_dns

vi /etc/mail_reverse_dns

Place the following line in the file:

10.0.0.1 host.hostname.tld

If you don’t specify this correctly, you may get an error during sending emails:

unable to bind outgoing SMTP call to xxx.xxx.xxx.xxx: Cannot assign requested address

Rebuild and restart Exim mail server

So simply rebuild the Exim configuration and restart the service:

/scripts/buildeximconf
service exim restart

That’s it!

Awesome, you’ve done it, that should work!

You can now do a test and see if the new IP reflects correctly on outgoing emails. You can view the raw source of emails to see the hostname, reverse DNS and IP address.

You can also take it further and write a bash script to modify the outgoing mail interface to rotate IPs specified in /etc/mailips as needed automatically.

Shares