Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

15.2.1 Configure the Postfix service program


May 24, 2021 That's what Linux should learn



Postfix is a free open source e-mail service funded by IBM that is well compatible with Sendmail and facilitates Sendmail users to migrate to Postfix. P ostfix services have better mail delivery capabilities than Sendmail services, and can automatically increase and decrease the number of processes to ensure the high performance and stability of the e-mail system. In addition, the Postfix service program consists of many small modules, each of which can perform specific functions, so it can be flexibly matched to their needs in a production work environment.

Step 1: Install the Postfix service program. T his step is redundant in the RHEL7 system. M r. Liu also wrote this step, the purpose is to let everyone after learning this book not only master the RHEL system, but also immediately get started fedora, CentOS and other mainstream Linux system. T hat way, since these systems don't have postfix service programs installed by default, we can do it ourselves. After installing the Postfix service program, you need to disable the iptables firewall or external users will not be able to access the e-mail system.

[root@linuxprobe ~]# yum install postfix Loaded plugins: langpacks, product-id, subscription-manager rhel7 | 4 .1 kB 00:00 (1/2): rhel7/group_gz | 1 34 kB 00:00 (2/2): rhel7/primary_db | 3 .4 MB 00:00 Package 2:postfix-2.10.1-6.el7.x86_64 already installed and latest version Of Nothing to do (root@linuxprobe) . I f you see the Postfix service program master profile (/etc/postfix/main.cf) for the first time, you are expected to be frightened by the content of about 679 lines. D on't worry, the vast majority of the content here is still comment information. In this book, Mr. Liu has always emphasized the correct way to learn Linux system, and firmly believe that "responsible good teachers should not be the porter of books, but should be a refiner of high-quality content", so after going through the introduction of configuration parameters, as well as combined with many years of operation and operation experience, finally summed up the 7 most important parameters, as shown in Table 15-1.

Table 15-1 Important parameters in the main configuration file of the Postfix service program

Parameter Action myhostname post office system host name mydomain post office system domain name myorigin from the machine to send mail domain name inet_interfaces listening to the network card interface mydestination can receive mail host name or domain name mynetworks settings which hosts can forward messages relay_domains settings can forward which domain messages I n the main profile of the Postfix service program, a total of 5 modifications are required. T he first is to define a variable called myhostname on line 76 to hold the host name of the server. Please remember the name of this variable, the following argument needs to call it:

[root@linuxprobe ~]# vim /etc/postfix/main.cf .................. O mit some of the output information... 6 8 # INTERNET HOST AND DOMAIN NAMES 69 # 70 # The myhostname parameter specifies the internet hostname of this 71 # mail system. T he default is to use the fully-qualified domain name 72 # from gethostname(). $ myhostname is used as a default value for many 73 # other configuration parameters. 7 4 # 75 #myhostname = host.domain.tld 76 myhostname = mail.linuxprobe.com .................. O mit some of the output information... T hen, on line 83, define a variable named mydomain to hold the name of the mail field. You also want to keep this variable name in mind, which will be called below:

78 # The mydomain parameter specifies the local internet domain name. 7 9 # The default is to use $myhostname minus the first component. 8 0 # $mydomain is used as a default value for many other configuration 81 # parameters. 8 2 s 83 mydomain s linuxprobe.com call the previous mydomain variable on line 99 to define the domain in which the message was sent. The benefit of calling variables is that you avoid writing information repeatedly and make it easier to modify it uniformly in the future:

85 # SENDING MAIL 86 # 87 # The myorigin parameter specifies the domain that locally-posted 88 # mail appears to come from. T he default is to append $myhostname, 89 # which is fine for small sites. I f you run a domain with multiple 90 # machines, you should (1) change this to $mydomain and (2) set up 91 # a domain-wide alias database that aliases each user to 92 # [email protected]. 9 3 # 94 # For the sake of consistency between sender and recipient addresses, 95 # myorigin also specifies the default domain name that is appended 96 # to recipient addresses that have no @domain part. 9 7 s 98 #myorigin s $myhostname 99 myorigin s $mydomain The fourth modification is to define the network card listening address on line 116. You can specify which IP addresses of the server you want to use to provide e-mail services to the outside world, or you can simply write all to provide e-mail services on behalf of all IP addresses:

103 # The inet_interfaces parameter specifies the network interface 104 # addresses that this mail system receives mail on. B y default, 105 # the software claims all active interfaces on the machine. T he 106 # parameter also controls delivery of mail to user@[ip.address]. 1 07 # 108 # See also the proxy_interfaces parameter, for network addresses that 109 # are forwarded to us via a proxy or network address translator. 1 10 # 111 # Note: you need to stop/start Postfix when this parameter changes. 1 12 s 113 #inet_interfaces s all 114 #inet_interfaces s $myhostname 115 #inet_interfaces s $myhostname, localhost 116 inet_interfaces s all the last modification is to define the host name or domain name list of receivable messages on line 164. The previously defined myhostname and mydomain variables can be called directly here (or the values in the variables if you do not want to call them):

133 # The mydestination parameter specifies the list of domains that this 134 # machine considers itself the final destination for. 135 # 136 # These domains are routed to the delivery agent specified with the 137 # local_transport parameter setting. By default, that is the UNIX 138 # compatible delivery agent that lookups all recipients in /etc/passwd 139 # and /etc/aliases or their equivalent. 140 # 141 # The default is $myhostname + localhost.$mydomain. On a mail domain 142 # gateway, you should also include $mydomain. 143 # 144 # Do not specify the names of virtual domains - those domains are 145 # specified elsewhere (see VIRTUAL_README). 146 # 147 # Do not specify the names of domains that this machine is backup MX 148 # host for. Specify those names via the relay_domains settings for 149 # the SMTP server, or use permit_mx_backup if you are lazy (see 150 # STANDARD_CONFIGURATION_README). 151 # 152 # The local machine is always the final destination for mail addressed 153 # to user@[the.net.work.address] of an interface that the mail system 154 # receives mail on (see the inet_interfaces parameter). 155 # 156 # Specify a list of host or domain names, /file/name or type:table 157 # patterns, separated by commas and/or whitespace. A /file/name 158 # pattern is replaced by its contents; a type:table is matched when 159 # a name matches a lookup key (the right-hand side is ignored). 1 60 # Continue long lines by starting the next line with whitespace. 1 61 # 162 # See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS". 1 63 s 164 mydestination s $myhostname, $mydomain 165 #mydestination s $myhostname, localhost.$mydomain, localhost, $mydomain 166 #mydestination s $myhostname, localhost.$mydomain, localhost, $mydomain, step 3: Create a login account for the email system. P ostfix, like the vsftpd service, can invoke the account and password of the local system, so it is available to create a regular account on the local system. F inally, restart the configured postfix service program and add it to the boot item. Home and dry!

[root@linuxprobe ~]# useradd boss [root@linuxprobe ~]# echo "linuxprobe" | p asswd --stdin boss Changing password for user boss. p asswd: all authentication tokens updated successfully. [root@linuxprobe ~]# systemctl restart postfix [root@linuxprobe ~]# systemctl enable postfix ln -s '/usr/lib/systemd/system/postfix.service' '/etc/systemd/system/multi-user.target.wants/postfix.service'