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 install and configure Postfix Mail Server on CentOS 8

2025-04-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

How to install and configure Postfix mail server on CentOS 8, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can harvest.

Postfix is an open source email server. Postfix tries to be faster, easier to manage, and more secure, while still maintaining sufficient compatibility with sendmail.

System: CentOS 8 Server

IP address: 192.168.1.13

hostname: server1.crazytechgeek.info (make sure the domain name points to the IP of the server)

Step 1) Update the system

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

# dnf update

Before proceeding, also make sure that no other MTAs (such as Sendmail) exist, as this would cause a conflict with the Postfix configuration. For example, to delete Sendmail, run the following command:

# dnf remove sendmail

Step 2) Set the hostname and update/etc/hosts

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

# hostnamectl set-hostname server1.crazytechgeek.info

# exec bash

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

# vim /etc/hosts

192.168.1.13 server1.crazytechgeek.info

Save and exit the file.

Step 3) Install Postfix Mail Server

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

# dnf install postfix

Install-Postfix-Centos8

Step 4) Start and enable 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've verified that Postfix is up and running. Next, we will configure Postfix to send mail locally to our server.

Step 5) Install 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 Postfix Mail Server

The configuration file for Postfix is located in/etc/postfix/www.example.com. main.cf We need to make some modifications to the profile, so please open it with your favorite text editor:

# vi /etc/postfix/main.cf

Change the following lines:

myhostname = server1.crazytechgeek.info

mydomain = crazytechgeek.info

myorigin = $mydomain

##Uncomment and set inet_interfaces to all##

inet_interfaces = all

##changed to all ##

inet_protocols = all

##Comments ##

#mydestination = $myhostname, localhost.$ mydomain, localhost

##Uncomment ##

mydestination = $myhostname, localhost.$ mydomain, localhost, $mydomain

##Uncomment and Add IP Range ##

mynetworks = 192.168.1.0/24, 127.0.0.0/8

##Uncomment ##

home_mailbox = Maildir/

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

# systemctl restart postfix

Step 7) Test Postfix Mail Server

To test whether our configuration works, 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 described above, you should get the following output:

[root@linuxtechi ~]# telnet localhost 25

Trying 127.0.0.1...

Connected to localhost.

Escape character is '^]'.

220 server1.crazytechgeek.info ESMTP Postfix

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

# ehlo localhost

The output looks like this:

250-server1.crazytechgeek.info

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-STARTTLS

250-ENHANCEDSTATUSCODES

250-8BITMIME

250-DSN

250 SMTPUTF8

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

mail from:pkumar>

250 2.1.0 Ok

rcpt to:postfixuser>

250 2.1.5 Ok

data

354 End data with CR>LF>.CR>LF>

Hello, Welcome to my mailserver (Postfix)

.

250 2.0.0 Ok: queued as B56BF1189BEC

quit

221 2.0.0 Bye

Connection closed by foreign host

Completing the telnet command sends mail 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/new

1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info

#

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

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

Read-postfix-email-linux

Postfix mail server logs

Postfix mail server mail logs are saved in the file/var/log/maillog, use the following command to view real-time logs

# tail -f /var/log/maillog

postfix-maillogs-centos8

Protect Postfix Mail Server

It is recommended that communication between clients and Postfix servers is always secured, which can be achieved using SSL Certificates, which can come from trusted authorities or self-signed certificates. In this tutorial, we will generate a self-signed certificate for Postfix using the openssl command.

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

# dnf install openssl -y

Generate the private key and CSR (certificate signing request) using the following openssl command:

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

Postfix-Key-CSR-CentOS8

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

# openssl x509 -req -days 365 -in mail.csr -signkey mail.key -out mail.crt

Signature ok

subject=C = IN, ST = New Delhi, L = New Delhi, O = IT, OU = IT, CN = server1.crazytechgeek.info, emailAddress = root@linuxtechi

Getting 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 = yes

smtpd_tls_cert_file = /etc/postfix/mail.crt

smtpd_tls_key_file = /etc/postfix/mail.key

smtpd_tls_security_level = may

………

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

# systemctl restart postfix

Let's try using mailx client to send mail to 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

Check and read messages using the following command:

# cd /home/postfixuser/Maildir/new/

# ll

total 8

-rw-------. 1 postfixuser postfixuser 476 Nov 12 17:34 1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info

-rw-------. 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 isn't blacklisted anywhere, your email to the external domain will be sent, otherwise it will be returned with a reminder that your IP is blacklisted by a database such as spamhaus.

Check Postfix message queue

Use mailq to list the messages in the queue:

# mailq

Mail queue is empty

#

ok! Our Postfix configuration works!

Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

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: 217

*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

Development

Wechat

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

12
Report