KNOWNHOST KNOWLEDGE BASE

Hosting Question? Find the Solution - Browse our Guides, Articles, and How-To's

How to Change the Outgoing Mail IP in DirectAdmin?

Category: DirectAdmin
Tags: # # # #

Occasionally with reseller hosting, one client can cause problems if the accounts are not sufficiently isolated from one another. One such case is when one client becomes hacked with spam-sending malware and causes the outgoing mail IP to become blocked.

The correct approach to take is to immediately do whatever it takes to stop the spam emails from being generated, clear the Exim queue of all spam emails waiting to be sent, identify all malicious code within the account, clean the account, and then properly secure the account so that no further attacks occur.

If the attack is caught early, blacklisting typically doesn’t occur. However, if the attack continues, the mail-sending IP may become blacklisted and this will cause problems for all users on the server.

To prevent the uncompromised accounts from suffering and being affected by the blacklisted IP while you work to clean and secure the compromised account and request delisting from the RBLs, one may consider placing the domains on separate mail IPs.

Another scenario in which one may choose to do this is to separate a client that uses mailing lists or separate clients based on their packages and email limits/restrictions.
Regardless of the case, this will require some configuration. This article outlines the steps needed for configuring this with a DirectAdmin server.

First, let us understand how mailing works in the DirectAdmin?

DirectAdmin uses configuration which is noted in the following files and decides from which IP email should be sent,

  • /etc/virtual/domainips
  • /etc/virtual/helo_data

There are two types of configuration which you can make in the above files,

  1. Direct the DirectAdmin control panel to send emails through a specific IP address.
  2. Let the DirectAdmin control panel send emails through an account-specific IP address.

Let us check both the types of configuration,


Manually Managing the Outgoing IPs Configuration

By default, DirectAdmin sends all the outgoing emails through the primary IP address of the server, and this is managed by the configurable variables mentioned below and those are available in the DirectAdmin’s configuration file, i.e., /usr/local/DirectAdmin/conf/DirectAdmin.conf.

#These are default variables available in the DirectAdmin.conf file.
add_domain_to_domainips=0
domainips_default_ip=

Let’s say that 1.2.3.4 is my secondary IP, and I want to use my secondary IP as my outgoing mail IP from now on. Currently, the domainips file doesn’t exist since domainips_default_ip= is empty in the DirectAdmin.conf file, and add_domain_to_domainips is set to 0. I want to manually manage which domains are sent from the primary and send all others from the secondary. I would create the domainips file with the following,

*:1.2.3.4
domainips enter new ipv4 for email service

To implement the changes, restart the exim by using following command,

service exim restart

Now, all the outgoing emails should be sent using the 1.2.3.4 IP address!

For a more complex domain-IP setup with a fallback IP, a sample /etc/virtual/domainips file will contain the following:

*:1.2.3.4
domain.com:1.2.3.5
other.com:1.2.3.5

Where domain.com and other.com will use 1.2.3.5 and all other domains will use 1.2.3.4 upon an Exim restart.

The helo can be configured similarly so that the Exim welcome headers are different depending on IP being connected to.

A sample helo_data file based on the last example would be as follows,

1.2.3.4:mail.domain.com
1.2.3.5:mail.other.com

The IPs on the left side must be unique unless add_domain_to_domainips is set to 2 in the directadmin.conf Wildcard for domainips with SpamBlocker.


Allowing DirectAdmin to Manage These Files

You also have the option to allow DirectAdmin to manage these files, but this requires that each domain sends from its assigned IP (for any domain created with an IP that is not the server IP). The helo_data will only get owned IPs. This configuration requires the following directadmin.conf setting,

add_domain_to_domainips=1

You can also set a fallback IP. If you want to specify a different fallback IP other than your server IP, you can set in the directadmin.conf with the variable,

domainips_default_ip=1.2.3.4

You can use the following commands to configure this (be sure to replace 1.2.3.4 with the fallback IP you’d like to use),

/usr/local/directadmin/directadmin set add_domain_to_domainips 1
/usr/local/directadmin/directadmin set domainips_default_ip 1.2.3.4  restart

Now, you will need to have DirectAdmin rewrite these Exim configuration files since it will be managing them for you,

echo "action=rewrite&value=domainips" >> /usr/local/directadmin/data/task.queue
echo "action=rewrite&value=helo_data" >> /usr/local/directadmin/data/task.queue

Finally, confirm that data has been written to these files (these files do not exist by default) and restart Exim.

service exim restart

Conclusion

Now that we’ve gone over how to change the outgoing mail IP address in the DirectAdmin control panel. You can change the IPv4 address as many times you want and make sure to restart the exim every time after you make any changes.

KnownHost offers 365 days a year, 24 hours a day, all 7 days of the week best in class technical support. A dedicated team ready to help you with requests should you need our assistance. You’re not using KnownHost for the best webhosting experience? Well, why not? Check with our Sales team to see what can KnownHost do for you in improving your web hosting experience.