Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure Postfix Mail Server in CentOS 8

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about how to configure Postfix mail server in CentOS 8. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Step 1) Update the system

The first step is to make sure that the system package is up to date. To do this, update the system as follows:

# dnf update

Before continuing, make sure that no other MTA (such as Sendmail) exists, as this will lead to conflicts with the Postfix configuration. For example, to delete a Sendmail, run the following command:

# dnf remove sendmail step 2) set the hostname and update / etc/hosts

Use the following hostnamectl command to set the hostname on the system:

# hostnamectl set-hostname server1.crazytechgeek.info# exec bash

In addition, you need to add the hostname and IP of the system to / etc/hosts:

# vim / etc/hosts192.168.1.13 server1.crazytechgeek.info

Save and exit the file.

Step 3) install the Postfix mail server

After verifying that there are no other MTA running on the system, run the following command to install Postfix:

# dnf install postfix

Install-Postfix-Centos8

Step 4) start and enable the Postfix service

After successfully installing Postfix, run the following command to start and enable the Postfix service:

# systemctl start postfix# systemctl enable postfix

To check the Postfix status, run the following systemctl command:

# systemctl status postfix

Start-Postfix-check-status-centos8

Great, we have verified that Postfix is up and running. Next, we will configure Postfix to send mail locally to our server.

Step 5) install the mailx mail client

Before configuring the Postfix server, we need to install mailx, to install it, run the following command:

# dnf install mailx

Install-Mailx-CentOS8

Step 6) configure the Postfix mail server

The configuration file for Postfix is located in / etc/postfix/main.cf. We need to make some changes to the configuration file, so please open it using your favorite text editor:

# vi / etc/postfix/main.cf

Change the following lines:

Myhostname = server1.crazytechgeek.infomydomain = crazytechgeek.infomyorigin = $mydomain## uncomment and set inet_interfaces to all##inet_interfaces = all## to change to all##inet_ protocols = all## comment # mydestination = $myhostname, localhost.$mydomain, localhost## uncomment # # mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain## uncomment and add IP range # # mynetworks = 192.168.1.0 127.0.0.0Universe # Uncomment # # home_mailbox = Maildir/

When finished, save and exit the configuration file. Restart the postfix service for the changes to take effect:

# systemctl restart postfix step 7) Test Postfix mail server

To test whether our configuration is valid, first, create a test user.

# useradd postfixuser# passwd postfixuser

Next, run the following command to send mail from the local user pkumar to another user postfixuser.

# telnet localhost smtp or # telnet localhost 25

If the telnet service is not installed, you can install it using the following command:

# dnf install telnet-y

When you run the command as mentioned earlier, you should get the following output:

[root@linuxtechi ~] # telnet localhost 25Trying 127.0.0.1...Connected to localhost.Escape character is'^] '.220 server1.crazytechgeek.info ESMTP Postfix

The above results confirm that the connection to the postfix mail server is normal. Next, enter the command:

# ehlo localhost

The output looks like this:

250-server1.crazytechgeek.info250-PIPELINING250-SIZE 10240000250-VRFY250-ETRN250-STARTTLS250-ENHANCEDSTATUSCODES250-8BITMIME250-DSN250 SMTPUTF8

Next, run the orange highlighted commands, such as mail from, rcpt to, data, and finally type quit:

Mail from:250 2.1.0 Okrcpt to:250 2.1.5 Okdata354 End data with. Hello, Welcome to my mailserver (Postfix) .250 2.0.0 Ok: queued as B56BF1189BECquit221 2.0.0 ByeConnection closed by foreign host

Complete the telnet command to send a message from the local user pkumar to another local user postfixuser, as follows:

Send-email-with-telnet-centos8

If everything goes according to plan, you should be able to view the emails sent in the new user's home directory:

# ls / home/postfixuser/Maildir/new1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info#

To read the message, simply use the cat command, as follows:

# cat / home/postfixuser/Maildir/new/1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info

Read-postfix-email-linux

Postfix Mail Server Log

The Postfix mail server mail log is saved in the file / var/log/maillog. Use the following command to view the real-time log

# tail-f / var/log/maillog

Postfix-maillogs-centos8

Secure the Postfix mail server

It is recommended that you always secure communication between the client and the Postfix server, which can be achieved using SSL certificates, which can come from trusted authorities or self-signed certificates. In this tutorial, we will use the openssl command to generate a self-signed certificate for Postfix

I assume that openssl is already installed on your system. If not, use the following dnf command:

# dnf install openssl-y

Use the following openssl command to generate the private key and CSR (certificate signing request):

# openssl req-nodes-newkey rsa:2048-keyout mail.key-out mail.csr

Postfix-Key-CSR-CentOS8

Now, use the following openssl command to generate a self-signed certificate:

# openssl x509-req-days 365-in mail.csr-signkey mail.key-out mail.crtSignature oksubject=C = IN, ST = New Delhi, L = New Delhi, O = IT, OU = IT, CN = server1.crazytechgeek.info, emailAddress = root@linuxtechiGetting Private key#

Now copy the private key and certificate file to the / etc/postfix directory:

# cp mail.key mail.crt / etc/postfix

Update the path to the private key and certificate file in the Postfix configuration file:

# vi / etc/postfix/main.cf. Smtpd_use_tls = yessmtpd_tls_cert_file = / etc/postfix/mail.crtsmtpd_tls_key_file = / etc/postfix/mail.keysmtpd_tls_security_level = may.

Restart the Postfix service for the above changes to take effect:

# systemctl restart postfix

Let's try to use the mailx client to send messages to the internal local domain and external domain.

Send internal local mail from pkumar to postfixuser:

# echo "test email" | mailx-s "Test email from Postfix MailServer"-r root@linuxtechi root@linuxtechi

Use the following command to check and read the message:

# cd / home/postfixuser/Maildir/new/# lltotal 8 RWMI. 1 postfixuser postfixuser 476 Nov 12 17:34 1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.infomurrwmuri. 1 postfixuser postfixuser 612 Nov 13 02:40 1573612845.Vfd02I20050bbM466643.server1.crazytechgeek.info# cat 1573612845.Vfd02I20050bbM466643.server1.crazytechgeek.info

Read-Postfixuser-Email-CentOS8

Send mail from postfixuser to external domain (root@linuxtechi.com):

# echo "External Test email" | mailx-s "Postfix MailServer"-r root@linuxtechi root@linuxtechi

Note: if your IP is not blacklisted anywhere, the email you send to the external domain will be sent, otherwise it will be returned and your IP will be blacklisted by a database such as spamhaus.

Check the Postfix message queue

Use the mailq command to list messages in the queue:

# mailqMail queue is empty# above is how to configure the Postfix mail server in CentOS 8. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report