Postfix is an open source mail server, also known as a Mail Transfer Agent (MTA), which relays mail locally or to a destination server outside the network.
In this post guide, we will cover how to install Postfix on RHEL 8 / CentOS 8.
Step 1: Uninstalling Sendmail
First you need to check whether sendmail is already installed :
[root@mail ~]# rpm -qa | grep sendmail
If it is installed, you will get an output similar to that shown below :
[root@mail ~]# rpm -qa | grep sendmail sendmail-8.14.7-6.el7.x86_64
If nothing is displayed, that’s mean sendmail is not installed.
To uninstall sendmail use the dnf command bellow :
[root@mail ~]# dnf remove sendmail Loaded plugins: fastestmirror Resolving Dependencies --> Running transaction check ---> Package sendmail.x86_64 0:8.14.7-6.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================== Package Arch Version Repository Size Removing: sendmail x86_64 8.14.7-6.el7 @base 1.7 M Transaction Summary Remove 1 Package Installed size: 1.7 M Is this ok [y/N]:
Installing Postfix
The Postfix configuration file is /etc/postfix/main.cf , we need to edit this file to make the configuration :
[root@mail ~]# vim /etc/postfix/main.cf
Uncomment the lines below and change the values to match your environment :
myhostname = smtp.mondomain.lan mydomain = mondomain.local myorigin = $mydomain inet_interfaces = all inet_protocols = all mydestination = $myhostname, localhost.$mydomain, localhost, mynetworks = 192.168.2.0/24, 127.0.0.0/8 home_mailbox = Maildir/
Then restart the service :
[root@mail ~]# systemctl restart postfix.service [root@mail ~]# systemctl status postfix.service ● postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2021-07-17 13:11:38 EDT; 7s ago Process: 10150 ExecStop=/usr/sbin/postfix stop (code=exited, status=0/SUCCESS) Process: 10165 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS) Process: 10163 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS) Process: 10159 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS) Main PID: 10237 (master) CGroup: /system.slice/postfix.service ├─10237 /usr/libexec/postfix/master -w ├─10238 pickup -l -t unix -u └─10239 qmgr -l -t unix -u Jul 17 13:11:38 mail systemd[1]: Stopped Postfix Mail Transport Agent. Jul 17 13:11:38 mail systemd[1]: Starting Postfix Mail Transport Agent… Jul 17 13:11:38 mail postfix/master[10237]: daemon started -- version 2.10.1, configuration /etc/postfix Jul 17 13:11:38 mail systemd[1]: Started Postfix Mail Transport Agent.
Testing the server
Create a test user ( testuser in my case ) :
[root@mail ~]# useradd testuser
[root@mail ~]# cat /etc/passwd |grep testuser testuserx:x:1000:1000::/home/testuser:/bin/bash
Check server access via telnet :
[root@mail ~]# telnet localhost smtp Trying ::1… Connected to localhost. Escape character is '^]'. 220 mail.localdomain ESMTP Postfix
Then send a test e-mail to an e-mail address with the command mail :
[root@mail ~]# echo "Contenu de mon mail" | mail -s "Sujet" adresse@courriel.fr
If your recipient has received the message, your postfix server is up and running.
C’est quoi le réseau CDN et comment fonctionne ?
nmap : les 12 commandes que vous devez connaître
dd (Disk Dump) : 7 exemples pratiques d’utilisation
Transfère des fichiers sous linux : scp, tftp et rsync
Fail2Ban : How to protect Linux services