Category Archives: Postfix

Linux: Change default IP address on host with multiple IP address

If you have a host with multiple IP address on it, and you need to change witch IP address it present it with on the Internet, you can change the Default IP address, by changing the source IP address on the default route

ip route change default via 192.168.0.254 src 192.168.0.10

Of course the Linux host need to listen on the IP address.
You can see the changes by this command

ip route list
default via 192.168.0.254 dev eth0 src 192.168.0.10

Delete mails from a sender or to recipient address

Here is a simple script “pfdel” that can be use to delete a mail from a sender or recipient address.
Save the perl script as pfdel in /usr/local/bin and chmod +x /usr/local/bin/pfdel

Then you can use the perl script as: pfdel [email protected] then it will delete all messages where ether [email protected], is in there sender or recipient address.

#!/usr/bin/perl -w
#
# pfdel – deletes message containing specified address from
# Postfix queue. Matches either sender or recipient address.
#
# Usage: pfdel
#

use strict;

# Change these paths if necessary.
my $LISTQ = “/usr/sbin/postqueue -p”;
my $POSTSUPER = “/usr/sbin/postsuper”;

my $email_addr = “”;
my $qid = “”;
my $euid = $>;

if ( @ARGV != 1 ) {
die “Usage: pfdel \n”;
} else {
$email_addr = $ARGV[0];
}

if ( $euid != 0 ) {
die “You must be root to delete queue files.\n”;
}

open(QUEUE, “$LISTQ |”) ||
die “Can’t get pipe to $LISTQ: $!\n”;

my $entry = ; # skip single header line
$/ = “”; # Rest of queue entries print on
# multiple lines.
while ( $entry = ) {
if ( $entry =~ / $email_addr$/m ) {
($qid) = split(/\s+/, $entry, 2);
$qid =~ s/[\*\!]//;
next unless ($qid);

#
# Execute postsuper -d with the queue id.
# postsuper provides feedback when it deletes
# messages. Let its output go through.
#
if ( system($POSTSUPER, “-d”, $qid) != 0 ) {
# If postsuper has a problem, bail.
die “Error executing $POSTSUPER: error ” .
“code ” . ($?/256) . “\n”;
}
}
}
close(QUEUE);

if (! $qid ) {
die “No messages with the address ” .
“found in queue.\n”;
}

exit 0;