{"id":15832,"date":"2019-03-06T08:47:33","date_gmt":"2019-03-06T08:47:33","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=15832"},"modified":"2025-01-23T10:49:07","modified_gmt":"2025-01-23T10:49:07","slug":"how-to-install-ubuntu-mail-server","status":"publish","type":"post","link":"\/in\/tutorials\/how-to-install-ubuntu-mail-server","title":{"rendered":"How to Install and Set Up Ubuntu Mail Server"},"content":{"rendered":"<p>Having your own email server is a great idea for any medium-sized company. With this, all the traffic is controlled, and we can define the rules ourselves. This way, we can manage the service clearly and cleanly.<\/p><p>In this tutorial, we will show you how to install and set up an <a href=\"\/in\/tutorials\/what-is-ubuntu\">Ubuntu<\/a> mail server on a <a href=\"\/in\/tutorials\/what-is-vps-hosting\">virtual private server<\/a> running Ubuntu. There are numerous alternatives and ways to create an email server in Linux; however, we will focus on <a href=\"https:\/\/en.wikipedia.org\/wiki\/Postfix_(software)\" target=\"_blank\" rel=\"noopener\">Postfix<\/a>!<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1024\" height=\"283\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet-1024x283.png\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet-1536x425.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet-300x83.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet-150x41.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet-768x212.png 768w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/Linux-cheat-sheet.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-configuring-the-dns-server-for-an-ubuntu-mail-server\">Configuring the DNS Server for An Ubuntu Mail Server:<\/h2><p>Just follow this step by step guide, and you shouldn&rsquo;t have any problems setting up the configuration!<\/p><h3 class=\"wp-block-heading\" id=\"h-1-log-in-and-update-your-server\">1. Log In and Update Your Server<\/h3><p>Log into your server using SSH. If you&rsquo;re having trouble, check out our <a href=\"\/in\/tutorials\/how-to-use-putty-ssh\">PuTTY tutorial<\/a>! After logging in, you should update your machine using the following command:<\/p><pre class=\"wp-block-preformatted\">apt-get update<\/pre><h3 class=\"wp-block-heading\" id=\"h-2-install-bind\">2. Install Bind<\/h3><p>To configure a DNS server that will use Postfix we&rsquo;ll need an additional tool &ndash; Bind. Let&rsquo;s install it first:<\/p><pre class=\"wp-block-preformatted\">sudo apt install bind9<\/pre><h3 class=\"wp-block-heading\" id=\"h-3-configure-var-cache-db-test\">3. Configure \/var\/cache\/db.test<\/h3><p>At this point, we must take into account that the IP address of our Ubuntu machine is <strong>192.168.250.7<\/strong>, it is necessary to replace it with the IP address where we will perform the installation. For this example we&rsquo;ll use mail.test.com as a FQDNS.<\/p><p>So, now it is necessary to create a new zone for our example. To do this, create a new file with the zone information.<\/p><pre class=\"wp-block-preformatted\">sudo nano \/var\/cache\/bind\/db.test<\/pre><p>Then, add the following:<\/p><pre class=\"wp-block-preformatted\">$ORIGIN test.com.\n$TTL 1D\n@ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IN SOA &nbsp;&nbsp;&nbsp;&nbsp;ns1 root(\n                1 ;serial\n                1D ;refresh\n                2H ;retry\n                2W ;expire\n                5H ;minimum\n);\n@ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IN &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NS ns1\nns1 &nbsp;&nbsp;&nbsp;&nbsp;IN &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A 192.168.250.7\nmail &nbsp;&nbsp;&nbsp;IN &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A 192.168.250.7\n@ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IN &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MX 5 mail<\/pre><p>Remember, we must replace the IP address with that of your server, and change the domain to the one you wish to use. Press <strong>CTRL+O<\/strong> to save the changes and <strong>CTRL+X<\/strong> to close the nano editor.<\/p><h3 class=\"wp-block-heading\" id=\"h-4-add-new-zone-to-bind-configuration\">4. Add New Zone to Bind Configuration<\/h3><p>Before enabling the newly created zone it is necessary to check the configuration of the file.<\/p><pre class=\"wp-block-preformatted\">sudo named-checkzone test.com. \/var\/cache\/bind\/db.test<\/pre><p>Now we can add our new zone to the Bind zone configuration file. To do this, run the following command:<\/p><pre class=\"wp-block-preformatted\">sudo nano \/etc\/bind\/named.conf.default-zones<\/pre><p>And add the new zone:<\/p><pre class=\"wp-block-preformatted\">zone \"test.com.\" {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type master;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file \"db.test\";\n};<\/pre><p>Again, <strong>CTRL+O<\/strong> to save the changes and <strong>CTRL+X<\/strong> to close it.<\/p><h3 class=\"wp-block-heading\" id=\"h-5-configure-etc-bind-named-conf-options\">5. Configure \/etc\/bind\/named.conf.options<\/h3><p>Now, in the file <strong>\/etc\/bind\/named.conf.options<\/strong> it is necessary to uncomment the forwarders line and include the Google DNS &ndash; <strong>8.8.8.8<\/strong>. For that simply remove the&nbsp;<strong>\/\/<\/strong> symbols as shown in the screenshot below.<\/p><pre class=\"wp-block-preformatted\">sudo nano \/etc\/bind\/named.conf.options<img decoding=\"async\" class=\"aligncenter size-full wp-image-15833\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/editing-dns-zone.png\" alt=\"Editing DNS zone to set up an Ubuntu Mail Server\" width=\"842\" height=\"493\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/editing-dns-zone.png 842w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/editing-dns-zone-150x88.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/editing-dns-zone-300x176.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2019\/03\/editing-dns-zone-768x450.png 768w\" sizes=\"(max-width: 842px) 100vw, 842px\" \/><\/pre><h3 class=\"wp-block-heading\" id=\"h-6-restart-bind\">6. Restart Bind<\/h3><p>Now, we have to restart the bind9 service. You can do it with one of two commands:<\/p><pre class=\"wp-block-preformatted\">sudo systemctl reload bind9<\/pre><p>or<\/p><pre class=\"wp-block-preformatted\">sudo systemctl restart bind9<\/pre><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/in\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner-1024x300.png\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-how-to-install-and-setup-mail-server-on-ubuntu\">How to Install and Setup Mail Server on Ubuntu<\/h2><p>We&rsquo;re almost there, your Ubuntu email server is ready to come online. Here&rsquo;s what you should do:<\/p><h3 class=\"wp-block-heading\" id=\"h-1-install-postfix-email-server\">1. Install Postfix Email Server<\/h3><p>Now it is time to install Postfix. Postfix is an email server written in C. Its main feature is the speed of execution and open source nature. Install it with the following command:<\/p><pre class=\"wp-block-preformatted\">sudo apt install postfix<\/pre><p>During installation, we will be asked to configure the package. On the first screen, choose the option Internet Site.<\/p><p>Then, we have to enter the name of the server. In this case <strong>test.com<\/strong>.<\/p><p>Postfix is very flexible and allows extensive configuration, but for this tutorial we&rsquo;ll fix with the default configuration.<\/p><h3 class=\"wp-block-heading\" id=\"h-2-add-user\">2. Add User<\/h3><p>Then, we have to add our user to the group mail:<\/p><pre class=\"wp-block-preformatted\">sudo usermod -aG mail $(whoami)<\/pre><p>After that, we have to create the users and add them to the mail group so they can send and receive mail. I&rsquo;ll add Gabriel:<\/p><pre class=\"wp-block-preformatted\">sudo useradd -m -G mail -s \/bin\/bash\/ gabriel<\/pre><p>Then, we need to set a password to the newly created user:<\/p><pre class=\"wp-block-preformatted\">sudo passwd gabriel<\/pre><h2 class=\"wp-block-heading\" id=\"h-test-the-ubuntu-mail-server\">Test the Ubuntu Mail Server<\/h2><p>Now to prove what we just did. We will send and receive an email from the terminal. To do this, we will install the mailutils package:<\/p><pre class=\"wp-block-preformatted\">sudo apt install mailutils<\/pre><p>Next, we send an email to the other email account user named gabriel. Type in the subject and the message. After that, press <strong>CTRL+D<\/strong> to finish. To start writing an email enter the following command:<\/p><pre class=\"wp-block-preformatted\">mail gabriel@test.com<\/pre><p>Now we can log into another user and check the mail utility.<\/p><p>There, after running the <strong>mail<\/strong> command, we will see the email we just sent to the other test user. To access the email just write the number of the mail, in this case, <strong>1<\/strong>.<\/p><p>To test outbound emails from this user, just try another email address:<\/p><pre class=\"wp-block-preformatted\">mail angelo@test.com<\/pre><p>That&rsquo;s it! You&rsquo;re sending emails from your very own email server on Ubuntu. <\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>An email server is easy to set up but might be a bit complex to manage. In Linux, it is recommended to do it for its security and resource management.<\/p><p>On the other hand, in a bigger company, it can be very useful to have a fully configured and functional email server out of the box, like the one offered by <a href=\"\/in\/business-email\">Hostinger<\/a>. Alternatively, <a href=\"\/in\/tutorials\/how-to-host-your-own-email-server-on-a-vps-with-cyberpanel\">host your own email server<\/a> to get complete control over the service.<\/p><p>There are many ways to improve and maintain an email server. It is a process that takes time and is constantly evolving. So we recommend that you keep going deeper into the subject! Good luck and happy mailing!<\/p><p>\n\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Learn What Else Your Ubuntu Can Do<\/h4>\n                    <p><a href=\"\/in\/tutorials\/how-to-install-yarn\">How to Install Yarn on Ubuntu<\/a><br>\n<a href=\"\/in\/tutorials\/how-to-install-git-on-ubuntu\">How to Install Git on Ubuntu<\/a><br>\n<a href=\"\/in\/tutorials\/how-to-install-maven-on-ubuntu\">How to Install Maven in Ubuntu<\/a><br>\n<a href=\"\/in\/tutorials\/install-pip-in-ubuntu\/\">How to Install Python Pip on Ubuntu<\/a><br>\n<a href=\"\/in\/tutorials\/how-to-install-tomcat-on-ubuntu\/\">How to Install Tomcat on Ubuntu<\/a><br>\n<a href=\"\/in\/tutorials\/how-to-install-jenkins-on-ubuntu\/\">How to Install Jenkins on Ubuntu<\/a><br>\n<a href=\"\/in\/tutorials\/how-to-check-ubuntu-version\/\">How to Check Ubuntu Version<\/a><br>\n<a href=\"\/in\/tutorials\/install-java-ubuntu\">How to Install Java on Ubuntu<\/a><\/p>\n                <\/div>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Having your own email server is a great idea for any medium-sized company. With this, all the traffic is controlled, and we can define the rules ourselves. This way, we can manage the service clearly and cleanly. In this tutorial, we will show you how to install and set up an Ubuntu mail server on [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/in\/tutorials\/how-to-install-ubuntu-mail-server\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":110,"featured_media":24070,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"","rank_math_description":"","rank_math_focus_keyword":"","footnotes":""},"categories":[22641,22640],"tags":[],"class_list":["post-15832","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps-use-cases","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-install-ubuntu-mail-server","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/serveur-messagerie-ubuntu","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/como-instalar-servidor-correo-en-ubuntu","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/membuat-mail-server-di-ubuntu","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-install-ubuntu-mail-server","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-install-ubuntu-mail-server","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-install-ubuntu-mail-server","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-install-ubuntu-mail-server","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/como-instalar-servidor-correo-en-ubuntu","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/como-instalar-servidor-correo-en-ubuntu","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/como-instalar-servidor-correo-en-ubuntu","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-install-ubuntu-mail-server","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-install-ubuntu-mail-server","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-install-ubuntu-mail-server","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/15832","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/comments?post=15832"}],"version-history":[{"count":22,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/15832\/revisions"}],"predecessor-version":[{"id":101028,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/15832\/revisions\/101028"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/media\/24070"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/media?parent=15832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/categories?post=15832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/tags?post=15832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}