1

I have created a script to install Postfix and it works perfect with all my Ubuntu clients, but not on my Fedora client.

The Fedora client is able to send e-mail directly to [email protected], but when sent to root it should be redirected to [email protected] but is instead sent to [email protected]

I can't figure out for the life of me why... Here is the configs and logs if anybody can point out the issue that would be awesome.

#!/bin/bash

DOMAIN=domain.com
[email protected]

cat << 'EOL' >/etc/postfix/main.cf
#
#PostFixConfig

##Modify Below [HOSTNAME] & [DOMAIN]##
######################################
myhostname = [HOSTNAME]
mydomain = [DOMAIN]

relayhost = smtp.$mydomain

biff = no
append_dot_mydomain = no
readme_directory = no

smtpd_banner = $myhostname ESMTP $mail_name
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtp_header_checks = regexp:/etc/postfix/header_checks

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

myorigin = $mydomain
mydestination = $myhostname $myhostname.$mydomain localhost
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128

mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all
EOL

cat << EOL >/etc/aliases
postmaster: root
root: $forwardemail
trash: /tmp/mail.trash
EOL

newaliases

cat << EOL >/etc/postfix/header_checks
/^From:[[:space:]]+(.*)/ REPLACE From: "$HOSTNAME" <$forwardemail >
EOL

postmap /etc/postfix/header_checks

chown root:root /etc/postfix/ -R && service postfix restart

echo "PostFix Setup For $HOSTNAME" | mail -s "PostFix has forwarded roots e-mail on $HOSTNAME to this e-mail" root

echo ""
echo "Main.CF"
cat /etc/postfix/main.cf
echo ""
echo "header_checks"
cat /etc/postfix/header_checks
echo ""
echo "Aliases"
cat /etc/aliases
echo ""
echo "MailName"
cat /etc/mailname
echo ""
echo "MailLog"
tail /var/log/maillog
tail /var/log/mail.log

Logs:

Jul 13 05:17:25 kvmatrix postfix/cleanup[16951]: F296FE104B: message-id=<20190713121725.F296FE104B@KVMatrix>                                                                                                                                                          
Jul 13 05:17:25 kvmatrix postfix/qmgr[16643]: F296FE104B: from=<[email protected]>, size=443, nrcpt=1 (queue active)                                                                                                                                       
Jul 13 05:17:26 kvmatrix postfix/smtp[16953]: F296FE104B: replace: header From: [email protected] (root): From: "kvmatrix" <[email protected] >                                                                                                
Jul 13 05:17:26 kvmatrix postfix/smtp[16953]: F296FE104B: to=<[email protected]>, orig_to=<root>, relay=smtp.domain.com[192.168.1.255]:587, delay=0.06, delays=0.01/0.01/0.03/0.01, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 17FACC247B)                                                                                                                                                                                                                                                                     
Jul 13 05:17:26 kvmatrix postfix/qmgr[16643]: F296FE104B: removed                                                                                                                                                                                                     
[root@kvmatrix ~]#  

I notice the line to=<[email protected]>, orig_to=<root>, which almost looks like a "redirect/alias" to me except the address is wrong.

[root@kvmatrix ~]# cat /etc/aliases                                                                                                                                                                                                                                   
mailer-daemon: postmaster                                                                                                                                                                                                                                             
postmaster: root                                                                                                                                                                                                                                                      
root: [email protected]                                                                                                                                                                                                                                   
trash: /tmp/mail.trash  

Here is a log from a working server setup using the exact same script:

Jul 13 05:03:18 confluence postfix/master[4518]: daemon started -- version 3.1.0, configuration /etc/postfix                                                                                                                                                          
Jul 13 05:03:18 confluence postfix/pickup[4521]: B9029A2C44: uid=0 from=<[email protected]>                                                                                                                                                     
Jul 13 05:03:18 confluence postfix/cleanup[4525]: B9029A2C44: message-id=<20190713120318.B9029A2C44@confluence>                                                                                                                                                       
Jul 13 05:03:18 confluence postfix/qmgr[4522]: B9029A2C44: from=<[email protected]>, size=449, nrcpt=1 (queue active)                                                                                                                           
Jul 13 05:03:18 confluence postfix/cleanup[4525]: BA500A2C45: message-id=<20190713120318.B9029A2C44@confluence>                                                                                                                                                       
Jul 13 05:03:18 confluence postfix/qmgr[4522]: BA500A2C45: from=<[email protected]>, size=594, nrcpt=1 (queue active)                                                                                                                           
Jul 13 05:03:18 confluence postfix/local[4533]: B9029A2C44: to=<[email protected]>, relay=local, delay=0.01, delays=0.01/0/0/0, dsn=2.0.0, status=sent (forwarded as BA500A2C45)                                                                
Jul 13 05:03:18 confluence postfix/qmgr[4522]: B9029A2C44: removed                                                                                                                                                                                                    
Jul 13 05:03:18 confluence postfix/smtp[4534]: BA500A2C45: replace: header From: [email protected] (root): From: "confluence" <[email protected] >                                                                                  
Jul 13 05:03:18 confluence postfix/smtp[4534]: BA500A2C45: to=<[email protected]>, orig_to=<[email protected]>, relay=smtp.domain.com[192.168.1.255]:587, delay=0.04, delays=0/0/0.03/0.01, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as C3BC8C247B)                                                                                                                                                                                                                                      
Jul 13 05:03:18 confluence postfix/qmgr[4522]: BA500A2C45: removed                                                                                                                                                                                                    
Jul 13 05:04:52 confluence postfix/pickup[4521]: 89B08A2C45: uid=0 from=<[email protected]>                                                                                                                                                     
Jul 13 05:04:52 confluence postfix/cleanup[4525]: 89B08A2C45: message-id=<20190713120452.89B08A2C45@confluence>                                                                                                                                                       
Jul 13 05:04:52 confluence postfix/qmgr[4522]: 89B08A2C45: from=<[email protected]>, size=385, nrcpt=1 (queue active)                                                                                                                           
Jul 13 05:04:52 confluence postfix/cleanup[4525]: 8A550A2C44: message-id=<20190713120452.89B08A2C45@confluence>                                                                                                                                                       
Jul 13 05:04:52 confluence postfix/qmgr[4522]: 8A550A2C44: from=<[email protected]>, size=530, nrcpt=1 (queue active)                                                                                                                           
Jul 13 05:04:52 confluence postfix/local[4533]: 89B08A2C45: to=<[email protected]>, relay=local, delay=0.01, delays=0/0/0/0, dsn=2.0.0, status=sent (forwarded as 8A550A2C44)                                                                   
Jul 13 05:04:52 confluence postfix/qmgr[4522]: 89B08A2C45: removed                                                                                                                                                                                                    
Jul 13 05:04:52 confluence postfix/smtp[4534]: 8A550A2C44: replace: header From: [email protected] (root): From: "confluence" <[email protected] >                                                                                  
Jul 13 05:04:52 confluence postfix/smtp[4534]: 8A550A2C44: to=<[email protected]>, orig_to=<[email protected]>, relay=smtp.domain.com[192.168.1.255]:587, delay=0.05, delays=0/0/0.04/0.01, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 93953C247B)                                                                                                                                                                                                                                      
Jul 13 05:04:52 confluence postfix/qmgr[4522]: 8A550A2C44: removed  

1 Answer 1

0

Well I have used this in the past, but tried to trim down my configs while setting Postfix up this time around. I'm not sure why Ubuntu doesn't need it, but Fedora does, but this is how I fixed it.

/etc/postfix/main.cf:

canonical_maps = hash:/etc/postfix/canonical  

/etc/postfix/canonical:

root [email protected]

Reload Postfix and test! --> postmap /etc/postfix/canonical && postfix reload

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .