We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.

Tutorials

More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsOperating SystemsLinuxAdministration

How to setup IP rotations for emails on Linux

Cloud Servers 727 x 90

If you have more than one IP addresses it is possible to setup IP rotations for outgoing e-mails. You can do that using IPtables. The standard command looks something like this:

  • iptables -t nat -I POSTROUTING -m state –state NEW -p tcp –dport 25 -o eth0 -m statistic –mode nth –every 1 -j SNAT –to-source 10.10.10.10

 

To setup IP rotations properly for all the IPs you will have to assign each IP manually and change the number after field –every.

Lets say you have 5 different IP’s. In order to setup IP rotations between them you would have to execute the following chain of commands:

  • iptables -t nat -I POSTROUTING -m state –state NEW -p tcp –dport 25 -o eth0 -m statistic –mode nth –every 1 -j SNAT –to-source 10.10.10.11
  • iptables -t nat -I POSTROUTING -m state –state NEW -p tcp –dport 25 -o eth0 -m statistic –mode nth –every 2 -j SNAT –to-source 10.10.10.12
  • iptables -t nat -I POSTROUTING -m state –state NEW -p tcp –dport 25 -o eth0 -m statistic –mode nth –every 3 -j SNAT –to-source 10.10.10.13
  • iptables -t nat -I POSTROUTING -m state –state NEW -p tcp –dport 25 -o eth0 -m statistic –mode nth –every 4 -j SNAT –to-source 10.10.10.14
  • iptables -t nat -I POSTROUTING -m state –state NEW -p tcp –dport 25 -o eth0 -m statistic –mode nth –every 5 -j SNAT –to-source 10.10.10.15

After executing these commands don’t forget to save iptables. Saving iptables is different on each Linux distribution:

  • service iptables save – save iptables rules on CentOS
  • iptables-save > /etc/iptables.rules – save iptables rules to the file on Ubuntu/Debian

 

After saving iptables you will have to start them as they do not start automatically. This can be done using the following command:

  • service iptables start – starts iptables on CentOS
  • iptables-restore < /etc/iptables.rules – enable iptables rules from the file on Ubuntu/Debian
Rate this Tutorial:
No Comments Leave a Comment
Leave a Comment

Cloud Servers 1 230×230

Other (3)

Popular Keywords

Cloud Servers 1 230×230