Changing Exim’s Sending IP

4.6/5 - (54 votes)

Anyone running a shared hosting server is probably now accustomed to dealing with constant complaints about blacklisting. It’s exim’s default setup on a cPanel server to use the shared IP of the server to send email, which means that all your clients on one server are sending out email on the same IP.  All it takes is for one spammer to send out a mailing list or one customer to get hacked and run a Darkmailer script, and suddenly everyone on your server seems to be complaining about getting their mail bounced.

You can change the server’s IP address for sending email. Assuming you already have an IP set up on your server with a valid PTR, you can simple update /etc/mailips

To set this up initially, go into WHM > Exim Configuration and enable this option:

** Send outgoing mail from the ip that matches the domain name in /etc/mailips (*: IP can be added to the file to change the main outgoing interface) [?]

You should also disable this option to keep /etc/mailips from being overwritten, as long as you don’t need this functionality (if you do, another solution is presented below using chattr):

**Send mail from account’s dedicated IP address

 

Then run

/scripts/buildeximconf
service exim restart

The /etc/mailips file should be root:exim, chmod 440  if it doesn’t already exist. You can additionally make the file immutable to keep cPanel from overwriting it but please note that this can cause problems with cPanel’s operation in other parts of the server, such as creating accounts.

chattr +i /etc/mailips

Now for actually changing the IP:

Changing the IP Globally

If you want everyone on the server to send out on the same IP, just add the following to /etc/mailips:

*: xxx.xxx.xxx.xxx

Then add the IP and it’s matching PTR to /etc/mail_reverse_dns:

xxx.xxx.xxx.xxx hostname.tld

This will tell Exim to use that IP for any sender on the server.

Changing the IP Per Domain

If you want your users with dedicated IP addresses to be able to use those IPs to send email as well, you can add them to /etc/mailips as well in the format of:

domain: ip

If you have multiple dedicated IP domains already, I’ve devised a simple loop you can use to populate /etc/mailips automatically:

while read line ; do DOMAIN=`echo -e $line |awk '{print $2}'` && IP=`echo -e $line |awk '{print $1}' |cut -d: -f1` && echo "$DOMAIN: $IP" >> /etc/mailips ;done < /etc/domainips

You’ll always want the wildcard line to be in there to account for any domain not listed in the file, whether it is the main server’s IP or another that you have assigned for email:

*: xxx.xxx.xxx.xxx

Then:

cp /etc/domainips /etc/mail_reverse_dns

This will set all the existing sites on dedicated IPs to send out mail on those IPs.

See also: https://documentation.cpanel.net/display/CKB/How+to+Configure+the+Exim+Outgoing+IP+Address

zp8497586rq

15 Comments

  1. Pingback: change exim ip - cPanel Forums

  2. Jay Levine

    Hey Vanessa,

    Worked like a charm!! Fixed my yahoo defers (for now).

    Two notes, if you change Exim from WHM then WHM will run rebuild the conf & restart exim for you.

    Also, chattr +i /etc/mailips before chaging the mailips is a problem :>

    Again, thanks for the writeup, found it at cPanel forums.

    Jay

  3. Pingback: Changing sender IP in Exim : Control Panel Blog

  4. Pingback: 10 Tips for Improving Email Delivery :: The cPanel Admin

  5. AfricanMovies

    @Jay Levine, true chattr +i /etc/mailips does cause an issue after doing this I got “Error writing mailips: Permission denied” when trying to edit the mailips file. I have to reverse it in order to edit the file

  6. Simon Bourgoin

    Yo!

    chattr +i /etc/mailips must be applied after modification on file /etc/mailips are complete.

    If this command has already been applied to / etc / mailips, or you need to do some other change other changes, the following command must be run before to modify the file:

    chattr-i / etc / mailips

  7. georges

    Hello,
    After I bought and installed the SSL certificate which my server gave me another IP address for https, my web page with http works fine all the text and photos are there and visible but not on my https which is most of things are missing, how do I correct the situation,
    thanks
    georges

  8. Pingback: Change the Sending IP for Outbound Email in Exim

  9. Pingback: Changing Exim’s Sending IP | Raafat Mohamed

  10. Pingback: Changing Exim Sending IP « Linux System Administration

Log in