English (change)
In this tutorial we’ll configure an email function for the VPS. That’s not to turn this Linux system into a mail server .. but to allow our web apps to be able to send and automate outgoing email.
If you recall the introductory post to this series – Set Up an Unmanaged VPS (4 Newbies) .. The V-P-S Bible – I said the aim was to set up the fastest possible web server, while retaining options to strap on other functionality later on. For most of us, the most likely addition would be a mail server. But.
[sniplet guvSellBox]
[sniplet vpsIndexSell]
But. A mail server takes up valuable resources. SMTP, for example, eats RAM. Which slows down your sites. OK, we could set up POP3 and retain greater efficiency. Then again, we could just use Google Apps, and focus this box 100% towards our web server solution.
…and that’s my plan, for now; retaining the option to add a mail server later on, yet allowing our web apps a mail handling capacity. So we need Postfix for that, and some configuration.
[sniplet video]
To see your hostname, at the CLI, type:-
[text]hostname -f[/text]
…and hit return. The name displayed is probably not what you’re after. Let’s change it.
I’ve got a domain hanging about, gathering dust, so I’ll use that as an ongoing example. It’s waywiderweb.com. For the mail function, it would be mail.waywiderweb.com, and so that is what I will call my hostname. You do likewise, substituting waywiderweb for your domain name.
We’ll change the hostname in 2 files, and then change the Reverse DNS to match. Let’s open:-
[text]sudo nano /etc/hostname[/text]
…replacing the hostname (for me it’s ubuntu) with the new one mail.waywiderweb.com.
And do the same with:-
[text]sudo nano /etc/hosts[/text]
…replacing the single instance of the existing hostname with mail.waywiderweb.com.
It’ll look something like this…
…If it doesn’t contain those last 7 lines, don’t worry about it.
Now for the reverse DNS. For this, using your web browser, head to your VPS manager.
With Linode, for example, goto the site and click on the Members tab, log in, then click on your Linode, then on Network, to find a link to Reverse DNS.
For Slicehost, after logging into the Slicemanager, you click the DNS tab, then the Reverse DNS link. Other unmanaged VPS providers will have similar control panels.
Clicking on the Reverse DNS link, fill the field with the desired hostname. So I type in mail.waywiderweb.com, click OK and confirm, and can see the RDNS is now set to mail.waywiderweb.com.
Perform a quick reboot:-
[text]sudo reboot[/text]
Logged back in, now type:-
[text]hostname -f[/text]
That’s better, huh?
To check the RDNS, do this:-
[text]sudo aptitude -y install dnsutils[/text]
Then, replacing mine with your IP address:-
[text]dig -x 97.107.129.135[/text]
Provided the output contains the following, but with your IP, we’re fine:-
…if it doesn’t, make some tea and try again. The RDNS may take a little time to propogate.
Type:-
[text]sudo aptitude -y install postfix telnet mailx[/text]
Prompted, choose Internet Site, as shown in the image at the top of this post.
Then enter your hostname:-
Now we’ll redirect mail from root to our username, in my case guvnr:-
[text]sudo nano /etc/aliases[/text]
…and where you see this line…
[text]root: some_value[/text]
…change “some_value” to your username, like this in my case…
[text]root: guvnr[/text]
Reload the aliases database:-
[text]sudo newaliases[/text]
Edit the Postfix configuration:-
[text]sudo nano /etc/postfix/main.cf[/text]
…and replace 3 lines, substituting waywiderweb for your domain:-
[text]
- Old: myorigin = /etc/mailname
- New: myorigin = $mydomain
- Old: mydestination = mail.waywiderweb.com, localhost.waywiderweb.com, , localhost
- New: mydestination = $waywiderweb, localhost.$waywiderweb, localhost
- Old: mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
- New: mynetworks = 127.0.0.0/8
[/text]
Refresh Postfix:-
[text]sudo /etc/init.d/postfix restart[/text]
Test it by sending yourself an email, with your email address:-
[text]
php -a
mail (‘your@email.com’, “Test from my VPS”, “Hey, don’t forget to fix an RSS or email feed from guvnr.com!”);
exit ();
[/text]
Go to your email client, or gmail or whatever, and check for that.
OK, that’s outgoing email sorted for your server, so you’ll be able to send email from your web applications. For incoming email, we’ll be setting up Google Apps later in this series, which is free, easy, saves time and your system resources, and can be popped or smtp’ed to your local email client, using your own domain name. Very splendid.
In the next tutorial Part 11: Nginx (better than Apache) Web Server on Your VPS, we’re getting pretty hot under the collar as we install one of the core modules in our super-sexy virtual private server, Nginx. And from there, we’re pretty much walking downhill all the rest of the way.
Meantime, here’s the index…
[sniplet vpsIndex]
Josh Sanders May 26th, 2009 at 8:38 am
Hello
Do you know how I can turn VPS into a mail server wit Postfix and webmin?
I am a Newbie
the_guv May 26th, 2009 at 11:24 am
@Josh,
I do know how, but boy it’s a lot of work to set out.
I may write a tutorial on turning a VPS into a mail server, but the current series concentrates on the fastest, most secure web server, and a mail server spoils that, and is generally unnecessary with Google Apps…have you considered GA?
…maybe in a couple of months, that guide. A few more enquiries like yours and it’s more likely.
Meantime, the almighty Google is my suggestion.
dan May 29th, 2009 at 1:00 am
Awesome information you have here. Thanks for sharing
Dale Lukas Peterson July 6th, 2009 at 3:58 am
Guv, your tutorials are awesome, I can follow them almost to the letter and everything works, except for one step in this tutorial, which didn’t work on my VPS host (fivebeans.com). The step that didn’t work was the mail command from within the interactive php, I got this error:
postdrop: warning: unable to look up public/pickup: No such file or directory
Here is what I did to fix it:
sudo mkfifo /var/spool/postfix/public/pickup
sudo /etc/init.d/postfix restart
Additionally, by default it seems that Ubuntu 8.04 has sendmail installed and up and running, so I had to find that process and kill it, and for good measure I also did an aptitude purge on all the sendmail packages.
This thread details what is needed to get this all straightened out:
http://ubuntuforums.org/showthread.php?t=666018
the_guv July 7th, 2009 at 12:03 am
@Dan .. tx to you.
@Dale. Appreciate that.
Sure, Linux distributions may vary a bit between VPS providers.
Ryan in Austin July 30th, 2009 at 1:15 am
Excellent tutorials!
Would I be correct in saying that changing my hostname to mail.xxx.com and reverse DNS literally changes my machine to that name?
I’m confused because many resources say to use the fqdn, but then if you have several virtual servers running, then your hostname should be localhost or something random … I don’t know, maybe the guvnr could clarify for us noobs?
Thanks for the great information!
the_guv August 2nd, 2009 at 2:26 pm
@Ryan .. thank you. Here’s some basics ..
A hostname is a machine’s name, so it can be identified on a network like, say, the web. It can be changed.
For the computer to talk to itself (to loopback) it uses another, standard hostname called localhost, with the IP address 127.0.0.1
Reverse DNS translates an IP address into a hostname. In this case, it will help outgoing email being considered legit and not spam.
A FQDN is a complete DNS name. Say, you’ve got the domain somesite.com, and strapped on the sub-domain blog, then the FQDN to your blog would be blog.somesite.com. (including that last dot, tho it’s often left out).
.. Equally, mail.somesite.com is a FQDN, but may just happen to be your machine’s hostname as well.
What are you actually wanting to achieve? Lemme know and I’ll try to really confuse the issue
trav 19 August 3rd, 2009 at 4:54 am
hello guv! my vps hosts file has the hostname pointed to localhost like so:
127.0.0.1 ubuntu localhost localhost.localdomain
all in one line. should i point “ubuntu” to a different ip like the one in your example (which was 127.0.1.1)?
the_guv August 3rd, 2009 at 12:53 pm
@Trav 19 .. aye, change to that for your hostname.
*Unless you’ve got a permanent IP address*, in which case use that instead of 127.0.1.1.
angel gomez August 26th, 2009 at 1:16 am
Hello guv!
Thanks for your time doind these tutorials. I am just starting with all this stuff. I am pretty newbie.
So far, I have followed all your instructions. I have one question:
When I enter the commands:
php -a
mail (‘your@email.com’, “Test from my VPS”, “Hey, don’t forget to fix an RSS or email feed from guvnr.com!”);
exit ();
and then I checked in may mail box, I received the email from:
myuser@mail.mysite.com
I was expecting receiving from:
myuser@mysite.com
Is something wrong with my configuration?
Sorry, if this question is very newbie.
Thanks a lot again!!!
the_guv August 26th, 2009 at 12:23 pm
hey Angel, tx for your comments.
That’s fine. This is just a generic test to show that the mail function works. As long as you got the mail, you know that, say, when someone sends a mail through one of your sites, you’ll get those too.
You could build a mail server proper on the VPS too but, for most sites, Google Apps is better as it won’t drain your resources. So what we have here is the bare bones so you never miss email sent thru your sites. (When you reply to those, you’ll be doing so via GA, if you follow the Bible’s method.)
angel gomez August 26th, 2009 at 5:23 pm
Thanks guv for your answer.
I am planning to have two or more web pages on my IP using virtual hosts: mysite.com and mysite2.com (or mysite.org).
Can I generate separate: mail.mysite.com, mail.mysite2.com (or mail.mysite.org) following these instructions or do I need to do something especial?
I really appreciate your time writing these tutorials and answering our questions.
Patrick August 26th, 2009 at 6:02 pm
After
sudo nano /etc/hosts
I got this
127.0.0.1 localhost localhost
194.145…….. vps104.vps.nl vps104
Can i change the IP to mail.blognetwerk.net ?
Thanks i am very happy with your site.
angel gomez August 26th, 2009 at 6:39 pm
Thanks guv.
Also, I would like to have two sites:
mysite.com and mysite2.com (or mysite.org)
Can I have two separate: mail.mysite.com and mail.mysite2.com (or mail.mysite.org) following these instructions or do I need to do in a different way?
I realle appreciate your help and time writing the tutorials and answering our questions.
the_guv August 27th, 2009 at 11:48 am
@Patrick .. dude, that’s all covered in the guide, word-for-word! follow it and you will have a rock solid solution .. at least by the time i finish writing the VPS Admin section
but basically, yes.
Ashesh August 27th, 2009 at 2:15 pm
Guv, thanks again for such exhaustive tutorial.
I have got a problem. After clicking Reverse DNS link on the next page it askes for “hostname Lookup” search box and following text is shown:
“The hostname you enter must have a valid A/CNAME record pointing to the IP you want to set the reverse DNS for. The A/CNAME record must be propagated and working before we will be able to find it. You may also enter the IP address if you don’t want an RDNS entry for that IP.”
When enter the domain name I have entered so far, it says No match was found for “xxxxxxxxxx”. Reverse DNS must have a matching forward entry for one of your IPs.
I have followed your tutorial word by word.
Ashesh August 27th, 2009 at 4:38 pm
Hi Guv,
It is possible that because the mail.domainname.com I am using is already in use and pointing to another server?
Anyways I am skipping this part for now and will work on it again once I have change the DNS of domain to linode NS
thanks
Ashesh August 27th, 2009 at 8:44 pm
Hi Guv,
It worked. I changed the DNS at registrar to point to linode NS
Thanks
the_guv August 28th, 2009 at 1:39 pm
@Ashesh .. 3 possibilities there. Either you’ve not properly set up your hostname, as explained here, else your Domain Zone, but also it can take a little time (some hours sometimes, maybe a day or so with some VPS providers, I guess) for those records to propagate before you can input a reverse DNS record.
Allow a little time for the RDNS propagation, folks.
felipe August 29th, 2009 at 3:07 am
Hi guv,
Thanks a lot for your tutorials.
I am creating two websites:
mywebsite.com and mywebsite2.com (or mywebsite.org).
How can I have two separate:
mail.mywebsite.com and mail.mywebsite2.com (or mail.mywebsite.org)?
Can I do that following the instructions here or do I need to do something different?
the_guv August 29th, 2009 at 2:13 pm
@Felipe and @Angel,
Tx for cmts .. Very good question. (Apologies for delay answering.)
You need (and only can, per server) set only the one RDNS/hostname. Essentially, along with the instructions in this post, this will give your VPS the capability of email. Then, when you set up however many websites, whether using a mail server or Google Apps, your various domains’ email will resolve via their individual address, such as whatever@thissite.com or somethingelse@thatsite.net.
This is standard stuff. So, the RDNS/hostname is simply a reference point, but is not necessarily the name used for individual domain emails. Indeed, using exactly this Bible, Google Apps and this Postfix solution, I’ve got a dozen websites/blogs running, all with catch-all email accounts using their specific domain names. Nice and tidy, totally professional.
Probably I should make this clear at the top of the tut. Bet there’s been a lot of folks with a similar concern. Think I had that worry myself with my first web server setup.
felipe August 29th, 2009 at 2:49 pm
Thanks a lot !!!! I really apreciate your effort and time helping us.
Patrick August 31st, 2009 at 8:45 pm
The Guv
Yessss it works after I try it again and again
the_guv September 1st, 2009 at 5:54 pm
@Patrick .. jolly fine. Fiddly init! Good to hear.
agus September 2nd, 2009 at 7:51 pm
Hello Guvs,
I just changed the host to mail.mydomain.com but im stuck on the reverse ip part. I am having the same problem as comment #16.
My domain name dns is currently hosted at zoneedit. Maybe you can help directing how I can use Linode along with Zoneedit.
I am running a pretty busy site (at least thats how I see it, around 7000 to 8000 visitors a day), and I really cant afford the down time.
Thank you, and you are a God sent as someone have previously mentioned somewhere on your site…
agus September 4th, 2009 at 6:19 pm
Hi Guv,
It’s me again, I have successfully created some virtual hosts per your tutorial… they worked flawlessly… expect for my main site that is hosted with zoneedit….
Anyway my main site is a drupal site, and I was wondering if you could teach me backup and migrate my drupal site.
I have checked everywhere about this and found it to be quite daunting, and they dont have your kind of tutorial, which if followed, guaranteed to work like a charm.
Thanks!
Agus September 9th, 2009 at 7:56 am
Hi Guv,
Everything is good now… thanks! btw when we installed xcache, that goes for all the other site too right?
I found even Xcache is not enough if Mysql is not optimized. I optimized mysql setting and everything seems to fly now… I am so happy…
What about writing tutorial on how to optimize Mysql? Everyone will surely appreciate this…
Thanks Guv! Gbu…
Agus
Dave September 12th, 2009 at 3:28 am
I cannot get Linode to recognize the Reverse DNS (I have tried 3 times from the beginning! Deleting everything and starting square 1) and I still cannot manage to get it
.
It says:
“Lookup Results
No match was found for “mail.[myweburl].com”. Reverse DNS must have a matching forward entry for one of your IPs.”
Of course [myweburl] is the actual url. This is after I search for the reverse DNS in Linode. I skipped the step on my first time around and I was able to send emails no problem and everything else worked with no red flags, but I am sure there is a reason for this, so any help would be greatly appreciated!
Thanks,
Dave
OZKAN September 13th, 2009 at 1:19 am
is ther any french speeking and experimented VPS people in this communuty able to help me to solve mail server setting ?
the_guv September 16th, 2009 at 8:25 pm
@Agus .. you can find full backup instructions, both for files and db, whether to Windoze or Linux, in the VPS Admin section.
Optimizin’ MySQL, that is a good idea. Ha, on the list, along with the rest!
Sorry for delay .. holiday’ed out.
@Dave .. sounds like a classic case of the RDNS taking a while to propagate. Time it takes varies from host to host.
Lemme know if it’s not sorted now.
@Ozkan .. good luck to you. Anyone?
Yendis September 20th, 2009 at 1:59 pm
Hi Guv, when I do dig -x XX.XXX.XXX.XX, I get the right IP in the answer section but where in your example it displays your domain name, I get something else. Is this significant?
;; ANSWER SECTION:
XX.XXX.XXX.XX.in-addr.arpa. 86400 IN PTR li97-190.members.linode.com.
the_guv September 23rd, 2009 at 10:16 am
@Yendis .. LOL! Yes, that’s significant. Basically, it’s wrong .. so retrace your steps, you’ve missed something out, very likely in the hostname steps.
Pep Talk - GUVNR November 30th, 2009 at 9:04 pm
[...] a recap, take a peek:- Set Up Unmanaged VPS (4 Newbies) – Part 10: Prepare Linux Server for Email with PostfixPart 10: How to install an email function for the Linux server, installing Postfix, changing the [...]
Alborz December 1st, 2009 at 7:14 pm
After I modified both hostname and hosts files to my own domain names, by ‘hostname -f’ I got: ‘Unknown’ error. I had a chat with olly and it turned out after modifying the host name, you gotta reboot for it to take effect.
the_guv December 1st, 2009 at 7:28 pm
cheers Alborz ..
yes, and bear in mind it can take a little while for the hostname change to propagate. how long varies from webhost to webhost
kevinayP December 16th, 2009 at 2:12 am
Hi Guv,
First of all, thank you so much for the extensive tutorial, really appreciated everything you did.
Before reading this tutorial from scratch, I already did set up a Google Apps account and connected it with my domain, verified it, changed the MX records, and get everything (including mail) working. That’s actually the first thing I would do once I get a domain name.
Now that all of my mail is managed from Google Apps, should I still install Postfix and if I do, can I change the hostname from “mail.xxxx.com” into just “xxxx.com”? Will that affect something?
Thanks,
Kevin
Philip Churchill January 1st, 2010 at 12:50 am
I have the same question as Kevin above as Google apps is already setup.
the_guv January 9th, 2010 at 5:13 pm
@Kevin & Philip .. APOLOGIES for delay .. this is probably too late for you, Kevin, now but for community benefit, at least ..
yes, still install Postfix. (I wouldn’t have added it in the guide if it wasn’t necessary, at least to future-proof your VPS’ sites and blogs!)
re hostname .. why change the regular format? .. makes no visible difference (the only thing looking is a database). mail.xxxx.com vs xxxx.com .. I can’t pretend to know the ins and outs of the syntax but you will need the former.
Chad January 11th, 2010 at 8:07 pm
Hi,
I don’t know why but I can’t get it to send mail to any address
I keep going back through this removing postfix telnet mailx (seperately)… rDNS is propagated – but nothing.
chad January 12th, 2010 at 6:49 am
Hi,
Went back through the entire previous steps… and seems I may be having some dependency issues in PHP. Still nothing sending – but any idea how to launch Postfix, as it deosn’t launch after you installed, even after removing then re installing.
the_guv January 15th, 2010 at 11:50 am
@Chad .. may have been a nitch with PHP .. try update/upgrade and try again (PHP should upgrade, cos they’ve just brought out a new version .. dunno, but maybe there was a fix) .. worth a try .. what Ubuntu version you using?
Tell you what .. next week I’m gonna be going over this entire guide again to see if there are any broken packages (that happens as wares are upgraded and need different dependencies, and this could be the root of your problem.)
Will post any disparities between this guide and it’s tidy up (if anything needs a tidy up .. something will, sods law)
…..
@ALL … I’d like to draw your attention to the fact that this guide is going to relocate to my new site vpsBible.com, launching end January.
The reason for the move is basically to try to monetize this beast I seem to have created so that, in turn, I can spend the time required to properly support and radically expand it.
At vpsBible, the bible will expand this year with stuff like:-
- CentOS (I can hear the cheers!)
- finishing current then expanding the VPS Admin series .. upgrade Nginx, backup all that
- benchmarking Nginx against Cherokee, Lighty, Apache etc
- alternative guides to Nginx
- email servers
- proxifying your VPS, elite proxy setup
- rewriting this guide for Lucid Lynx 10.04 (out April – it’s Long Term Support so the most important release since 8.04, which this guide uses)
- more video
- and just for Agus .. Drupal! Oh, and some stuff like MODx
This doesn’t mean Guvnr’s had its chips or anything like that, it’s just gonna concentrate on non-VPS stuff, so lots of Linux desktop, savvy surfing, some web dev, rants from my pants, stuff like that.
If you’ve got some benefit from this Bible, don’t be a stranger! Please check out …
Guvnr.com & vpsBible.com – Focussing on 2010
… which gives all the detail for the 2 sites, and even recalls this story about a belly dancer I met in Arabia.
And please, leave comments about this change, good or bad .. let me know what you think, and don’t pull any punches.