Email - preparing the Slice

Beginning a series of articles on many aspects of email (sending, receiving, configuring, etc), we need to start with the very basics by preparing the Slice.

This article looks at the hostname and reverse DNS (RDNS) settings on the Slice.


Assumptions

The only assumptions made for these email articles are:

1: You are running Ubuntu Hardy (The instructions may work on other distros but it has not been tested and is not guaranteed)

2: You have followed the setup articles: page 1 and page 2

Beyond that, I hope to show everything that is needed from the very basics upwards.

Hostname

The first thing to look at is the Slice hostname.

This is simply the 'name' of the Slice and is used in the headers of the email (the headers can be thought of as the address and sender label on the email).

There are a couple of ways of setting the host name.

Slicemanager

When you build a new Slice or rebuild a Slice, you are given the opportunity to set the Slice name - this can be a FQDN (Fully Qualified Domain Name). This name is then used to set the hostname when the Slice is built.

This can be a quick and easy way of setting the hostname.

However, you do not have restrict your Slice name to match that of the hostname.

On the demo account I have a Slice named 'slice1'. As such, the hostname of the Slice was initially set as 'slice1'.

I don't want to rebuild the Slice and I am happy with the Slicemanager name of 'slice1'. As such, let's look at changing the hostname from the command line:

Command Line

Setting the hostname via the command line involves the very simple adjustment of a couple of files.

We can start by checking what the current hostname is:

hostname -f

On my Slice, the output is:

slice1

Well, that makes sense. When I built the Slice I named it 'slice1' in the Slicemanager. As such, the hostname was set to 'slice1'.

mail.demoslice.com

For these basic articles I am going to use the domain 'mail.demoslice.com' - I am setting up a mail server so that makes sense.

I need to change the hostname to match the domain:

sudo nano /etc/hostname

Replace the current hostname (slice1) with the one you need (in this case mail.demoslice.com).

The second file to edit is:

sudo nano /etc/hosts

The default looks like this on my Slice:

127.0.0.1       localhost localhost.localdomain
127.0.0.1       slice1

Following on from what we are doing, replace 'slice1' with 'mail.demoslice.com'.

Of course, replace mail.demoslice.com with your domain.

reboot

Conduct a quick reboot:

sudo reboot

and check the hostname:

hostname -f

The output is now:

mail.demoslice.com

Good start!

Reverse DNS

The second main aspect we need to look at when preparing the Slice is the Reverse DNS (RDNS).

One of the main reasons for email being marked as spam and causing IP addresses to be blocklisted is a mismatch between the sending domain and the RDNS of the Slice.

We can check the RDNS of the Slice from the Slicemanager.

Log into the Slicemanager

Once done, click the DNS tab and then the 'Reverse DNS' link.

On the demo account, one of the Slices has this record as the default:

Slicemanager - Reverse DNS

All we need to do is change the default entry to match our main domain:

Slicemanager - Changing the RDNS

Done.

Check the RDNS

The RDNS may take a while to propagate and you really need to wait until it has done so before you can fully configure and test any mail setup.

To check the RDNS, you need to input the IP address if the Slice into the 'dig' command.

Note that 'dig' is not installed on a base Ubuntu Hardy Slice:

sudo aptitude install dnsutils

(Many thanks for the comments that noted dig is not installed by default - I use my workstation to conduct dig commands and didn't think that others may use the Slice for that!)

So, to check the RDNS:

dig -x 208.75.84.20

In this case, the output includes the correct answer:

dig -x 208.75.84.20
...
...
;; QUESTION SECTION:
;20.84.75.208.in-addr.arpa.     IN      PTR

;; ANSWER SECTION:
20.84.75.208.in-addr.arpa. 3477 IN      PTR     mail.demoslice.com.

Done.

Summary

Preparing the Slice is a vital step in any mail setup - even if 'only' sending mail from your application to an administrator, it is very important to get the basics right.

As the articles progress you will start to see where this preparation comes into play when sending and receiving emails.

PickledOnion

Article Comments:

Luke commented Mon Jul 28 22:15:27 UTC 2008:

I think I said this before but I'd like to say it again. Your articles are excellent and very much appreciated!

Jose commented Tue Jul 29 00:40:27 UTC 2008:

Looking forward for the upcoming postfix article.

Alesandro commented Tue Jul 29 02:28:58 UTC 2008:

I don't know if an article on setting up SPF (or other e-mail sender verification methods) is on the schedule, but it seems perfect for this series. I've yet to find a good article on setting up SPF.

Thanks for the excellent articles!

PickledOnion commented Tue Jul 29 10:22:27 UTC 2008:

Alesandro,

I do plan on covering SPF records during the series.

PickledOnion

davemck commented Tue Jul 29 16:19:51 UTC 2008:

I get "command not found" when I try to dig. There is no manual entry for it either.

dozens commented Wed Jul 30 00:20:58 UTC 2008:

Yeah, what is the path to dig ?

jfrench commented Wed Jul 30 01:23:25 UTC 2008:

dig is not pre-installed on Ubuntu 8. Get it with sudo apt-get install dnsutils

PickledOnion commented Wed Jul 30 09:21:50 UTC 2008:

Hi,

Thanks for the comments regarding dig. I have adjusted the article to reflect the installation of dig.

I use my workstation for dig queries and I did not think of people using the Slice.

As an aside, please note that apt-get was depreciated a couple of years ago and the last distro that it is recommended to use it with is Ubuntu Dapper LTS.

It has been recommended to use 'aptitude' since then.

PickledOnion

dedekind commented Thu Jul 31 14:49:25 UTC 2008:

I'm not sure I get this. Why do you choose demoslice.com as your hostname? Is this the name of your main website (that you are pointing towards the slicehost nameservers)? Are you planning on making emails like pickledOnion@slicehost.com is that why you choose this hostname?

What if I have a bunch of domains (say foo.com and bar.com) and want to make email addresses for both domains, say dede@foo.com and dede@bar.com ?

PickledOnion commented Thu Jul 31 17:48:48 UTC 2008:

Hi,

As I mention in this and the other articles, this is for a single domain only.

I will get onto multiple domains at a later article.

I use the domain demoslice.com as it is a demonstration domain name.

You use your own main domain.

I am not sure what you mean in your comment about making emails for a different domain - you mention making an email for slicehost.com which has nothing to do with the main domain used in the articles (demoslice.com).

PickledOnion

Michael commented Fri Aug 01 21:42:30 UTC 2008:

to install dig on Fedora 9 using yum: yum install bind-utils

Hope this helps someone.

dedekind commented Mon Aug 04 18:06:29 UTC 2008:

Yes oops. Didn't mean to say slicehost.com there earlier. Just a typo.

But anyway, I somehow find it strange to be changing the hostname of the whole slice from slicename to mail.whatever.com. Because this will change the Bash prompt's feedback from username@slicename to username@mail.whatever.com, which I found very weird...

dedekind commented Mon Aug 04 18:20:38 UTC 2008:

Correction: I meant to say that in Bash, that "mail" thing sits screaming at you at all times. So in the above, I made a typo. "username@mail.whatever.com" was only supposed to be "username@mail". Is there any way to do this thing without changing the machine's hostname? Seems kind of weird to change the whole hostname just to incorporate email...

PickledOnion commented Tue Aug 05 10:36:16 UTC 2008:

dedekind,

I am not really sure what your question is - as explained in the articles, the hostname is needed to set the correct details in the email headers.

It is as simple as that.

Not sure what the 'mail' thing is you are referring to? Do you mean the bash prompt? If so, edit the .bash_config file to change it to one you prefer.

PickledOnion

Barry commented Wed Aug 06 03:32:24 UTC 2008:

For the main domain name on my server, I'm using Google Apps for my email.

Can I still use this setup to send emails from my server even if my MX records are directing mail to Google?

Is there a way to setup my server to use Google's SMTP servers?

archondigital commented Thu Aug 07 08:25:39 UTC 2008:

I would also like to know how postfix would work if the mail.domain.com points to Google Apps. Thanks.

FatherShawn commented Thu Aug 14 10:34:11 UTC 2008:

I'm wondering why you would set the RDNS to mail.demoslice.com and not simply demoslice.com?

PickledOnion commented Sun Aug 17 09:37:59 UTC 2008:

Hi,

I set the hostname to mail.demoslice.com as the Slice is the mail server for demoslice.com.

I could host the main domain anywhere.

It is impossible to cover every possible eventuality for Slice setups and the simplest thing to do is to concentrate on one thing.

In the email articles, we are looking at email - that is to say, running a mail server.

As such, the hostname and RDNS are set to the mail server domain.

I hope that helps.

PickledOnion

nerb commented Sat Aug 23 15:52:33 UTC 2008:

So it is fair to say then, that if we only own ONE slice, and run both our websites and mail from the same slice, we would need to just ensure that reverse DNS is working and that we have SOME name in the hostname -f.

correct?

Mike commented Fri Sep 19 16:14:03 UTC 2008:

When I change the hostname and reboot, the command 'hostname -f' returns: hostname: Unknown host

Jay commented Thu Oct 16 14:51:18 UTC 2008:

I get the same problem as Mike. Also, this is a web / mail server, so why am I doing this?

Jeremy Lim commented Tue Dec 02 05:07:58 UTC 2008:

As a complete klutz with anything that doesn't have a GUI, I can't tell you how grateful I am for this series.

So much love, PickledOnion!

Baruch commented Thu Dec 04 05:48:22 UTC 2008:

Like some others, I got a peculiar prompt (baruch@mail). Also, when I tried running hostname -f, I got "Unknown Host".

Furthermore, my Websites no longer worked, nor did webmin.

I don't understand this article, nor is my system responding as described, even though I followed the directions faithfully. I am confused.

PickledOnion commented Thu Dec 04 10:58:46 UTC 2008:

Baruch,

Not sure what is peculiar about the prompt. If you don't like it, then you can change it by following the Slice setup articles. It shows exactly what we set it to show.

If you are having issues with the hostname then you didn't change one of the mentioned items or are using a distro not covered in this article (this is for Ubuntu Hardy).

Sorry I can't be more help but it really is as simple as that. If you changed the files as noted then it works.

PickledOnion

Dhanil commented Tue Dec 09 08:16:15 UTC 2008:

Hello,

I am using Fedora Core 9. I want to setup postfix & as per articles i have tried to configured basic setup but it does not have file /etc/hostname so do i have to create one or I can use /etc/hosts file? I have setup /etc/hosts file as :

127.0.0.1 localhost localhost.localdomain 127.0.0.1 mail.mydomain.co.in

staticip mydomain.co.in.

When i type hostname -f it shows mydomain.co.in

Eric commented Tue Dec 09 18:53:39 UTC 2008:

The point a lot of comments here are getting at, and one which I share, is:

If I have one slice, my hostname is: toast.com

My reverse DNS is: mail.toast.com

Will this discrepancy cause any problems? I don't want to make the hostname for my one and only slice to be mail.toast.com, but I would like mail to work from it and not get blacklisted/rejected.

Thanks!

Eric commented Tue Dec 09 18:58:02 UTC 2008:

As a continuation of my previous comment, would the solution be to just set my reverse DNS as: Slice Name: toast.com Record: toast.com And just forget the 'mail.' prefix altogether?

Jamie commented Sat Dec 13 06:28:14 UTC 2008:

This setup guide appears to be for if you intend to setup a Slice that is purely used as a mail server. If you wish to use it as both a mail server and a web server, you'd be better to drop the mail prefix from most of the setup as doing so may cause problems with your web server setup.

The change in bash prompt occurs because you are changing the hostname of the machine... and so to try and be convenient (under the assumption your "group of servers" works within one domain), bash assumes the first part of your domain - in this case, mail. This works on the basis that you would have another web server slice named "web.blah.com" which bash would call "@web", or a fileserver called "files.blah.com" which bash would call "@files", etc, to aid in identification when using SSH or whatever.

You can easily set the RDNS and mail server to run from justyourdomain.com without causing any problems - there is no requirement to run from mail.justyourdomain.com except for the ease of identifying what the server is for.

Your MX records will identify where your mail server is, so using the mail. prefix is purely for convenience.

j.

Tibor commented Tue Jan 06 02:16:42 UTC 2009:

hostname -f or -a gave me "Unknown Host" too

For some reason the host name was not picked up from the /etc/hosts file.

I found one workaround: comment or remove the line setting the HOSTNAME in the /etc/sysconfig/network file. Something like this: NETWORKING=yes

HOSTNAME=MySlice

GATEWAY=173.45.236.1

Seems to me the above HOSTNAME comes from the slice web management interface. I am not sure what tool should be used to change this line officially but editing the file + reboot the slice resolved my problem!

Andrew B commented Sun Jan 11 05:21:38 UTC 2009:

How long does it take the RDNS to propagate? If it has not propagated yet, could that be a reason for a "Relay access denied" error when attempting to send email?

Abed commented Mon Jan 19 00:14:43 UTC 2009:

Re: dedekind (and others) (about the Bash prompt)

I'm essentially a complete noob to *nix. Changing the hostname to mail.domain... would change the bash prompt to "mail", which was quite irksome for me. PickledOnion mentioned ".bash_config" which I couldn't figure out but I did after some googling + talking to a friend.

If you followed along the series of Ubuntu articles (particularly the Ubuntu Hardy setup page 2: http://articles.slicehost.com/2008/4/25/ubuntu-hardy-setup-page-2 ) you may have already come across this, too. Edit the .bash_rc file in your home directory. If you followed the article change the export PS1 line where it says \h (the "mail" part of your hostname) to whatever you want (then do what you have to do so the changes are applied, which in the article above is "source ~/.bashrc"). Here's a page I referred to on more bash prompt / .bashrc info: http://www.ibm.com/developerworks/linux/library/l-tip-prompt/

Now I can have my bash prompt read as my slicename, keep the host as mail.domain.com to follow along the series of tutorials without any worries or irritations =)

Abed commented Mon Jan 19 00:16:35 UTC 2009:

whoops! In my comment above "Edit the .bash_rc file" should read "Edit the .bashrc file" (no underscore!).

Michael commented Wed Feb 18 01:18:05 UTC 2009:

Hi there,

There's been a few comments about the necessity to name your slice mail.example.com. I can see where these people are coming from. They don't want their slice to have an email centric name because they they might want to use it for lots of other things.

I've set mine up in the following way: I've given it a FQDN of slice.example.com and added a and reverse dns for slice.example.com. I can then (if I want) add an MX for slice.example.com and mail will arrive at my slice and spam people will be happy that everything is kosha.

Does this make sense to people? Is it a good way to proceed? Any drawbacks?

Matt Enright commented Thu Feb 26 14:17:14 UTC 2009:

Hey guys, If you're getting the hostname not found error when requesting the FQDN (i.e. using hostname -f), you need to return to /etc/hosts, and give it two columns - the FQDN first, and the local hostname second.

127.0.0.1 mail mail.demoslice.com

Patrick Sanchez commented Mon Mar 23 09:43:55 UTC 2009:

I tried "mail myemail" and it hangs after I input the subject.

Gswain commented Thu May 21 17:58:29 UTC 2009:

For Centos (and probably fedora) you can change your hostname permanently by editing /etc/sysconfig/network

Hope that helps someone

Mark McLean commented Thu Jul 02 21:17:25 UTC 2009:

For Jaunty Matt Enright is correct except his example is wrong whereas his text is correct.

Should be: 127.0.0.1 mail.demoslice.com mail

datakid commented Fri Sep 25 23:07:30 UTC 2009:

These are great, easy to follow tutes PO. But fwiw, I think the comments on this one are indicative of a trend and important to note. There needs to be another tutorial here for those that only have one server. There are a number of other steps that need to be taken if you decide to use:

hostname = berlin hostname -f = berlin.server.com mail = mail.server.com web = server.com, subdomain.server.com

all on the same slice. I'm struggling with it now, and it's not obvious which way to go. Should I be adding:

mail.server.com
subdomain.server.com

to the bottom of /etc/hosts for instance? ie:

127.0.0.1     localhost localhost.localdomain
127.0.0.1 berlin.server.com 
# entries for subdomains 
98.111.239.111 redmine.server.com
98.111.239.111 mail.server.com
98.111.239.111 subdomain.server.com

Jason commented Fri Oct 09 02:28:28 UTC 2009:

I'm trying to setup email on my slice as outlined and after reboot I'm getting ~: hostname -f hostname: Unknown host. I'm running Ubuntu 9.04 (jaunty) and have added the domain name to my zone.

Thanks for any help,

Jason

iChaitanya commented Wed Nov 04 16:30:17 UTC 2009:

Ubuntu 9.10: If you're getting a "hostname: Unknown host" reply after issuing the command 'hostname -f', change the hostname of your slice to a FQDN from the SliceManager. After a reboot if you issue the command 'hostname -f', it'll display the same FQDN that you entered in SliceManager. Hope this helps someone!

Brian commented Mon Nov 09 00:05:17 UTC 2009:

If I follow you setup and set records for mail.domain.com, should I be sending emails from user@mail.domain.com or can I still send them from user@domain.com? Does it not matter?

Gabriel commented Sat Jan 09 08:25:00 UTC 2010:

Debian Lenny + Exim4 I configured my RDNS, hostname, hosts, according to these instructions.

And every recipient mail servers look at the incoming email address and try to verify the domain, or mx (I'm assuming.. )

I get things like this:

2006-08-28 11:08:57 1GH7KP-0001Gq-Py == themail@domain.com R=dnslookup T=remote_smtp defer (-44): SMTP error from remote mail server after RCPT TO:themail@domain.com: host 1.2.3.4[1.2.3.4]: 450 ne@mydomain.com: Sender address rejected: Domain not found

Any help would be greatly appreciated.

Thanks.

nicolas block commented Sat Jan 16 00:45:13 UTC 2010:

the protocol for changing my hostname didn't work for me on Ubuntu Hardy.

here's what did work:

first back up just in case i'm wrong sudo cp /etc/hosts /etc/hosts.bak sudo cp /etc/hostname /etc/hostname.bak

next:

sudo nano /etc/hosts

make it look like this:

127.0.0.1 localhost 127.0.1.1 your.hostname.net

where your.hostname.net is your actual hostname

next:

sudo nano /etc/hostname

make it look like this:

your.hostname.net

where your.hostname.net is your actual hostname

finally,

sudo reboot

nicolas block commented Sat Jan 16 00:50:46 UTC 2010:

*ok, that formatted horibly, let me try again, maybe i can make this markdown thingy work...

the protocol for changing my hostname didn't work for me on Ubuntu Hardy.

here's what did work:

first back up just in case i'm wrong

sudo cp /etc/hosts /etc/hosts.bak 
sudo cp /etc/hostname /etc/hostname.bak

next:

sudo nano /etc/hosts

make it look like this:

127.0.0.1    localhost 
127.0.1.1    your.hostname.net

where your.hostname.net is your actual hostname

next:

sudo nano /etc/hostname

make it look like this:

your.hostname.net

where your.hostname.net is your actual hostname

finally,

sudo reboot

Ben Maden commented Sat Mar 20 03:32:51 UTC 2010:

All works for Fedora too.

thanks, very handy :)

J.Ganesan commented Sun May 02 00:59:33 UTC 2010:

I have signed up for one slice and my requirements are

  1. I run my web sites a. www.searchterrain.com b. www.linebalance.com
  2. I need to have email ids a. jg@searchterrain.com b. jg@linebalance.com

At present when I do hostname -f I get searchterrain.com

I do not want to have anything like mail.searchterrain.com. My question is wherever the article mentions "mail.searchterrain.com", if I substitute "searchterrain.com", will postfix work or not ?

Jered commented Tue May 04 15:39:46 UTC 2010:

You can use "searchterrain.com" instead of "mail.searchterrain.com", just make sure that the reverse DNS for your slice points back to "searchterrain.com" when you use it for the mail host address too.

John commented Sun May 16 21:56:10 UTC 2010:

Hi guys was just wondering what you think is the best server currently for email hosting?

Frank Malina commented Sat Nov 27 16:36:58 UTC 2010:

I was getting bounced mails "Undelivered Mail Returned to Sender" with errors such as: host ... refused to talk to me ... Helo command rejected: need fully-qualified hostname.

This fixed it.

Additionally I went to www.spamhaus.org and got my IP removed from PBL list as it originated from a dynamically assigned IP range, all good.

Fred Cord commented Tue Aug 30 01:38:17 UTC 2011:

These articles are of great help!!!!!!!!!!!!!!!!! It works for me perfectly.

architectural wall deca commented Fri May 03 19:08:25 UTC 2013:

I went over this website once i think a few a lot of wonderful info, saved to bookmarks (:.

architectural wall deca commented Fri May 03 19:08:31 UTC 2013:

I went over this website once i think a few a lot of wonderful info, saved to bookmarks (:.

a house commented Wed Jun 12 07:41:32 UTC 2013:

We have joined your feed and show toward seeking greater amounts of your magnificent post. Also, I've shared your site within my myspace!

a house commented Wed Jun 12 07:44:09 UTC 2013:

We have joined your feed and show toward seeking greater amounts of your magnificent post. Also, I've shared your site within my myspace!

yahoo commented Fri Jul 18 04:56:57 UTC 2014:

It's very straightforward to find out any matter on net as compared to textbooks, as I found this piece of writing at this site.

My blog - yahoo

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)