第 2 章 Deploying and configuring a Postfix SMTP server


As a system administrator, you can configure your email infrastructure by using a mail transport agent (MTA), such as Postfix, to transport email messages between hosts by using the SMTP protocol. Postfix is a server-side application for routing and delivering mail. You can use Postfix to set up a local mail server, create a null-client mail relay, use a Postfix server as a destination for multiple domains, or choose an LDAP directory instead of files for lookups.

The postfix package provides multiple configuration files in the /etc/postfix/ directory.

To configure your email infrastructure, use the following configuration files:

  • main.cf: contains the global configuration of Postfix.
  • master.cf: specifies Postfix interaction with various processes to accomplish mail delivery.
  • access: specifies access rules, for example hosts that are allowed to connect to Postfix.
  • transport: maps email addresses to relay hosts.
  • aliases: contains a configurable list required by the mail protocol that describes user ID aliases. Note that you can find this file in the /etc/ directory.

The key features of Postfix:

  • Security features to protect against common email related threats
  • Customization options, including support for virtual domains and aliases

2.1. Installing and configuring a Postfix SMTP server

You can configure your Postfix SMTP server to receive, store, and deliver email messages. If the mail server package is not selected during the system installation, Postfix will not be available by default. Perform the following steps to install Postfix:

Prerequisites

Procedure

  1. Remove the Sendmail utility:

    # dnf remove sendmail
  2. Install Postfix:

    # dnf install postfix
  3. To configure Postfix, edit the /etc/postfix/main.cf file and make the following changes:

    1. By default, Postfix receives emails only on the loopback interface. To configure Postfix to listen on specific interfaces, update the inet_interfaces parameter to the IP addresses of these interfaces:

      inet_interfaces = 127.0.0.1/32, [::1]/128, 192.0.2.1, [2001:db8:1::1]

      To configure Postfix to listen on all interfaces, set:

      inet_interfaces = all
    2. If you want that Postfix uses a different hostname than the fully-qualified domain name (FQDN) that is returned by the gethostname() function, add the myhostname parameter:

      myhostname = smtp.example.com

      For example, Postfix adds this hostname to header of emails it processes.

    3. If the domain name differs from the one in the myhostname parameter, add the mydomain parameter:

      mydomain = example.com
    4. Add the myorigin parameter and set it to the value of mydomain:

      myorigin = $mydomain

      With this setting, Postfix uses the domain name as origin for locally posted mails instead of the hostname.

    5. Add the mynetworks parameter, and define the IP ranges of trusted networks that are allowed to send mails:

      mynetworks = 127.0.0.1/32, [::1]/128, 192.0.2.1/24, [2001:db8:1::1]/64

      If clients from not trustworthy networks, such as the internet, should be able to send mails through this server, you must configure relay restrictions in a later step.

  4. Verify if the Postfix configuration in the main.cf file is correct:

    # postfix check
  5. Enable the postfix service to start at boot and start it:

    # systemctl enable --now postfix
  6. Allow the SMTP traffic through firewall and reload the firewall rules:

    # firewall-cmd --permanent --add-service smtp
    # firewall-cmd --reload

Verification

  1. Verify that the postfix service is running:

    # systemctl status postfix
    • Optional: Restart the postfix service, if the output is stopped, waiting, or the service is not running:

      # systemctl restart postfix
    • Optional: Reload the postfix service after changing any options in the configuration files in the /etc/postfix/ directory to apply those changes:

      # systemctl reload postfix
  2. Verify the email communication between local users on your system:

    # echo "This is a test message" | mail -s <subject> <user@mydomain.com>
  3. To verify that your mail server does not relay emails from external IP ranges to foreign domains, follow the below mentioned procedure:

    1. Log in to a client which is not within the subnets that you defined in mynetworks.
    2. Configure the client to use your mail server.
    3. Try to send an email to an email address that is not under the domain you specified in mydomain on your mail server. For example, try to send an email to non-existing-user@redhat.com.
    4. Check the /var/log/maillog file:

      554 Relay access denied - the server is not going to relay.
      250 OK or similar - the server is going to relay.

Troubleshooting

  • In case of errors, check the /var/log/maillog file.
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部