How to Create a Mail Server on Ubuntu

In this tutorial, we will guide how to install and set up an Ubuntu mail server on an Ubuntu 18.04 VPS server. There are several alternatives for creating a Linux mail server; however, we will focus on Postfix.


Configuring DNS Servers For Ubuntu Mail Server


You can follow the steps that we have provided. By following the steps we provide, there will be no problems when you want to manage the email server configuration:


1. Login and Update Your Server

Log in to your server using SSh. If you have trouble logging in, After successfully logging in, you need to update your device using the command:

 


2. install bind

To configure DNS servers that will require Postfix, you must have an additional tool called Bind. Run the following command to install the tool:

 


Configuration/var/cache/db.test 

In this step, you need to remember that the IP address for Ubuntu 18.04 devices is 192.168.250.7. Therefore, the IP address needs to be changed to the address where the installation will run. For example, we use mail.test.com as the FQDNS.

So, now you need to create a new zone. To do this, create a new file with the zone information.

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

Then, add this command line:

$ORIGIN test.com.$TTL 1D@IN SOA ns1 root(1 ;serial 1D ;refresh 2H ;retry 2W ; expire 5H ;minimum);@  

IN NS ns1ns1

IN A 192.168.250.7mail

IN A 192.168.250.7@

IN MX 5 mail 


Keep in mind, you must change the IP address with the command line, and change the domain to the one you want to use. After that, press CTRL+O to save the changes, and press CTRL+X to close the nano editor.


4.  Adding a New Zone for Bind Configuration


Before activating the new zone, you need to check the configuration file first.

 

After that, you can add a new zone to the Bind configuration zone. To do so, run the command:

 

Then, add a new zone:

 

Don't forget to press CTRL+O to save your changes, and press CTRL+X to close the nano editor.


5. Configuration /etc/bind/named.conf.options 

You need to uncomment the forwarder line and enter Google DNS  – 8.8.8.8. In the file /etc/bind/named.conf.options.  To do so, you just need to remove the // symbol as shown in the image below: 

 


6. Restart Bind 

Now, you need to restart bind9. You can do this through two commands:

 

Or

 


Configuring the connection used

 

When you're done with the process, you'll need to change your DNS server to the Ubuntu mail server, as it will also be your DNS server.


1. Download Network-Manager

To do so, you can use network-manager. Install the tool by entering the following command on the command line:

 


2. Display All Active Connections

After that, you can display all active connections by running the command:

 

For active connections, it is shown in green.


3. Select Specific Connections to Change

Now you can know approximately which connection needs to be changed. In the command below, replace "[active connection name]" with the connection name you want to change:

 


4. Remove Active DNS Servers

You can remove the active DNS Server with the following command:

 


5. Set New DNS Servers

To set up a new DNS server, you need to run the commands as shown below:

 

Here are the commands to save changes and exit:

 
 


6. Connection Restart

The next step is to restart the connection so that the changes that have been made can run properly. Keep in mind that you need to enter the name of your connection:

 


7. Changing the Active Hostname

You need to change the active hostname as the last step before installing the mail server:

 

We recommend logging out and then logging back in to your server before starting the next session.


How to Create a Mail Server on Ubuntu 18.04

 

Here are the steps you need to execute:


1. Install Postfix Email Server

You can install Postfix. Postfix is an email server written in the C programming language. The main features of Postfix are its execution speed and open-source features. Install Postfix with the following command:

 

During the installation process, there will be questions to configure the package. On the first screen, select the Internet Site option.

Then, you can enter the server name. In this case, it's example.com.

Postfix is very flexible and flexible in terms of extensive configuration. However, in this tutorial, we will stick with the default configuration.


2. Add User

Next, you need to add users to the mail group:

 

This needs to be done because in Ubuntu 18.04, only users who are in the mail group can use this utility.

Then, create users and add them to mail groups so they can send and receive mail. In this example, Gabriel will be added to the mail group:

 

Afterward, you can set a password for the newly created user:

 

 

Test Ubuntu Mail Server

After creating a mail server in Ubuntu, there is one important thing that needs to be done. That is to test the mail by sending and receiving emails from the terminal. To do so, you need to install the mailutils package:

 

That way, you can send an email to another email account user named example. Type the subject and message you want to send. After that, press CTRL+D to complete the process. To compose an email, enter the following command:

 

Now we can log in to the other user and check the mail utility.

After running the email command, you will see the email that was just sent to another test user. To access the email, simply write the mail number, in this case, 1.

To test the outbound email from this user, try entering another email address:

 

Now you can send emails from Ubuntu 18.04 email sever

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.