I have written an IP rotation shell script. The Script is given below.
#!/bin/sh
#Get the counter from stored value
read count < counter.txt
if [[ $count -eq 0 ]]
then
prev=5
fi
if [[ $count -gt 0 ]]
then
prev=$(($count-1))
fi
#First we want to store all available IP addresses
IP_ADDRESSES=(1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1)
#Store all hostnames
HOST_NAMES=(server1.example.com server2.example.com server3.example.com server4.example.com server5.example.com server6.example.com)
#this command will
#echo ${IP_ADDRESSES[$count]}
#now change system default source ip
ip route replace default via ${IP_ADDRESSES[$prev]} dev venet0 src ${IP_ADDRESSES[$count]}
#Now change the hostname
hostnamectl set-hostname ${HOST_NAMES[$count]}
#Now change hostname in postfix
postconf -ev myhostname=${HOST_NAMES[$count]}
count=$count+1
if [[ $count -gt 5 ]]
then
count=0
fi
echo $count > counter.txt
When I run the script from command line, it's perfectly working and I can send email from a new IP and hostname pair. Now I want to execute this script before or after sending every outgoing email from our POSTFIX server. But I don't know how to trigger this script within POSTFIX.