Set hostname (REQUIRED)
Postfix is very sensitive to the system hostname.
hostnamectl set-hostname mail.yourdomain.id
Edit /etc/hosts:
nano /etc/hosts
Add:
127.0.1.1 mail.yourdomain.id mail
Verify:
hostname
hostname -f
The output must be:
mail.yourdomain.id
Install Postfix
apt update
apt install postfix mailutils -y
When the setup wizard appears, choose:
- General type: Internet Site
- System mail name: mail.yourdomain.id
Check Postfix service
systemctl status postfix
ss -lntp | grep :25
Postfix must be listening on port 25.
Basic Postfix hardening
Edit the configuration file:
nano /etc/postfix/main.cf
Ensure the following settings:
myhostname = mail.yourdomain.id
mydomain = yourdomain.id
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost
mynetworks = 127.0.0.0/8, [::1]
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP
# Prevent open relay
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination
Restart Postfix:
systemctl restart postfix
Test local email delivery
echo "Postfix OK" | mail -s "Test Email" root
Check inbox:
mail
Test outbound (internet) email
echo "Hello from Ubuntu Postfix" | mail -s "Test SMTP" your@gmail.com
Monitor the mail log:
tail -f /var/log/mail.log
–have trying..
Leave a Reply