Postfix
One of the key aspects of understanding and administering Postfix is that it is designed to be a modular package
the base installation itself is fairly small and vast majority of the usual mail administration, such as anti-spam and anti-virus, are actually conducted by third party packages like SpamAssassin.
You can see the modular nature of Postfix by looking at the main.cf file
/etc/postfix/main.cf consists of three sections.
the first section consists of several settings such as smtp_banner and biff.
The second section has settings for TLS parameters
The third section settings for the hostname, alias and destination
myhostname = mail.democloud.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = mail.democloud.com, localhost.democloud.com, , localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
myhostname
this is set during the postfix installation when we entered the domain name we wanted to use.
aliases
aliases are ways of delivering mail to different users without having to set up dozens of different accounts
the default settings in the main.cf are good and reference another file:
/etc/aliases
/etc/aliases
you will see a list of names followed by root. in these instances, mail delivered to the first name will actually be delivered to the second name.
we don’t need to set up the postmaster, news, webmaster, abuse, etc users for postfix as mail delivered to these names will be sent to root.
Using the same syntax, we can have all mail for root delivered to our admin user by adding this line:
root:demo
remember, ‘demo’ is the main admin for the test server.
you may notice that there will be up to three changes in delivery destination:
mail sent to ‘mailer-daemon’ is sent to postmaster
mail sent to postmaster is sent to root, and we have just added that all mail sent to root is sent to main admin user ‘demo’
You are, of course, free to adjust the aliases as you see fit, but instead of changing all the ‘root’ users in the file, it is easier and quicker to add the one line as shown above …. this makes for easier migration/administration at a later date.
If you have changed the aliases file you must then refresh the aliases database or any changes will not be affected :
# sudo newaliases
myorigin
this setting is important as internal emails from packages such as cron jobs do not supply full mail ‘credentials’ such as sender email. They use the ‘myorigin’ setting.
it needs to be set to the main hostname
by default, the setting refers to the ‘/etc/mailname’ file.
you can also setting ‘myorigin’ by using ‘$mydomain’ in the main.cf file
myorigin = $mydomain
myorigin
postfix gets the information from the ‘myhostname’ setting - parsing the hostname to gain the main domain name.
the advantage of setting the myorigin this way is that it makes for easier administration at a later date as only one setting (myhostname) needs changing - all the others take the change from that.
mydestination
The default looks like this:
mydestination = mail.democloud.com, local.democloud.com, , localhost
using the variable saves a lot of possible administrative headaches at a later date.
mynetworks
Defines the network to use. The default includes IPv6 settings which can be removed, leaving :
mynetworks = 127.0.0.0/8
The last section of the main.cf should look like this:
myhostname = mail.democloud.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = $mydomain
mydestination = $mydomain, localhost.$mydomain, localhost
relayhost =
mynetworks = 127.0.0.0/8
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
Test it
As with all administrative changes (not that we made many changes here), it is always a good idea to test them.
Send mail to a working email address:
mail user@example.com
Subject: test
test
.
Cc:
You should receive an email from the correct user and the correct domain - check the headers to see if they are correct.
Last updated
Was this helpful?