Relaying using a Dynamic IP
by Igloo on Jan 16th in Uncategorized
Sometimes you need to send email from a remote site, On a dynamic IP range that is blocked by mail servers for being a possible relay.
Here is what i’ve used to combat this problem using Postfix and some bash!
#! /bin/bash
IP=`<hosttobecheckedforitsipforrelaying> | sed 's/^[ ]*//g' | cut -d ' ' -f 4`
echo mynetworks = <yourserverip>/32, 127.0.0.0/8, $IP/32, > /etc/postfix/mynetworks
/etc/init.d/postfix reload
that writes the pattern file to /etc/postfix/mynetworks and then just does a simple reload on it
You could have as many hosts as you need and just ammend the line that outputs the pattern file accordingly.
I’ve setup a cron file to run this every 5 mins so that if remote site changes IP it’ll get updated *fairly* quickly!
*/5 * * * * /etc/postfix/getmynetworks.sh &> /dev/null
Then comment out the following in the main.cf file
# Not needed due to script getting my networks
# mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mynetworks = /etc/postfix/mynetworks
restart postfix
/etc/init.d/postfix restart
And you’re done

5 Comments