How to Change the Outgoing Mail IP in DirectAdmin?
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,
There are two types of configuration which you can make in the above files,
- Direct the DirectAdmin control panel to send emails through a specific IP address.
- 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 188.8.131.52 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,
To implement the changes, restart the exim by using following command,
service exim restart
Now, all the outgoing emails should be sent using the 184.108.40.206 IP address!
For a more complex domain-IP setup with a fallback IP, a sample /etc/virtual/domainips file will contain the following:
*:220.127.116.11 domain.com:18.104.22.168 other.com:22.214.171.124
Where domain.com and other.com will use 126.96.36.199 and all other domains will use 188.8.131.52 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,
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,
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,
You can use the following commands to configure this (be sure to replace 184.108.40.206 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 220.127.116.11 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
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.