Configuring DNS for Postfix:
To have a working configuration of Postfix, you must have a MX record added to your DNS server. I am setting up a DNS server using BIND 9 here just to demonstrate how everything works.
My Ubuntu 18.04 LTS machine has the IP address 192.168.199.170. This is going to be my DNS server and Mail server. So replace it with your IP address. I’ve chosen mail.linuxhint.com as the FQDN of my mail server. Replace it with yours.
First update the APT package repository cache with the following command:
Install BIND 9 DNS server with the following command:
Now press y and then press <Enter> to continue.
BIND 9 should be installed.
Now create a zone file with the following command:
Now add the following lines and save the file. Replace 192.168.199.170 with the IP address of your computer. Also replace linuxhint.com with your domain name.
Now check whether the configuration file is okay with the following command:
Now run the following command to edit /etc/bind/named.conf.default-zones file:
Now add the following lines to configure your DNS zone. Adjust where necessary.
Now edit /etc/bind/named.conf.options file with the following command:
Now uncomment forwarders (by removing // from the beginning of each line) and change 0.0.0.0 to Google’s DNS server 8.8.8.8
Before:
After:
Now restart BIND 9 with the following command:
Now you have to change your DNS server. I used Network Manager to do that.
If you don’t have network manager installed, install it with the following command:
List your network manager connection with the following command:
As you can see, the name of my active connection is Wired connection 1
Now edit your connection with the following command:
Remove the current DNS server:
Now run the following nmcli command to change your DNS server for the connection.
Save the changes.
Finally exit out of nmcli prompt:
Now restart the connection with the following commands:
Now set your hostname to mail.linuxhint.com with the following command:
Now reboot your computer for the changes to take effect.
Installing Postfix:
Now install Postfix with the following command:
Press <Tab> and then press <Enter> to continue.
Select Internet Site. Then press <Tab> to select <OK> and then press <Enter> to continue.
Type in your domain name. Then press <Tab> and then press <Enter> to continue.
Postfix should be installed and configured
Reconfiguring Postfix:
If you need to re-configure the Postfix server in future, run the following command:
Terminal based Postfix configuration wizard should show up. Just answer the questions and you’re done.
Configuring Users for Sending and Receiving E-Mails:
On Ubuntu 18.04 LTS, only users added to the mail group can send and receive E-Mails. By default, none of the users are added to the mail group.
You can add the user you’re logged in as to the mail group with the following command:
If the user you’re logged in as don’t have sudo or super user privileges, you can add user, let’s say linda to the mail group with the following command:
If you want to create new users for sending and receiving E-Mails, run the following command:
Here, USERNAME is the username of your new user.
In my case, let’s say the USERNAME is Kelly:
Now run the following command to set a login password for the USERNAME kelly:
Now enter the password for the user kelly and press <Enter>.
You will have to re-type the password again. Once you’re done, the password should be set.
Now the user kelly can send and receive E-Mails.
Sending and Reading E-Mails from the Command Line:
Ubuntu 18.04 LTS has many command line tools for sending emails such as Sendmail, mail, mutt etc.
In this section, I am going to show you how to use the mail command to send and read E-mails.
The mail program may not be installed by default on Ubuntu 18.04 LTS. Run the following command to install it:
Now press y and then press <Enter> to continue.
It should be installed.
Now you can send an E-Mail with the following command:
Let’s send an E-Mail to kelly,
You should be asked to provide Carbon Copy (CC). If you want to forward it to many mail addresses, type in the email addresses here. Otherwise leave it empty and press <Enter>.
Now type in the subject of your E-Mail. Once you’re done, press <Enter>.
Now type in your email.
Once you’re done, press <Ctrl> + d.
The mail should be sent.
Now kelly can read the E-Mail with the following command:
As you can see, kelly received my E-Mail.
Now type in the number as marked below and press <Enter> to read the E-Mail:
This is the E-Mail I sent kelly.
Now kelly can send an E-Mail to me as well.
I can see kelly’s email.
This is kelly’s email.
That’s how you install and configure Postfix on Ubuntu 18.04 LTS. Thanks for reading this article.