Detailed guide to installing and configuring Postfix on CentOS 9 for mail forwarding
Step 1: Installing Postfix
- System update Before installing new software, it is important to make sure that all system packages are updated to current versions. To do this, run the command:
This command will update all packages on your server.
sudo dnf update -y
sudo apt update - Installing Postfix Now that the system has been upgraded, you can install Postfix, the mail server that will process and forward email. To install it, perform:
The
sudo dnf install postfix -y
sudo apt install postfix -y-yflag automatically confirms the setting without requesting further confirmation. - Starting and enabling Postfix at boot After installation, you should start Postfix and configure it to start automatically at every system startup:
The first command will start Postfix immediately, and the second command will configure it to start automatically every time the server is switched on.
sudo systemctl start postfix
sudo systemctl enable postfix
Step 2: Configuring Postfix
-
Editing the configuration file Now you need to configure Postfix. To do this, open the main configuration file:
sudo nano /etc/postfix/main.cfHere we will specify the basic parameters of the mail server operation.
-
Configuring Basic Settings In the configuration file, add or modify the following lines:
- myhostname: specifies the domain name of your mail server. Replace
mail.example.comwith your actual domain name. - myorigin: this parameter specifies the domain to be added to outgoing messages.
- mydestination: lists the host names for which this server will accept mail.
- relayhost: specify the ip where the e-mails will be sent to
Example:
myhostname = mail.example.com
myorigin = /etc/mailname
mydestination = $myhostname, localhost.$mydomain, localhost
relayhost =- smtpd_client_restrictions: configure restrictions on receiving mail. Here you can specify from which IP addresses the server will accept messages.
- sender_bcc_maps: this setting allows you to send copies of all outgoing emails to a specified address.
- transport_maps: defines rules for forwarding mail to other servers.
Example:
smtpd_client_restrictions = permit_mynetworks, reject
sender_bcc_maps = hash:/etc/postfix/sender_bcc
transport_maps = hash:/etc/postfix/transport- mynetworks: lists the IP addresses and networks from which mail is allowed to be sent through this server.
Example:
mynetworks = 10.1.99.35/32, 127.0.0.0/8 - myhostname: specifies the domain name of your mail server. Replace
-
Configuring Forwarding to Exchange Server To forward all emails to the Exchange server, you need to create a transport rules file:
sudo nano /etc/postfix/transportAdd a line to this file:
* smtp:[10.1.80.35]Then update the transport table:
sudo postmap /etc/postfix/transport -
Configuring BCC for the sandbox To configure the sandbox to forward copies of all messages to the sandbox, create or edit a file:
sudo nano /etc/postfix/sender_bccAdd the following line:
@example.com bcc@10.1.72.11Update the BCC table:
sudo postmap /etc/postfix/sender_bcc -
Restart Postfix To apply any changes you have made, you must restart Postfix:
sudo systemctl restart postfix
Step 3: Check the setting
- Check the status of the Postfix service Verify that the Postfix service is running correctly:
sudo systemctl status postfix - Checking Postfix logs To diagnose possible problems, you can view Postfix logs:
sudo tail -f /var/log/maillog