Setup Email Server Ubuntu 18.04

An email server or mail server is a computer system that lets you send and receive emails over standard email protocols. Ubuntu 18.04 is the latest version of Linux that comes with the latest Linux kernel 4.15 series and GNOME desktop 3.28 as the default desktop.

Setup Email Server Ubuntu 18.04

Let’s see how to set up an email server on Ubuntu 18.04 using Postfix.

Postfix is a free, open-source, and widely used mail server.

You can set up an email server on Ubuntu 18.04 easily.

  1. First, you need to configure a DNS server for the Ubuntu Mail Server.
  2. After configuring it, set up your current connection.
  3. Once you have done the connection configuration, your Ubuntu system is ready to install and setup the Mail Server.

Now, let’s see the email setup process in detail.

Configuring a DNS Server

Step 1: Log in to your Server and update it

  1. You can perform this step using SSL.
  2. Once you have signed in to your server, update Ubuntu using the command mentioned below.

    apt-get update -y

Step 2: Installing Bind

  • You need to install any additional tool such as Bind to configure the DNS server that uses Postfix.
  • To install the Bind tool, run the following command:

    sudo apt install bind9

Step 3: Configuring /var/cache/db.test

  • Now, you need to replace the IP address of your Ubuntu 18.04 ( with the IP address where we will perform the install process.
  • For example, consider as an FQDNS. Now, you need to create a new zone for Use the following command to create the new zone:

    sudo nano /var/cache/bind/db.test

  • Now, add the following commands:

    $ORIGIN $TTL 1D @ IN SOA ns1 root( 1 ;serial 1D ;refresh 2H ;retry 2W ;expire 5H ;minimum ); @ IN NS ns1 ns1 IN A mail IN A @ IN MX 5 mail

  • Make sure to replace your server’s IP address.
  • You can also change the domain of your desire.
  • Press the Ctrl + O buttons followed by Ctrl +X to save and close the nano editor.

Step 4: Configure and add a new zone to Bind

  • Check the configuration of the newly created file. To do so, run the following command:  

    sudo named-checkzone /var/cache/bind/db.test

  • Now, add your new zone to the Bind zone configuration file using the commands mentioned below.         

    sudo nano /etc/bind/named.conf.default-zones        zone “” {        type master;        file “db.test”; };

  • Save the changes and close it.

Step 5: Configuring /etc/bind/named.conf.options

  1. Run the sudo nano /etc/bind/named.confi.options. Wait for the process to complete.
  2. Once it is done, remove the forwarders line (// symbols) and add Google DNS 

Step 6: Restart the Bind service

Use any one of the commands mentioned below to restart the bind9 service.


sudo systemctl reload bind9                or          sudo systemctl restart bind9

Configuring your current connection

Step 1: First, download and install the Network- manager on your computer using the command given below:


sudo apt install network-manager

Step 2: To display all active connections use the following command:


sudo nmcli connection slow

All active connections will be shaded green.

Step 3: Now, select the connection you wish to configure using the command given below:

sudo nmcli connection edit “[active connection name]”

In the command above, replace “[active connection name]” with your connection name.

Step 4: Delete or remove the existing server.

To do so, run the following command:


nmcli> remove ipv4.dns

Step 5: Now, set up a new DNS server using the command mentioned below:


nmcli> set ipv4.dns [mail_server]

Step 6: Save and exit from the connection configuration window by using the commands given below.


nmcli> save
                    nmcli> quit

Step 7: Restart your connection

sudo nmcli connection down “[active connection name]”
                    sudo nmcli connection up “[active connection name]”

In the commands above, make sure to replace the “active connection name” field with your connection name correctly.

Step 8: Now, change your hostname using the command mentioned below.


sudo hostnamect1 set-hostname

Installing and setting up a Mail Server on Ubuntu 18.04

Step 1: Install Postfix using the following command: 

sudo apt install postfix

  1. Make sure to select the Internet Site option when prompted during the installation process.
  2. Similarly, enter your server name in the given field.
  3. In the section below, we’ll be using as the server name.

Step 2: Adding user

  1. First, create a mail group using the command mentioned below.

    sudo usermod -aG mail $(whoami)

  2. Now, create the users and set a password for them.
  3. To do so, use the following commands.
  4. For example, create the XXXX user using the command given below.

sudo useradd -m -Gmail -s /bin/bash/ xxxx

Note: Replace “XXXX” with the user’s name.

  • Set password for users using: sudo password xxxx
  • The email server has been set up successfully on your Ubuntu 18.04 system.
  • To test the Ubuntu Mail Server, install the mailutils package, and then send & receive an email from the terminal.
  • To install the mailutils package, use the following command:  sudo apt install mailutils
  • Once it has been installed, compose an email message. To start writing an email, run the mail command.
  • Now, you can see the emails that you have sent.
  • To check the outbound emails list, run the mail command.

Contacts us to get remote assistance on the same.