How To Setup A Mail Server In Ubuntu?
If you use your own email server, it will control all the network traffic and help you in managing the services clearly. Let’s see how to set up a mail server on Ubuntu. In the following section, the steps to set up a VPS server that runs on Ubuntu 18.04 and How To Setup A Mail Server In Ubuntu are given.
Now, let us see how to set up Outlook.com to forward all the incoming emails to another email address.
Create an email server in Linux using Postfix by following the steps that are given below
Step 1: Updating your server
- First, sign in to your server using Secure Shell.
- Open the Terminal window and enter ssh email@example.com. Make sure to replace exampledomain.com with your IP address or domain name.
- When you are prompted for confirmation, type Yes and then enter the root password.
- Now, update your server by typing apt-get update.
Step 2: Installing Bind
- You will require an additional tool named Bind to configure a DNS server using Postfix.
- Enter sudo apt install bind9.
Step 3: Configuring /var/cache/db.test
- Let us consider 192.168.250.7 as the IP address of your server. Make sure you replace it with your server’s IP address.
- To create a new a new file with the information about the zone, type sudo nano /var/cache/bind/db.test.
- Now, you can add the following details in the file.
- To save the settings you have made, press the Ctrl+O buttons together, and press Ctrl+X to close the editor.
$ORIGIN test.com. $TTL 1D @ IN SOA ns1 root( 1 ;serial 1D ;refresh 2H ;retry 2W ;expire 5H ;minimum ); @ IN NS ns1 ns1 IN A 192.168.250.7 mail IN A 192.168.250.7 @ IN MX 5 mail
Step 4: Adding a new zone
- You have to check the configuration of the file before you enable the newly created zone.
- Type sudo named-checkzone test.com. /var/cache/bind/db.test.
- To bind configuration, enter sudo nano /etc/bind/named.conf.default-zones.
- Save the settings you have made and close the nano editor.
Step 5: Configuring /etc/bind/named.conf.options
- Include the Google DNS number 188.8.131.52. If that entry is already present in the conf file, just remove the // symbols.
- Enter sudo nano /etc/bind/named.conf.options to make the changes to the file.
Step 6: Restarting Bind
- Now, you have to restart the Bind service before configuring the connection.
- Enter sudo systemctl reload bind9.
Step 7: Configuring the connection
- You have to change the DNS server to the Ubuntu mail server by following the instructions given below.
- Download Network Manager by entering sudo apt install network-manager.
- Type sudo nmcli connection show to view all active connections.
- Select the connection you want to edit. Now, enter sudo nmcli connection edit “[active connection name].”
- Make sure to replace ‘active connection name’ with the name of the connection.
- To remove the existing DNS server, type Nmcli> remove ipv4.dns.
- To create a new DNS Server, enter nmcli> set ipv4.dns [mail_server].
- Enter nmcli> save and nmcli> exit to save and close it.
- Now, you can restart your connection by entering the following commands. Make sure to replace your connection name in the active connection name section.
- Change your hostname by entering sudo hostnamectl set-hostname mail.test.com.
- Make sure to log out and then log in to your server before setting up the mail server.
sudo nmcli connection down “[active connection name]” sudo nmcli connection up “[active connection name]”
Step 8: Installing and setting up a Mail server:
- To install the Postfix mail server, enter sudo apt install postfix.
- You can add users to the mail group by entering sudo usermod -aG mail $(whoami).
- We have to add users to send and receive emails. Here we add user1. sudo useradd -m -G mail -s /bin/bash/ user1
- Enter sudo passwd User to create a password.
Step 9: Testing the Ubuntu Mail server
- You have to install mailutils package to send and receive emails from the Terminal.
- Enter sudo apt install mailutils.
- To create an email, type mail firstname.lastname@example.org.
- Once you have added your subject and message, press the Ctrl+D buttons together.
- You can also add another email and test the server.
- You have now successfully set up the mail server on Ubuntu 18.04 and How To Setup A Mail Server In Ubuntu.