Postfix mail server setup centos

Here is a step-by-step guide to setting up a Postfix mail server on CentOS:

Prerequisites

Step 1: Install Postfix

  1. Update the package list: sudo yum update
  2. Install Postfix: sudo yum install postfix

Step 2: Configure Postfix

  1. Edit the Postfix configuration file: sudo nano /etc/postfix/main.cf

  2. Add the following lines to the end of the file:

    mydestination = example.com
    myhostname = mail.example.com
    myorigin = $myhostname

    Replace example.com with your domain name.

  3. Save and exit the file.

Step 3: Configure DNS

  1. Create a TXT record for your domain: example.com. IN TXT "v=spf1 a mx ptr?all" This record helps prevent spam by specifying which mail servers are authorized to send mail for your domain.
  2. Create an MX record for your domain: example.com. IN MX 10 mail.example.com This record specifies the mail server responsible for receiving mail for your domain.

Step 4: Configure Postfix to use DNS

  1. Edit the Postfix configuration file: sudo nano /etc/postfix/main.cf

  2. Add the following lines to the end of the file:

    mynetworks = 127.0.0.0/8 [::1]/128
    relayhost =

    The first line specifies the local network (127.0.0.0/8) as the only network allowed to send mail through Postfix. The second line specifies that Postfix should not relay mail to another mail server.

  3. Save and exit the file.

Step 5: Start and enable Postfix

  1. Start Postfix: sudo systemctl start postfix
  2. Enable Postfix to start automatically on boot: sudo systemctl enable postfix

Step 6: Test Postfix

  1. Send a test email from the command line: echo "Test email" | mail -s "Test email" [email protected] Replace [email protected] with a valid email address on your domain.

Step 7: Configure a mail client

  1. Configure a mail client (e.g. Thunderbird, Outlook) to use your Postfix mail server.
  2. Set the mail server to mail.example.com and the port to 25 (or 587 for TLS).

That's it! Your Postfix mail server should now be set up and ready to use.