3

I'm going through the process of setting up a Discourse forum on my server (Ubuntu 12.04 x64) and am getting stuck at the point where I have to configure mailers.

I'm following Discourse's instructions and am stuck trying to configure postfix for Mandrill. It is says to check my fully-qualified domain name by typing hostname -f

When I enter in hostname -f, I get localhost. As far as I know, entering in hostname -f should return mydomainname.com.

When I just enter in hostname, I get mydomainname which is correct because that is what I set my hostname to in /etc/hostname.

Looking at some of my other settings, my /etc/hosts file reads:

127.0.0.1       localhost mydomainname
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

And in my /etc/postfix/main.cf file, I have myhostname set like this:

myhostname = mydomainname.mydomainname.com

(Should this be myhostname = mail.mydomainname.com instead?)

And mydestination is the following:

mydestination = mydomainname.com, localhost, localhost.localdomain, localhost

I'm not that familiar with configuring hostnames. I've been reading Postfix's instructions, but haven't been able to figure it out yet.

Any help on how to get this to work would be greatly appreciated. Thanks.

John K. Ferguson
  • 131
  • 1
  • 1
  • 2

2 Answers2

7

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 lines

    127.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.

Jonathon Reinhart
  • 506
  • 1
  • 8
  • 27
Pothi Kalimuthu
  • 6,117
  • 2
  • 26
  • 38
  • My answer is not about how to receive emails from outside! – Pothi Kalimuthu Jul 31 '17 at 15:10
  • I'm [trying to understand the siginificance of `/etc/mailname`](https://serverfault.com/questions/1063236/what-role-does-etc-mailname-play-in-postfix). I can't find anything in postfix's documentation on it. – bluenote10 May 11 '21 at 16:38
  • 1
    The `hostname -F /etc/hostname` seems to be a mandatory step (or rebooting I presume), thanks! – 4wk_ Mar 28 '22 at 12:10
1

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.

Rahul Patil
  • 2,941
  • 3
  • 14
  • 10
  • Thanks. I edited the `/etc/hosts` file. Then I tried `echo "mail" > /etc/hostname` and got `-bash: /etc/hostname: Permission denied` (even when using sudo). Can I just open up the `/etc/hostname` and change the hostname to mail? Is it safe to change the name? – John K. Ferguson Oct 20 '13 at 06:42
  • @JohnKellyFerguson try with `sudo` or edit file manually – Rahul Patil Oct 20 '13 at 06:43
  • I tried `sudo echo "mail" > /etc/hostname` and got `-bash: /etc/hostname: Permission denied`. – John K. Ferguson Oct 20 '13 at 06:44
  • have you tried with manualy edit that file ? – Rahul Patil Oct 20 '13 at 06:45
  • I am logged into my server as `deploy@myname`. When I go to edit the file using sudo, I change `myname` to `mail` and then save and exit. I then get a message saying: `sudo: unable to resolve host myname`. – John K. Ferguson Oct 20 '13 at 06:47
  • sorry, my mistack, in steps sequence.. first we need to run `sudo hostname mail` set hostname, then to permanent save, need to add in `/etc/hostname` – Rahul Patil Oct 20 '13 at 06:51
  • @JohnKellyFerguson I have tested above steps in my ubuntu, so please once do check and let me know if you are facing any issue.. – Rahul Patil Oct 20 '13 at 06:56