Skip to content
Home ยป Configuring the Postfix Server and Running the Server

Configuring the Postfix Server and Running the Server

Configuring the Postfix Server and Running the Server


1. Introduction

After installing Postfix, the next step is configuration and running the server so that it can properly send and receive emails using SMTP.

๐Ÿ‘‰ Configuration ensures:

  • Correct domain setup
  • Proper mail routing
  • Security and reliability

2. Main Configuration File

Postfix configuration is done in:

/etc/postfix/main.cf

๐Ÿ‘‰ This file contains all core settings of the mail server.


3. Basic Configuration of Postfix

Edit the configuration file:

sudo vi /etc/postfix/main.cf

3.1 Essential Parameters

1. Hostname

myhostname = mail.example.com
  • Fully qualified domain name (FQDN)

2. Domain Name

mydomain = example.com

3. Origin of Mail

myorigin = $mydomain

4. Network Interfaces

inet_interfaces = all
  • Allows Postfix to listen on all network interfaces

5. Protocol

inet_protocols = ipv4

6. Destination Domains

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
  • Defines domains handled locally

7. Mailbox Location

home_mailbox = Maildir/
  • Stores emails in user home directory

3.2 Relay Configuration (Optional)

relayhost = [smtp.gmail.com]:587
  • Used to forward emails through another SMTP server

3.3 Network Access Control

mynetworks = 127.0.0.0/8
  • Defines trusted networks

4. Running the Postfix Server


4.1 Start Postfix

sudo systemctl start postfix

4.2 Enable at Boot

sudo systemctl enable postfix

4.3 Check Status

sudo systemctl status postfix

4.4 Restart / Reload

sudo systemctl restart postfix
sudo systemctl reload postfix

5. Checking Configuration

Verify Configuration

postfix check

Reload After Changes

sudo systemctl reload postfix

6. Testing the Postfix Server


6.1 Send Test Email

echo "Hello" | mail -s "Test Mail" user@localhost

6.2 Check Mail Queue

mailq

6.3 View Logs

tail -f /var/log/mail.log

7. Mail Flow in Postfix

User โ†’ Postfix โ†’ Mail Queue โ†’ SMTP โ†’ Recipient Server

8. Firewall Configuration

Allow SMTP traffic:

sudo ufw allow 25

For CentOS:

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

9. Important Postfix Commands

CommandPurpose
postfix startStart server
postfix stopStop server
postfix reloadReload config
mailqShow mail queue
postqueue -fFlush queue

10. Common Issues & Troubleshooting

ProblemSolution
Mail not sendingCheck logs
Port 25 blockedOpen firewall
Wrong hostnameFix myhostname
DNS issuesConfigure MX record

11. Real-World Example

  • Company mail server:
    • Domain: example.com
    • Postfix handles outgoing emails
    • Users send emails via SMTP

12. Advantages of Proper Configuration

  • Reliable email delivery
  • Secure communication
  • Efficient mail routing
  • Reduced spam issues

13. Conclusion

Configuring and running Postfix is essential for building a functional email server in Linux. Proper setup of parameters, services, and security ensures smooth, secure, and reliable email communication in real-world environments.