Exim4 configuration to use several external ip for mail sending
Solution 1:
I found this article which show how to sets up a random function to pick an IP from a list and then assign it as an output interface to the smtp driver.
Essentially, you have to set up a function:
sub randinet {
@inet = ("x.x.x.1", "x.x.x.2", "x.x.x.3", "x.x.x.4");
return $inet[int rand($#inet+1)];
}
and modify the smtp driver:
remote_smtp:
driver = smtp
interface = "${perl{randinet}}"
Solution 2:
You can do this from within exim as well without using perl:
create a lookup file /etc/exim/ips.txt with
1: xxx.xxx.xxx.1
2: xxx.xxx.xxx.2
3: xxx.xxx.xxx.3
4: xxx.xxx.xxx.4
Set the transport to:
remote_smtp:
driver = smtp
interface = "${lookup {${randint:5}} lsearch {/etc/exim/ips.txt}}"
randint will return a random number between 1-4 which is then looked up in the file and used if you have more ip's just add to the list and increment the randint value to number ips + 1
Can be used by those who have exim built without perl or just don't want to use perl keeping everthing within exim.