{"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":"2026-03-09T19:19:43","modified_gmt":"2026-03-09T19:19:43","slug":"how-to-install-ubuntu-mail-server","status":"publish","type":"post","link":"\/ng\/tutorials\/how-to-install-ubuntu-mail-server\/","title":{"rendered":"How to install and set up an Ubuntu mail server"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><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 use Postfix to install and set up a mail server on a virtual private server running Ubuntu.<\/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\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure>\n<\/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=\"\/ng\/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-example\">3. Configure \/var\/cache\/db.example<\/h3><p>At this point, we must take into account that the example IP address in this tutorial is <strong>123.123.123.123<\/strong> &ndash; you&rsquo;ll need to replace it with the IP address where we will perform the installation. For this example we&rsquo;ll use mail.example.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.example<\/pre><p>Then, add the following:<\/p><pre class=\"wp-block-preformatted\">$ORIGIN example.com.<br>$TTL 1D<br>@ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IN SOA &nbsp;&nbsp;&nbsp;&nbsp;ns1 root(<br>                1 ;serial<br>                1D ;refresh<br>                2H ;retry<br>                2W ;expire<br>                5H ;minimum<br>);<br>@ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IN &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NS ns1<br>ns1 &nbsp;&nbsp;&nbsp;&nbsp;IN &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A 123.123.123.123<br>mail &nbsp;&nbsp;&nbsp;IN &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A 123.123.123.123<br>@ &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 <strong>example.com<\/strong> to the domain 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 example.com. \/var\/cache\/bind\/db.example<\/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 \"example.com.\" {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type master;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file \"db.example\";<br>};<\/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 loading=\"lazy\" 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:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/editing-dns-zone.png\/w=842,fit=scale-down 842w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/editing-dns-zone.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/editing-dns-zone.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/editing-dns-zone.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (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><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/ng\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-how-to-install-and-setup-the-mail-server-on-ubuntu\">How to install and setup the 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>example.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 <strong>gabriel<\/strong>. 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@example.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@example.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 service out of the box, like the one offered by <a href=\"\/ng\/business-email\">Hostinger<\/a>. Alternatively, <a href=\"\/ng\/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>        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Learn What Else Your Ubuntu Can Do                <\/p>\n            <\/div>\n            <p class=\"protip__content\"><a href=\"\/ng\/tutorials\/how-to-install-yarn\/\">How to Install Yarn on Ubuntu<\/a><br>\n<a href=\"\/ng\/tutorials\/how-to-install-git-on-ubuntu\/\">How to Install Git on Ubuntu<\/a><br>\n<a href=\"\/ng\/tutorials\/how-to-install-maven-on-ubuntu\/\">How to Install Maven in Ubuntu<\/a><br>\n<a href=\"\/ng\/tutorials\/install-pip-in-ubuntu\/\">How to Install Python Pip on Ubuntu<\/a><br>\n<a href=\"\/ng\/tutorials\/how-to-install-tomcat-on-ubuntu\/\">How to Install Tomcat on Ubuntu<\/a><br>\n<a href=\"\/ng\/tutorials\/how-to-install-jenkins-on-ubuntu\/\">How to Install Jenkins on Ubuntu<\/a><br>\n<a href=\"\/ng\/tutorials\/how-to-check-ubuntu-version\/\">How to Check Ubuntu Version<\/a><br>\n<a href=\"\/ng\/tutorials\/install-java-ubuntu\/\">How to Install Java on Ubuntu<\/a><\/p>\n                    <\/div>\n        \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 use Postfix to install and set up a mail [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ng\/tutorials\/how-to-install-ubuntu-mail-server\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":110,"featured_media":145127,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Start an Ubuntu Mail Server","rank_math_description":"Having your own email server brings control and security to your operation. Here's how you can start your own Ubuntu mail server.","rank_math_focus_keyword":"ubuntu mail server","footnotes":""},"categories":[22644],"tags":[],"class_list":["post-15832","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","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-GB","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\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/15832","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/comments?post=15832"}],"version-history":[{"count":24,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/15832\/revisions"}],"predecessor-version":[{"id":145126,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/15832\/revisions\/145126"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media\/145127"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media?parent=15832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/categories?post=15832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/tags?post=15832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}