Loading...

Lab 80: Installing and Configuring Postfix (MTA)

Install and start Postfix as a local Mail Transfer Agent (MTA) so the system can deliver service notifications and cron output. Validate service health, set a basic mail domain, and send a test message to the local root mailbox.

mail services core

Scenario

You are responsible for ensuring that system-generated mail (cron output, security alerts, logrotate notices, and service notifications) is delivered locally. The host does not need to relay mail to the internet, but it must have a working local MTA. You will deploy Postfix, enable it at boot, verify it is running, set the system mail domain, and send a test message to confirm delivery is functional.

Operator context

A local MTA is often part of baseline Linux operations even in hardened environments. It ensures alerts and automation output do not disappear silently when no external mail relay is configured.

Objective

  • Install Postfix using the system package manager.
  • Enable and start the postfix service.
  • Verify service health using systemctl status.
  • Configure the system mail name (basic mail domain).
  • Send a test message to the local root user.

What You’ll Practice

  • Installing packages using a distro package manager (apt, pacman, or yum).
  • Managing services with systemctl enable --now.
  • Service verification with systemctl status.
  • Setting a basic mail domain via /etc/mailname.
  • Sending local mail with the mail command.

Walkthrough

Step 1 : Install Postfix.
Note

LPIC environments can vary. Use the package manager that matches your system. In production, prefer the native toolchain (for example, apt on Debian/Ubuntu, dnf on RHEL, pacman on Arch).

Command
# Debian/Ubuntu
sudo apt install postfix

# Arch
sudo pacman -S postfix

# RHEL/CentOS (legacy)
sudo yum install postfix

Installing Postfix provides the MTA components that accept mail from local processes and deliver it to local mailboxes (or relay it if configured).

Installing Postfix... Done.
Step 2 : Enable and start the Postfix service.
Command
sudo systemctl enable --now postfix

This ensures Postfix starts at boot and begins accepting local mail immediately.

Postfix enabled and started.
Step 3 : Check the Postfix service status.
Command
systemctl status postfix

Confirm the unit is active and that the master process is running. This is your baseline verification before you start troubleshooting delivery behavior.

● postfix.service - Postfix Mail Transport Agent
Loaded: loaded (...; enabled; vendor preset: disabled)
Active: active (running) since Fri 2025-11-28 10:23:45 EST; 5min ago
Main PID: 2143 (master)
Step 4 : Set the system mail name (mail domain).
Command
echo 'example.local' | sudo tee /etc/mailname

Setting a mail name establishes a default domain identity used by some mail tooling and Postfix configurations. In a real environment, choose a domain that matches your naming standards.

Mail name set to 'example.local'.
Step 5 : Send a test message to local root.
Command
echo 'Test message' | mail -s 'Hello' root

This validates the local delivery path. In a real workflow, you would also verify the mailbox contents (for example with mail or by inspecting the local spool) and check logs if delivery fails.

Message sent to local root user.
Step 6 : Common verification points when mail does not arrive.
Commands
# View mail queue (if configured)
mailq

# Inspect logs (varies by distro)
journalctl -u postfix --no-pager
# or
tail -n 50 /var/log/mail.log
tail -n 50 /var/log/maillog

These checks help you determine whether mail is stuck in a queue, failing delivery due to configuration, or being rejected by policy. For this lab, the goal is to understand the standard “install, enable, validate, send test mail” workflow.

Reference

  • postfix : Mail Transfer Agent (MTA) commonly used for local and relay mail delivery.
  • systemctl enable --now postfix : Enables Postfix at boot and starts it immediately.
  • systemctl status postfix : Verifies whether the Postfix service is active and running.
  • /etc/mailname : Stores the system mail domain on Debian-based systems; may be referenced by local mail tooling.
  • mail -s : Sends a message with a subject to a local user.
  • mailq : Shows queued mail messages waiting for delivery.