Binding Dovecot and Exim to a specific IP on WHM/cPanel

If you’ve got a WHM/cPanel server, and you want to run an alternative mail server on one IP address and have Dovecot and Exim bound to another IP, it’s not as straightforward as you might first hope.

From what I can find, there’s scant documentation on explaining how to get Dovecot to behave, and no documentation whatsoever that explains how to get Exim to play nice.

If you were running a standard server, with off-the-shelf versions of the above packages, then it’s all very easy. WHM however makes things difficult by rebuilding config files and pulling in bits and pieces of data from all over the place when it does so. This means that if you know what change normally needs to be made to, say, /etc/exim.conf – you’re probably out of luck trying to change this as whenever the config reloads, or is changed in WHM, your changes will get wiped out.

Dovecot

Dovecot turned out to be the easier of the two to work out what to do.

Simply edit /var/cpanel/conf/dovecot/main and add listen: 127.0.0.1 <your.ip.address> to the end of the file (obviously changing it for your desired IP address)

Exim

This was a real pain in the arse – there was absolutely no documentation on how to accomplish this within WHM, and in the end the fix was quite simple (as these things often are)

Edit /etc/exim.conf.local and in the @CONFIG@ section, add local_interfaces = 127.0.0.1 : <your.ip.address>

You will often see examples of the local_interfaces directive having a value like so:

local_interfaces = <; 127.0.0.1 ; ::1 ; 
                      10.0.0.10 ; 
                      3ffe:cafe:12:1:a00:babe:fe86:a061

In this case the <; after the = sign changes the item delimiter to ; from the default of : which we don’t need in this case as we’re not dealing with IPv6 addresses. We also don’t want to bind to 127.0.0.1 as our other mail server is listening on this port.

This article was posted by Kai Howells. If you liked this content and have any technical work in the Melbourne area, say hello via my contact form or give me a call on 0419 361 653 - I cover most of the greater Melbourne area and my rates are competitive.

Leave a Reply

Your email address will not be published. Required fields are marked *