Dec 062010

This time i’ll show you how to randomize your smtp outbound’s IP addresses. This can be done via transport map. But, since ordinary Postfix lookup tables store information as (key, value) pairs. it will provide static value only. we need someting that can manipulate the value (right hand side) of a lookup table. In order to answer random transport value.

first come to mind was tcp_tables, tcp_tables lookup table gives some flexibility for us to execute our tiny perl script that will randomizing transport. that’s the basic idea.

Ok, here’s the first part, create perl script call, anyway this script only provide answer in “catch-all” manner. so it will randomized, all outgoing mail.

# cd /etc/postfix
# vi
#!/usr/bin/perl -w
# author: Hari Hendaryanto <hari.h -at->

use strict;
use warnings;
use Sys::Syslog qw(:DEFAULT setlogsock);

# our transports array, we will define this in as transport services

our @array = (

# Initalize and open syslog.

# Autoflush standard output.
select STDOUT; $|++;

while (<>) {
        # randomizing transports array
        my $random_smtp = int(rand(scalar(@array)));
        if (/^get\s(.+)$/i) {
                print "200 $array[$random_smtp]\n";
                syslog("info","Using: %s Transport Service", $random_smtp);

	print "200 smtp:";

Make it executable

# chmod 755 parts

Run the scripts via postfix spawn daemon service. inet  n       n       n       -       0      spawn
          user=nobody argv=/etc/postfix/

add 5 smtp client services called rotate1, rotate2, rotate3, rotate4, rotate5, that bind to its own ip
address and has uniq syslog/helo name.

# random smtp
rotate1  unix -       -       n       -       -       smtp
          -o syslog_name=postfix-rotate1
          -o smtp_bind_address=

rotate2  unix -       -       n       -       -       smtp
          -o syslog_name=postfix-rotate2
          -o smtp_bind_address=

rotate3  unix -       -       n       -       -       smtp
          -o syslog_name=postfix-rotate3
          -o smtp_bind_address=

rotate4  unix -       -       n       -       -       smtp
          -o syslog_name=postfix-rotate4
          -o smtp_bind_address=

rotate5  unix -       -       n       -       -       smtp
          -o syslog_name=postfix-rotate5
          -o smtp_bind_address=

Before we actually implement our randomize transport, let’s make sure that the setting actually work.

Reload postfix

# postfix reload

Run this query fiew times, and you’ll see the perl script will return “random answer” transport

# postmap -q "whatever" tcp:
# postmap -q "whatever" tcp:

And so on..

Note on “whatever”, since the script acted in “catch-all” mode as i’ve mentioned earlier, what ever postfix transport_maps client asked. it will be answered with random values such as rotate1, rotate2, rotate3, rotate4, rotate5 in randomized fashion. parts

Add these lines

transport_maps = tcp:[]:2527 = 3600s

Reload postfix
that’s it. example log would be like these and that’s indicate that randomizer is working.

Month date 12:26:53 host postfix-rotate1/smtp[4252]: A1CA68480A4: to=<>,[]:25], delay=3.6, delays=0.69/0.01/0.81/2, dsn=2.0.0, status=sent (250 ok dirdel)
Month date 12:27:06 host postfix-rotate5/smtp[4253]: 41C2E8480A4: to=<>,[]:25], delay=6, delays=0.14/0.01/0.85/5, dsn=2.0.0, status=sent (250 ok dirdel)
Month date 12:27:22 host postfix-rotate3/smtp[4277]: 4BA9F8480A4: to=<>,[]:25], delay=7.9, delays=0.85/0.02/0.61/6.4, dsn=2.0.0, status=sent (250 ok dirdel)

I’m not taking any responsible if the reader “misuse” this tutorial.the tutorial is provide as-is for experimental purposes.

use Sys::Syslog qw(:DEFAULT setlogsock);

  99 Responses to “Postfix Randomizing Outgoing IP Using TCP_TABLE And Perl”

Comments (98)
  1. what is your inet_interfaces setting?

  2. inet_interfaces = all
    inet_protocols = ipv4

    Here is my ifconfig:

    eth2 Link encap:Ethernet HWaddr 00:23:7d:14:25:18
    inet addr:96.93.xxxx Bcast:96.93.xxxxx Mask:
    inet6 addr: 2601:8b:8401:3a00:2c14:xxxxxx/64 Scope:Global
    inet6 addr: 2601:8b:8401:3a00:223:xxxxxxx/64 Scope:Global
    inet6 addr: fe80::223:7dff:xxxxxxxxx/64 Scope:Link
    RX packets:19804 errors:0 dropped:0 overruns:0 frame:0
    TX packets:13830 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:2913491 (2.9 MB) TX bytes:2756940 (2.7 MB)
    Interrupt:19 Memory:f0180000-f01a0000

    eth2:0 Link encap:Ethernet HWaddr 00:23:7d:14:25:18
    inet addr:96.93.xxxxx Bcast:96.93.xxxxx Mask:
    Interrupt:19 Memory:f0180000-f01a0000

    lo Link encap:Local Loopback
    inet addr: Mask:
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:65536 Metric:1
    RX packets:18775 errors:0 dropped:0 overruns:0 frame:0
    TX packets:18775 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:3659381 (3.6 MB) TX bytes:3659381 (3.6 MB)

  3. what is in your randomize services?do you have firewall that prevent postfix from using those ip addresses?

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>