Initial configuration required from installation of Postfix on CentOS to startup.


Publication date:January 4, 2021



INFOMARTION > Initial configuration required from installation of Postfix on CentOS to startup.

summary

This is the initial configuration procedure required to install and start Postfix on CentOS. This description assumes CentOS7. We would like to configure it with a submission port.

If you are also installing Dovecot, please see here.

Postfix is for sending mail and Dovecot is for receiving mail. Those who need to send mail should install Postfix, and those who want to receive mail should install Dovecot as well.

The versions are as follows

CentOS Version7.6 (1810)
Postfix Version2.10.1

Table of Contents

  1. install
  2. Setting details
  3. summary

1. install

This section describes the configuration of Postfix from installation to startup.

1-1. Installing Postfix

Execute Postfix installation by yum command. Please work as root user.

[username@hostname ~]$ su -
[root@hostname ~]# yum -y install postfix

1-2. Startup Confirmation

Check the startup to confirm that it has been successfully installed.

[root@hostname ~]# /usr/sbin/postfix start
[root@hostname ~]# ps aux | grep postfix
root      1485  0.7  0.2  89744  2128 ?        Ss   16:02   0:00 /usr/libexec/postfix/master -w
postfix   1486  0.2  0.4  89848  4080 ?        S    16:02   0:00 pickup -l -t unix -u
postfix   1487  0.2  0.4  89916  4104 ?        S    16:02   0:00 qmgr -l -t unix -u
root      1489  0.0  0.1 112824   964 pts/0    S+   16:02   0:00 grep --color=auto postfix

If there is a process running as postfix user as described above, it is OK. Let's stop it.

[root@hostname ~]# /usr/sbin/postfix stop

2. Setting details

2-1. initialization

We will do the initial configuration of Postfix. Basically, Postfix configuration is described in "/etc/postfix/main.cf", so we will modify main.cf.

[root@hostname ~]# vi /etc/postfix/main.cf

Correct as follows

main.cf【Before change】


#
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
~omission~
#
#mydomain = domain.tld
~omission~
#myorigin = $myhostname
#myorigin = $mydomain
~omission~
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost
~omission~
mydestination = $myhostname, localhost.$mydomain, localhost
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
#       mail.$mydomain, www.$mydomain, ftp.$mydomain
~omission~
#mynetworks = 168.100.189.0/24, 127.0.0.0/8
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
~omission~
#
#home_mailbox = Mailbox
#home_mailbox = Maildir/

main.cf【After change】


#
myhostname = example.com
#myhostname = virtual.domain.tld
~omission~
#
mydomain = example.com
~omission~
#myorigin = $myhostname
myorigin = $mydomain
~omission~
inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost
~omission~
#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
#       mail.$mydomain, www.$mydomain, ftp.$mydomain
~omission~
mynetworks = 127.0.0.0/8, 192.168.100.0/24
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
~omission~
#
#home_mailbox = Mailbox
home_mailbox = Maildir/

"myhostname", "mydomain", and "myorigin" are settings related to the domain. The "example.com" should be set to the domain name of the server. The "example.com" part of "https://example.com/" is the domain name.

The email address is username@example.com.

"mynetworks" is a setting related to the network. This is an IP address that can be connected to postfix. If the mail server and the server to be linked are different servers, modify this value accordingly.

"home_mailbox" is the mail directory. It stores sent e-mails.

2-2. OS user, or reject if not defined in $alias_maps

Set up the OS user and the user listed in $ALIAS_MAPS to send mail. An OS user is a user added by useradd.

[root@hostname ~]# vi /etc/postfix/main.cf

Correct as follows

main.cf【Before change】


#local_recipient_maps = unix:passwd.byname $alias_maps
#local_recipient_maps = proxy:unix:passwd.byname $alias_maps
#local_recipient_maps =

main.cf【After change】


local_recipient_maps = unix:passwd.byname $alias_maps
#local_recipient_maps = proxy:unix:passwd.byname $alias_maps
#local_recipient_maps =

Add the following to the end of main.cf

main.cf


### MAIL SIZE (20Mbyte)
message_size_limit = 20971520
### TLS
smtpd_use_tls = yes
smtpd_tls_cert_file = /etc/pki/tls/certs/localhost.crt
smtpd_tls_key_file = /etc/pki/tls/private/localhost.key

Set "smtpd_tls_cert_file" and "smtpd_tls_key_file" according to your environment. Set the path where the server certificate is stored.

SSL settings are required in advance, so if you have not set up SSL settings, please do so first. Please refer to the following.

Initial configuration required from installation of Apache on CentOS to startup

2-3. postfix submission port settings

Configure the settings for sending mail using the submission port.

[root@hostname ~]# vi /etc/postfix/master.cf

※Note that the file to be edited is not "main.cf" but "master.cf", so the file names are similar.

Correct as follows

master.cf【Before change】


#submission inet n - n - - smtpd
~omission~
#-o smtpd_sasl_auth_enable=yes
~omission~
#-o smtpd_client_restrictions=$mua_helo_restrictions
~omission~
#-o smtpd_sender_restrictions=$mua_sender_restrictions
~omission~
#-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject

master.cf【After change】


submission inet n - n - - smtpd
~omission~
-o smtpd_sasl_auth_enable=yes
~omission~
-o smtpd_client_restrictions=permit_sasl_authenticated
~omission~
-o smtpd_sender_restriction=permit_sasl_authenticated
~omission~
-o smtpd_recipient_restrictions=permit_sasl_authenticated


Install the necessary libraries for SASL authentication with yum.

[root@hostname ~]# yum -y install cyrus-sasl
[root@hostname ~]# yum -y install cyrus-sasl-plain
[root@hostname ~]# yum -y install cyrus-sasl-md5
[root@hostname ~]# yum -y install cyrus-sasl-devel

Edit saslauthd to use UNIX accounts for authentication.

[root@hostname ~]# vi /etc/sysconfig/saslauthd

Correct as follows

saslauthd


#MECH=pam
MECH=shadow

2-4. Enable SASL

Enable SASL.

[root@hostname ~]# systemctl enable saslauthd
[root@hostname ~]# systemctl is-enabled saslauthd
enabled
[root@hostname ~]# systemctl list-unit-files --type=service | grep saslauthd
saslauthd.service                                enabled
[root@hostname ~]# systemctl daemon-reload

2-5. Startup Confirmation

Check if Postfix starts.

[root@hostname ~]# /usr/sbin/postfix start
[root@hostname ~]# ps aux | grep postfix
root      1838  0.0  0.1  89744  2080 ?        Ss   18:14   0:00 /usr/libexec/postfix/master -w
postfix   1839  0.0  0.3  89848  3988 ?        S    18:14   0:00 pickup -l -t unix -u
postfix   1840  0.0  0.3  89916  4008 ?        S    18:14   0:00 qmgr -l -t unix -u
root      1845  0.0  0.0 112824   968 pts/0    S+   18:15   0:00 grep --color=auto postfix

If there is a process running as the postfix user as shown above, the configuration has been successfully completed and the process is running. Now that the startup has been confirmed, let's stop the process.

[root@hostname ~]# /usr/sbin/postfix stop

2-6. Automatic startup setting

Lastly, although it is not required, it is hard to start Postfix every time the server is rebooted, so we will configure Postfix to start automatically when the server starts. Register the systemctl command to the systemctl command. Please note that this procedure is for CentOS7, so those who are using other than CentOS7 need to use the service command.

Check if "/usr/lib/systemd/system/postfix.service" exists. If not, create "postfix.service" as follows Execute as root user.

[root@hostname ~]# touch /etc/systemd/system/postfix.service
[root@hostname ~]# vi /etc/systemd/system/postfix.service

The following information is provided

[Unit]
#Description.
Description=Postfix
#Control before and after execution
#Before=xxx.service
After=syslog.target network.target

[Service]
#User and group designation
User=root
Group=root
#Once activated, set the status to Activated.
Type=oneshot
RemainAfterExit=yes
#Start, stop, reload
ExecStart=/usr/sbin/postfix start
ExecStop=/usr/sbin/postfix stop
ExecReload=/usr/sbin/postfix reload

[Install]
#runlevel3 equivalent setting
WantedBy=multi-user.target

Next, register it with the systemctl command.

[root@hostname ~]# systemctl enable postfix
[root@hostname ~]# systemctl is-enabled postfix
enabled
[root@hostname ~]# systemctl list-unit-files --type=service | grep postfix
postfix.service                                enabled
[root@hostname ~]# systemctl daemon-reload

3. summary

We have described the initial configuration required when Postfix is installed.

I struggled with the setup quite a bit, so please refer to this if you are building Postfix.

Thank you for taking the time to read this to the end.




■INFORMATION

Please click here to go to the top page of INFORMATION.


■PROFILE

Please click here to view the profile.


■For inquiries, please contact

For inquiries about the article, please contact us here.