#/etc/aliases
mailer-daemon: postmaster
postmaster: root
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root
root: [email protected]
Forwarding System Mail to a Central Mail Server
Redirect system-generated email from multiple GNU/Linux hosts to a single central SMTP server. Set-up lightweight relay-only or full-featured MTAs such as nullmailer, msmtp, Postfix, Exim 4, Sendmail or ssmtp.
1. 1. Configure system aliases to redirect root mail to the central mail server
Edit /etc/aliases and set root to your central e-mail address:
Then run:
newaliases
2. 2. Check whether you already have an MTA installed
readlink -f /usr/sbin/sendmail
If this points at a real binary (Postfix, Exim 4, Sendmail, ssmtp, nullmailer, msmtp), you already have an MTA or send-only client.
3. 3. Install a mail client + relay (if none present)
The mail client used in this guide is bsd-mailx for simplicity, but you can use any you prefer.
For the Mail Transfer Agent there are different options, depending on your needs. If unsure, choose one of the first entries and continue:
-
nullmailer - minimal relay-only MTA with disk queue, recommended
-
msmtp - light on-demand send-only SMTP client with no queue
-
postfix - full-feature MTA with queue, filtering and policy
-
exim4 - monolithic MTA with advanced ACL and routing
-
sendmail - heavyweight but classic, not recommended
-
ssmtp - similar to msmtp, deprecated
4. 4. Configuration
4.1. A. nullmailer
apt update
apt install bsd-mailx nullmailer
|
When installing nullmailer in an interactive frontend, debconf automatically prompts you to set the mailname and smarthost (relay), allowing you to skip the next three steps. |
-
Set your local domain
echo "mysystem.local" | tee /etc/mailname -
Set the relay
echo "hermes.local smtp" | tee /etc/nullmailer/remotes -
Restart
systemctl restart nullmailer
4.2. B. msmtp
apt update
apt install msmtp-mta bsd-mailx
-
Create system-wide config at
/etc/msmtprc(or/etc/msmtp/msmtprc):# Default SMTP relay account default host hermes.local port 25 # no TLS/auth inside trusted LAN tls off auth off # Set envelope-from domain from [email protected] -
Set permissions so only root can read it:
chmod 600 /etc/msmtprc -
Restart isn’t needed, msmtp runs on demand as
/usr/sbin/sendmail.
4.3. C. postfix
apt update
apt install postfix bsd-mailx
-
Set relayhost
postconf -e 'relayhost = [hermes.local]:25' -
Ensure LAN is trusted in
/etc/postfix/main.cf:mynetworks = 127.0.0.0/8, 192.168.0.0/16 # adjust to your LAN -
Reload
newaliases systemctl reload postfix
4.4. D. Exim 4
apt update
apt install exim4-daemon-light bsd-mailx
-
Reconfigure
dpkg-reconfigure exim4-configChoose mail sent by smarthost; no local mail and set the smarthost to
hermes.local::25. -
Restart
systemctl restart exim4
4.5. E. Sendmail
apt update
apt install sendmail bsd-mailx
-
Edit
/etc/mail/sendmail.mcand add:define(`SMART_HOST', `hermes.local')dnl -
Regenerate
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf -
Restart
systemctl restart sendmail
4.6. F. ssmtp (Deprecated - for reference only)
apt update
apt install ssmtp bsd-mailx
Edit /etc/ssmtp/ssmtp.conf:
mailhub=hermes.local:25
AuthMethod=
No daemon to restart; ssmtp hands off on demand.
5. 5. Test end-to-end
Send an e-mail locally, it should automatically be relayed to the central mail server.
echo "Hello from $(hostname)" | mail -s "Test from $(hostname)" root@localhost
On the mail server, watch the log:
tail -f /var/log/mail.log
You should see each client connect and deliver mail successfully.