This document aims to provide the reader with a detailed understanding of the various components of an email system, including installation, basic configuration, and association. The recommendation is that you use an open source email server(s) in a production environment.
All commands in this document are executed using root(uid=0).
# Modify the main configuration file
Shell(192.168.100.7)>vim/etc/named.conf
options{listen-onport53{192.168.100.7;};...
allow-query{any;};...
};
...
include"/etc/named.rfc1912.zones";
include"/etc/named.root.key";
Shell(192.168.100.7)>named-checkconf/etc/named.conf
# Modify the zone file## In practice, you can replace rockylinux.me with your domain name, such as rockylinux.org
Shell(192.168.100.7)>vim/etc/named.rfc1912.zones
zone"rockylinux.me"IN{typemaster;file"rockylinux.localhost";allow-update{none;};};
Question
What is DNS zone? A DNS zone is the specific portion of a DNS namespace that's hosted on a DNS server. A DNS zone contains resource records, and the DNS server responds to queries for records in that namespace. A DNS server can have multiple DNS zones. Simply put, a DNS zone is the equivalent of a book catalog.
# Modify data file
Shell(192.168.100.7)>cp-p/var/named/named.localhost/var/named/rockylinux.localhost
Shell(192.168.100.7)>vim/var/named/rockylinux.localhost
$TTL1D
@INSOArockylinux.me.rname.invalid.(0;serial
1D;refresh
1H;retry
1W;expire
3H);minimum
NSdns.rockylinux.me.
MX2mail.rockylinux.me.
dnsA192.168.100.7
mailA192.168.100.6
Shell(192.168.100.7)>named-checkzonerockylinux.me/var/named/rockylinux.localhost
zonerockylinux.me/IN:loadedserial0
OK
Start your bind service - systemctl start named.service
We can test whether the hosts under the domain name can resolve properly.
Here I have not inserted the ciphertext password for the relevant email users, which requires the use of doveadm pw -s SHA512-crypt -p twotestandtwo command. See here
Use the $ sign to separate the output text information.
6: It means id. For the SHA-512 encryption algorithm, it is fixed at 6.
8jpmvCw8RqNfHYW4: Also known as "salt". Its main function is to increase the security and improve the difficulty of cracking. The system can randomly generate it or it can be specified manually.
pOlsEZG066eJuTmNHoidtvfWHe/6HORrKkQPwv4eyFxqGXKEXhep6aIRxAtv7FDDIq/ojIY1SfWAQkk7XACeZ0: 86 fixed number of characters. Refers to ciphertext passwords generated by using encryption algorithms.
After installing Postfix, the following files need to be know:
/etc/postfix/main.cf. The main and most important configuration file
/etc/postfix/master.cf. Used to set runtime parameters for each component. In general, no changes are required, except when performance optimization is required.
/etc/postfix/access. Access control file for SMTP.
/etc/postfix/transport. Maps email addresses to relay hosts.
You need to know these binary executable files:
/usr/sbin/postalias. Alias database generation instruction. After this command is executed, /etc/aliases.db is generated based on the /etc/aliases file
/usr/sbin/postcat. This command is used to view the mail content in the mail queue.
compatibility_level = 2. A new mechanism introduced in Postfix 3 is designed to be compatible with previous versions.
data_directory = /var/lib/postfix. The directory where the cached data is stored.
myhostname = host.domain.tld. Important parameters that have been commented out. You need to change it to the hostname under your domain name.
mydomain = domain.tld. Important parameters that have been commented out. You need to change it to your domain name.
myorigin = \$myhostname and myorigin = $mydomain. Important parameters that have been commented out. The main function is to complement the sender's mail suffix. \$ represents a reference parameter variable.
inet_interfaces = localhost. When receiving mails, this parameter indicates the address to be listened. The value is usually modified to "all".
inet_protocols = all. Enable IPv4, and IPv6 if supported
mydestination = \$myhostname, localhost.\$mydomain, localhost. Indicates the reception of mail from the stated destination.
unknown_local_recipient_reject_code = 550. The error code returned when sending to an account that does not exist local domain or rejecting an email.
mynetworks =. Set which hosts' emails can be forwarded.
relay_domains = $mydestination. Set which domains' emails can be forwarded.
alias_maps = hash:/etc/aliases. It is used to define user aliases and requires database support.
alias_database = hash:/etc/aliases. The database to be used by aliases.
home_mailbox = Maildir/. Important parameters that have been commented out. This indicates where the local mailbox is stored.
debug_peer_level = 2. Level of log records.
setgid_group = postdrop. The group identifier used to submit emails or manage queues.
Except for the parameter items mentioned or displayed above, some parameters are hidden and can be viewed through the postconf command. The most important parameters are:
message_size_limit = 10240000. Set the size of a single email (including the body and attachments). The unit of value is B (Bytes).
mailbox_size_limit = 1073741824. Set the capacity limit for a single mailbox user.
smtpd_sasl_type = cyrus. The type of SASL (Simple Authentication and Security Layer) authentication. You can use postconf -a to view.
smtpd_sasl_auth_enable = no. Whether to enable SASL authentication.
smtpd_sasl_security_options = noanonymous. Security options for SASL. Anonymous authentication is off by default.
smtpd_sasl_local_domain =. The name of the local domain.
smtpd_recipient_restrictions =. Filtering of recipients. The default value is empty.
If you encounter this kind of error after running systemctl start postfix.service -- "fatal: open lock file /var/lib/postfix/master.lock: unable to set exclusive lock: Resource temporarily unavailable." Please delete the existing /var/lib/postfix/master.lock file
Testing Postfix configure:
Shell(192.168.100.6)>systemctlstartpostfix.service
Shell(192.168.100.6)>postfixcheck
Shell(192.168.100.6)>postfixstatus
# If the command return 1, it is successful.
Shell(192.168.100.6)>postmap-qmail.rockylinux.memysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
Shell(192.168.100.6)>echo$?1
Shell(192.168.100.6)>postmap-qfrank@mail.rockylinux.memysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
Shell(192.168.100.6)>echo$?1
Shell(192.168.100.6)>postmap-qall@mail.rockylinux.memysql:/etc/postfix/mysql-virtual-alias-maps.cf
frank@mail.rockylinux.me,leeo@mail.rockylinux.me
Yes, both Postfix and Dovecot have very complex configurations, so it is recommended that most GNU/Linux system administrators use open source email servers.
As with postfix, enter the doveconf command to view the complete configuration.
The file description is as follows:
dovecot.conf: The main configuration file of dovecot.
Load sub configuration files through the method of !include conf.d/*.conf. Dovecot doesn’t care which settings are in which files.
The Numeral prefix of the sub configuration file is to facilitate human understanding of its parsing order.
Due to historical reasons there are still some config files that are external to the main dovecot.conf, which are typically named *.conf.ext.
In the configuration file, you can use variables, which are divided into Global variables and User variables, starting with %. See here.
10-auth.conf. Configuration related to identity authentication.
10-logging.conf. Log related configuration. It can be very useful in performance analysis, software debugging, etc.
10-mail.conf. Configuration of mailbox locations and namespaces. By default, the value of the user's mailbox location is empty, which means that Dovecot automatically looks for the mailbox location. When the user does not have any mail, you must explicitly tell Dovecot the location of all mailboxes.
10-metrics.conf. Configuration related to statistical information.
15-mailboxes.conf. Configuration of mailbox definition.
listen = *, ::. A comma separated list of IPs or hosts where to listen in for connections. "*" listens in all IPv4 interfaces, "::" listens in all IPv6 interfaces.
disable_plaintext_auth = yes. Whether to turn off the plaintext password for authentication.
auth_mechanisms =. The type of authentication mechanism whose values can be multiple and separated by Spaces. Values: plain, login, digest-md5, cram-md5, ntlm, rpa, apop, anonymous, gssapi, otp, skey, gss-spnego.
login_trusted_networks=. Which clients (MUA) are allowed to use Dovecot. It can be a separate IP address, it can be a network segment, or it can be mixed and separated by spaces. Like this-- login_trusted_networks = 10.1.1.0/24 192.168.100.2
mail_location =. For an empty value, Dovecot attempts to find the mailboxes automatically (looking at ~/Maildir, /var/mail/username, ~/mail, and ~/Mail, in that order). However, auto-detection commonly fails for users whose mail directory hasn’t yet been created, so you should explicitly state the full location here, if possible.
mail_privileged_group =. This group is enabled temporarily for privileged operations. Currently, this is used only with the INBOX when either its initial creation or dotlocking fails. Typically, this is set to "mail" to access /var/mail.
Shell(192.168.100.6)>vim/etc/dovecot/conf.d/10-mail.conf
...
# %u - username# %n - user part in user@domain, same as %u if there's no domain# %d - domain part in user@domain, empty if there's no domain# %h - home directorymail_location=maildir:/var/mail/vhosts/%d/%n
...
mail_privileged_group=mail
...
Create related directories -- mkdir -p /var/mail/vhosts/rockylinux.me. rockylinx.me refers to the domain name you applied for (called domain or local domain in email).
Add related users and specify home directory -- groupadd -g 2000 vmail && useradd -g vmail -u 2000 -d /var/mail/ vmail
Change owner and group -- chown -R vmail:vmail /var/mail/
Don't write the above grammar on one line, such as this--"userdb {driver = sql args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n}". Otherwise, it won't work.
Create /etc/dovecot/dovecot-sql.conf.ext file and write related content: