Install and Configure a Postfix Mail Server


There are a number of reasons why you would want to set up your own Linux mail server. You are in a company that has needs for a more reliable mail solution than anything the competition has to offer. Your company has a very limited IT budget and can't afford Exchange or the CALs involved. Or, maybe you just want to expand your repertoire of Linux skills. Regardless of why, knowing how to set up a mail server on a Linux machine is an important task any Linux admin should know. And of course, in the spirit of all things Linux, there are a number of ways you can go in order to get that mail server up and running. Over the years I have found Postfix to be one of the easiest to set up and most reliable to deploy in most organizations.

I have deployed Postfix servers in single-user environments and up to three hundred user environments. It works like a champ no matter the size. And in this article I am going to show you how to get that Postfix server up and running in no time flat.

NOTE: For the purposes of this article I will be installing Postfix on an Ubuntu Server (the release is 10.04 but can be applied to 9.10) and I will use the fake domain You will, of course, need to substitute your own domain (which must be a FQDN). 


You will be shocked at how simple it is to install the Postfix mail server. All you have to do is follow these steps:

1) Open up a terminal window (or, if you are using a GUI-less server just log in).

2) Issue the command sudo apt-get install postfix.

That's it! Of course, depending upon the current state of your distribution, the installation may or may not have to install some dependencies. But this will happen automatically for you. The installation will also automatically start the Postfix daemon for you. So as soon as installation is complete you can test to make sure you can connect to your Postfix server with the command:

telnet localhost 25

You should see something like this:

Connected to
Escape character is '^]'.
220 localhost.localdomain ESMTP Postfix (Ubuntu)

Now you might want to first make sure you can also connect to your domain in the same way with the command:

telnet 25

Of course you will use your own FDQN in the above command (instead of Hopefully you will see the same output you did when you used localhost. If not, you will have to check to make sure your domain is pointing to your server or that port 25 traffic can get to your server from your router, switch, or firewall. Those issues are beyond the scope of this article however.

Now it is time to start configuration.

Configuring Postfix

The Postfix mail server has one main configuration file /etc/postfix/ This is where you will do the bulk of your configurations. Open this file up in your favorite text editor (mine is Nano) and look for the following section:

myhostname =
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination =
relayhost =
mynetworks =
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

This is the section of the configuration file you must focus on. And, believe it or not, there isn't much to do. Below are the sections you need to configure:

myhostname: This is the hostname of your machine. But don't put the full hostname. If your machine hostname is you will only use mydomain.

mydestination: This parameter specifies what destinations this machine will deliver locally. The default is:

mydestination = $myhostname localhost.$mydomain localhost

You could also use something like what I have used in the past (for simplicity's sake): mydomain localhost.localdomain localhost

This call is up to you. Either way will work; but the latter line will help to avoid mailloops.

mynetworks: This line is a bit trickier. This entry will define authorized destinations that mail can be relayed from. You would think that adding your subnet here would work. Sometimes that is the case; sometimes not. You could go with a mynetworks entry that looks like:

mynetworks =

The above entry is a safe entry and defines local machines only.

You could also have an entry that looks like:

mynetworks =

The above entry would authorize local machines and your internal network addresses.

I have found, however, that the above entries will cause problems with relaying due to constantly changing dhcp addresses. Because of this I have used the following, specialized entry which will avoid this issue:

mynetworks = [::ffff:]/104 [::1]/128

Now, if your mail server serves up mail to your entire domain, you will need to add another entry to that section above. That entry is:

mydomain =

Again, as in all configurations above, the will be substituted with your real domain.

Now, save that configuration file and restart your mail server with the command:

sudo /etc/init.d/postfix reload

Your mail server should be up and running.


Since this is a Linux mail server, you will need to make sure you have a user name that corresponds with every email address you need. If your server has a GUI you can just use the GUI tool for this. If your server is a GUI-less server you can create users with the command:

sudo useradd -m USERNAME

Where USERNAME is the actual name of the user. The next step is to give the username a password with the command:

sudo passwd USERNAME

Again, where USERNAME is the actual username. You will be prompted to enter the new password twice.

Test Your Server

Go to an external source and send an email to one of your users on your new mail server. To find out if it worked you can log on as that user and use the Alpine command line email reader (you might have to install that first with the command sudo apt-get install alpine). If you do not see an email show up you will want to check the log file /var/log/mail.err which should give you some clues as to what is going wrong.

Final Thoughts

Setting up a mail server has never been easier. Not only is Postfix a simple to set up server, it's also simple to administer, as well as simple to troubleshoot. I hope you have as easy a time as I have had setting up and administering Postfix. Next time around, we'll add a few features to this Postfix server.



Subscribe to Comments Feed
  • Jason Said:

    You think that is simple? I haven't got a clue what you are on about. You need to explain stuff like mydestination = $myhostname localhost.$mydomain localhost. That is the 'default'. I don't know what it means. There is three paramaters $myhostname - what is that? The last one is localhost, well if it isn't delivering mail to localhost (i.e. me), where the hell is it delivering to? Why is there three and why four in your next setting? Unhelpful guide.

  • David Said:

    @Jason $myhostname = The name of your server, you choose this when installing your server (Same thing as computer name on a windows machine) $mydomain = If your email server was serving email to your domain would be the '' part. Normally when we seperate internal (company domains) and external (web domains) by using .local,. We would use 'ilovesausages.local' This might be completely wrong :)

  • xentoth Said:

    i would appreciate it if the host of this would hit me up with an email at xentoth @ gmail. com

  • Nizzy Said:

    DOES WORK IN UBUNTU: # sudo /etc/init.d/postfix reload * Reloading Postfix configuration... postfix/postfix-script: fatal: the Postfix mail system is not running THIS WORKS: # /etc/init.d/postfix restart * Stopping Postfix Mail Transport Agent postfix [ OK ] * Starting Postfix Mail Transport Agent postfix

  • Nizzy Said:

    correction -> DOES NOT WORK IN UBUNTU:

  • Gorth D Said:

    someone looking for help on postfix in the internet is probably not a whiz at postfix, which (albeit 20 year's of C++) I find to be bear. I've spent days trying to get the mail server to accept mail from my Windows client. I can't get past the mail server refusing my telnet [host] 25 (which the author fails to address). Totally unhelpful article by yet another person unable to communicate.

  • Johnnyvile Said:

    This was a pretty good article and it makes sense. I mean he didn't give every detail for every little part but he did post a short, concise, and easy to follow article. It is easy to do some research outside of the article to figure out things you are having trouble with. There is no need to get insulting to a guy giving you free advice.

  • Bob Said:

    Yes, because authors are obligated to help you fix a problem you can't even describe other than "it don't work" 3 years after writing the article. Schmuck.

  • Virneto Said:

    This is awesome info for me!!! I'll sure try it right away!!!! Thanks for sharing!!! Best Regards!

  • paul Said:

    Good tutorial. I also wrote my own tutorial on configuring Ubuntu 12.04 with postfix and dovecot. Check it out

  • brijesh trivedi Said:

    hey!!! i want to create my own mail server using cpanel but issue is that when i create a new account my current mail address data will be lose from gmail accout so help me to how to solve this issues.

  • linux newbie Said:

    i setup postfix, i am able to receive and send within the same domain. I am having problem sending to external domain email such as gmail and etc. in the maillog, it stated, 'relay rejected"...

  • Ed Said:

    Hi, Thank you for your nice page, very useful! Recently I setup a homemade e-mail server and wrote a full detailed tutorial that you can find in using Debian Squeeze, Postfix, Dovecot, SASL, Spamassassin and Squirrel (and a Google account for SMTP relay). I wish it is helpful to someone.

  • jeremiah Said:

    hi i what i have to put in the domain fields if i dont have a domain? i got a host,my

  • jaypee Said:

    how to configure postfix into mail server?

  • Juioh H Said:

    I was wondering, exactly at which point are you supposed to release the lion? and at which point do I remove my gimp suit? Kind Regards J.H.

  • Muhammad Shafiq Alibhai Said:

    This is to respond to linux newbie : You need to configure SMTP relay server (e.g. smarthost) this will relay your message to external (As you mentioned earlier, internal emails are already working.

  • SamuelNZ Said:

    Also, Don't forget to run sudo apt-get update ; sudo apt-get upgrade ; Every time you download/install a new package.

  • Michael Said:

    For step by step info see below

  • Salahuddin Said:

    Sir I have register domain and with incoming mail facility also and it was registered from US. Now for my Lan need a SMTP server only. I have configured Postfix in my debian7 server. But now i can send mail outside from my Lan only like in gmail etc.. When i am sending any mail to my Lan its going to Mail Queue with below error : host ******.net [*.*.254.17] refused to talk to me: 554 dropsmtpd - Your mail is being dropped as spam. plz help..

  • Vannary Said:

    I want to know about installation and configuration Mail server in Linux

  • Muhammad Shafiq Alibhai : Said:

    Hello Vannary, There is very good side called Linux Home Networking (LHN) ... check chapter 21 or click at the link below: Hope it is useful.

  • Marius Said:

    That tutorial was helpfull for installing postfix. And you are right, it wan's that hart. On my mailserver i can receave mails now. But i dont think that im able wo send mails out of ths server to an external mail-server. What I need now is an IMAP or POP3 server. maybe you could write a tutorial about how to do that? That would be nice. Thanks, Marius

  • myOpenSourceStore Said:

    Hello experts. would you be interested in offering remote services on PostFix to our customer. Please let me know using

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board