Following from the Postfix installation article, we can now look at the main.cf file and see what the settings are and what they mean.
Note that these settings are intended for a multiple domain configuration of your mail server.
One of the key aspects of understanding and administering postfix is that it is designed to be a modular package.
By that, I mean that the base installation itself is fairly small and the vast majority of the 'usual' mail administration, such as anti-spam and anti-virus, are actually conducted by third party packages like SpamAssassin .
Although those particular aspects are for a later article, we can begin to see the modular nature of Postfix when we look at the main.cf file.
Many settings refer to other files on the Slice. This setup can, at first, seem slightly confusing and the initial reaction may be to hard code the data rather than reference another file with a single word in it.
I would advise sticking with the modular premise of Postfix and editing multiple files for what may seem like one simple setting.
It makes a lot more sense when we start adding multiple domains, users and aliases to our setup.
So what is this main.cf file?
Let's take a look:
sudo nano /etc/postfix/main.cf
I won't paste it here as we are only going to look at a few settings.
The settings we want to look at are as follows on the demo slice:
#myhostname = host.domain.tld alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases #myorigin = $myhostname #mynetworks = 18.104.22.168/28, 127.0.0.0/8 inet_interfaces = localhost #home_mailbox = Maildir/
Although some of the settings may be self explanatory, let's go through some of them so we have a better understanding of the nature of postfix and what we can do with it at this early stage.
This setting is used to specify the fully-qualified domain name of the slice. By default, the myhostname setting will use the hostname of the slice. As discussed earlier, Postfix is modular in nature and many settings do not need to be hard coded.
With that said, we are going to explicitly define the hostname as many other settings rely on this to option to be set correctly.
myhostname = mail.demoslice.com
This will allow us to ensure that no unexpected issues arise as a result of the hostname setting.
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:
alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases
Have a look at the file:
sudo nano /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 setup the postmaster, news, webmaster, abuse, etc users for Postfix as mail delivered to those 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:
Remember, 'demo' is the main admin user for this Slice.
You may notice that there will be up to three changes in delivery destination:
Mail sent to 'mailer-daemon' is sent to postmaster.
Mail to postmaster is sent to root, and we have just added that all mail sent to root is sent to the 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 also makes for easier migration and 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:
This setting is important as internal emails from packages such as cron jobs do not supply full mail 'credentials' such as sender email. Instead, they rely on 'myorigin' setting. As such, it needs to be set to the main hostname of the Slice.
By default, the setting refers to the $myhostname parameter. However, there is another way of setting 'myorigin' and that is to use the '$mydomain' option in the main.cf file like this:
myorigin = $mydomain
We haven't specifically set the $mydomain variable at any point but postfix gets the information from the 'myhostname' setting - parsing the hostname to gain the main domain name.
The advantage of setting 'myorigin' as shown is that it will make for easier administration going forward. Changes to only one setting (myhostname) will automatically change the other settings as well.
This setting defines the network that Postfix will allow to send mail. If configured incorrectly, it could allow your mail server to be used as an open relay, which allows unauthorized users to send emails through your slice.
Set this parameter as shown below to only allow your slice to send mail:
mynetworks = 127.0.0.0/8
This setting is used to define the interface that Postfix sends and receives mail on.
The default setting is localhost, so we need to change this to listen on all interfaces.
inet_interfaces = all
Finally, we need to specify the format for our mailbox. The default is to place mail in one file located in /var/spool/mail/user.
We want to clean this up a little bit in favor of a qmail-style delivery for our messages.
Therefore, we need to uncomment the following line:
home_mailbox = Maildir/
The remaining settings can be left unchanged at this stage.
They will come into play later on when we look at some more complex configurations but, for the moment, they are not needed and can be left at the defaults.
After the changes we have made, the settings we discussed in this article should look like this in the main.cf file:
myhostname = mail.demoslice.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = $mydomain mynetworks = 127.0.0.0/8 inet_interfaces = all home_mailbox = Maildir/
Now we can move onto restarting Postfix.
As with all packages, once you have made any changes to the configuration, you will need to restart it:
sudo /etc/init.d/postfix restart
Once that is done, we can conduct a quick test.
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 email@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.
Getting involved in the configuration of Postfix can be a daunting task.
This introduction should help with the basics, showing that Postfix is simple in its approach and design, and how using variables instead of hard coding can save time and effort in future administration.