Set Up Local Email Forwarding
Linux Training Architect II in Content
A Linux system administrator should have a basic understanding of working with local email accounts. Many services will forward email messages to the local administrator (
root) containing notifications about tasks and other relevant system information. Understanding how to forward an email on a local system is important in making sure that a system administrator does not miss out on any essential information. This learning activity will assist you in developing the skills necessary to set up local email forwarding on a system and learning how to access that email.
Set up Local Email Forwarding
We've just taken over a new server, and it needs some further configuration. Any email bound for the
root user needs to be forwarded to our
cloud_user account so that we can keep tabs on the system. Once we've finish modifying the email aliases, we'll test by sending
root an email with an attachment, and verifying that the email landed in
Get logged in
Use the credentials and server IP in the hands-on lab overview page to log into our lab server.
Set up the Alias
First, let's switch to the
[cloud_user@host]$ sudo su -
Run the following command to add an alias to all mail destined for the
root user, so that it will instead get sent to the
[root@host]# echo "root: cloud_user" >> /etc/aliases
Re-generate the Aliases Database File
Run the following command to re-generate a new
/etc/aliases.db file so that your new email alias rule gets registered:
Send a Test Email
We need to generate an email to test your new forwarding rule. This command will send a copy of the
/etc/services file as an email attachment, along with the subject line "Just Testing", to the local
[root@host]# mail -s "Just Testing" -a "/etc/services" root@localhost < /dev/null
We are using a null message body, as we are just checking for the attachment.
Read the Email, Then Remove It
Go back to the
cloud_user account, and run the mail command to view the
cloud_user's email message:
[root@host]# exit [cloud_user@host]$ mail
The message sent from the
root user should be in the list. Press the number corresponding to the message (typically 1) and then press Enter. After we've finished reviewing the message (pressing the spacebar with scroll through the attachment), press q to close the message, then press d at the ampersand prompt (
&) to delete the message. Finally, press q to quit the mail application.
All of the mail destined for
root will be forwarded now to
cloud_user. That was our job, and we got it done. Congratulations!