How can I configure myhostname to work with Postfix?
There are multiple files involved in setting up a proper Ubuntu server (12.04.x) for email. Here's the list of those as available at the moment in my server.
-
/etc/hosts
- This file in my Ubuntu server has the following line, among other lines127.0.1.1 myhostname.mydomainname.tld myhostname
Note: Please never touch the line that contains
127.0.0.1
. It may be generated and / or updated by the web host upon each reboot. -
/etc/hostname
- This file in my Ubuntu server has the following content.myhostname
-
/etc/mailname
- This file in my Ubuntu server has the following content.mydomainname.tld
-
/etc/postfix/main.cf
- This file in my Ubuntu server has the following lines, among others...myorigin = /etc/mailname myhostname = myhostname.mydomainname.tld mydestination = localhost, myhostname.mydomainname.tld
Once all the above files have the expected content, you may run the following commands to let them all work together while sending emails...
$ sudo hostname -F /etc/hostname
$ sudo service postfix restart
If you have a server, exclusively for email, I'd recommend keeping the hostname
as mail
. Otherwise, use any hostname
and keeping sending the emails as mydomainname.tld
using Mandrill.
Make sure, everything works as expected even upon a reboot. You wouldn't want your web host to override any files upon reboot, that may affect the email sending / receiving.
I hope that helps.
Make changes in your /etc/hosts
file as below :
<IP> <FQDN> <ALIAS>
So in your case it would be :
127.0.0.1 mail.mydomainname.com mail
then do following changes :
if you are using Ubuntu:
Edit /etc/hostname and change to the new value,
nano /etc/hostname
if you are using RHEL/CentOS:
Edit: /etc/sysconfig/network
HOSTNAME=mail.mydomainname.com
then you can run following command to apply changes .
hostname mail
then check.