This morning, when I took my daughter to school, I got the idea to experiment with postfix and GeoIP location. the idea is, if mx emails are in a geo targeted a specific location, mail delivery will be done with a certain ip address.
Ie:
- Every emails with the mx hosts that have IP addresses/host mapped to the US country code, will be bind to ip 1.2.3.4.
- Every emails with the mx hosts that have IP addresses/host mapped to the HK country code, will be bind to ip 5.6.7.8.
or
- Every emails with the mx hosts that have IP addresses/host mapped to the CN country code, will be relay to our smtp nexthop in china.
And so on..
what is geolocation?
Geolocation is used to deduce the geolocation (geographic location) of another party. For example, on the Internet, one geolocation approach is to identify the subject party’s IP address, then determine what country (including down to the city and post/ZIP code level), organization, or user the IP address has been assigned to, and finally, determine that party’s location. Other methods include examination of a MAC address, image metadata, or credit card information.
But, in this experiment we just need ip/host to country code map and perl script.
Perl module required:
Net::DNS
Geo::IP
Sys::Syslog
Basic Usage perl geoip
#!/usr/bin/perl
use Geo::IP;
my $gi = Geo::IP->new(GEOIP_STANDARD);
print $gi->country_name_by_name("amazon.com");
I would still be using transport_maps and tcp_table to interact with Perl scripts. so here’s the prototype.
In Postfix part, we have custom transport like this in master.cf:
smtp-JP unix - - n - - smtp
-o syslog_name=postfix-smtp-JP
-o smtp_helo_name=smtp-JP.example.com
-o smtp_bind_address=1.2.3.1
smtp-US unix - - n - - smtp
-o syslog_name=postfix-smtp-US
-o smtp_helo_name=smtp-US.example.com
-o smtp_bind_address=1.2.3.2
smtp-ID unix - - n - - smtp
-o syslog_name=postfix-smtp-ID
-o smtp_helo_name=smtp-ID.example.com
-o smtp_bind_address=1.2.3.3
smtp-CN unix - - n - - smtp
-o syslog_name=postfix-smtp-CN
-o smtp_helo_name=smtp-CN.example.com
-o smtp_bind_address=1.2.3.4
smtp-HK unix - - n - - smtp
-o syslog_name=postfix-smtp-HK
-o smtp_helo_name=smtp-HK.example.com
-o smtp_bind_address=1.2.3.5