From Wikipedia
Hello friends! Today we are discussing “configuration of SMTP mail server” for sending mail in your LAN network.
SMTP stands for simple mail transfer protocol communication between mail servers uses TCP port 25 Mail clients. For retrieving messages, client applications usually use either IMAP or POP3.
POP3 stands for Post Office Protocol (POP) is an application-layer Internet standard protocol used by local e-mail clients to retrieve e-mail from a remote server over a TCP/IP connection. It uses port 110 for receiving mail.
IMAP stands for Internet Message Access Protocol (IMAP) is also an Internet standard protocol used by e-mail clients to retrieve e-mail messages from a mail server over a TCP/IP connection. It uses port 143 for receiving mail.
Let’s start!!
Add Hostname and domain
With root privilege open hosts file for adding hostname and Domain name through following command:
sudo gedit /etc/hosts
Now add given below line in host file and then save it.
127.0.0.1 mail.ignite.lab ignite
Open hostname file with root privilege for changing the default hostname.
sudo gedit /etc/hostname
Now re-write the default hostname as “ignite” which we have mention in host file also, as shown in given image and save it.
Now restart the machine after making changes in hosts file and hostname.
sudo reboot
Now check hostname and domain by typing following command and assured the changes you had made.
hostname
hostname -f
Install Postfix
Postfix is the default Mail Transfer Agent (MTA) for Ubuntu. It is in Ubuntu’s main repository, which means that it receives security updates. This guide explains how to install and configure postfix and set it up as an SMTP server using a secure connection.
sudo apt-get install postfix
A dialog box will pop for Postfix Configuration where you have to select Internet site as general type of mail configuration as shown in given image.
Enter Domain name (mail.ignite.lab) which you have save inside host file for system mail name and click on OK.
Postfix Configuration Setting
Open main.cf file and make following changes in this then save it.
sudo gedit /etc/postfix/main.cf
- Add subnet IP mynetworks = 127.0.0.0/8 168.1.0/24
- Enter inet_protocols = ipv4
- Add new line home_mailbox = Maildir/
Execute given below command after making changes in configuration file.
sudo service postfix restart
Now Type following command to view the list of open port to listen for incoming connections.
netstat –tnl
-t: for TCP ports
-n: for network
-l: for list
From given image you can observe that STATE of port 25.
Install Dovecot
Dovecot is a Mail Delivery Agent, written with security primarily in mind. It supports the major mailbox formats: mbox or Maildir. This section explains how to set it up as an imap or pop3 server.
sudo apt-get install dovecot-imapd dovecot-pop3d
A dialog box will pop for configuring dovecot-core where you can select yes for create a self –signed SSL certificate.
Another POP up will ask hostnamethat will be used in ssl certificates. Enter your doamin name as shown in given image and click on OK.
Dovecot configuration setting
Open 10-auth.conf file through given below path:
sudo gedit /etc/dovecot/conf.d/10-auth.conf
Now make following changes in this as shown in given image then save it.
disable_plaintest_auth = yes
change auth mechanisms = plain login
Open 10-mail.conf file through given below path:
sudo gedit /etc/dovecot/conf.d/10-mail.conf
Now make following changes in this as shown in given image then save it.
mail_location= maildir:/home/%u/Maildir
Open 10-master.conf file through given below path:
sudo gedit /etc/dovecot/conf.d/10-master.conf
Enable port =143
Enable port = 110
Give permission for unix_listener auth-user db
Mode = 0600
User = postfix
Group = postfix
sudo service dovecot restart
Check service using netstat–tnl to view the list of open port to listen for incoming connections
From given image you can observe STATE LISTEN for port 110 and 143.
Configure mail Account in Thunderbird
We have already a user: sr let’s configure a mail account for him by adding following information in given text field
- Your name: sr
- Email address: sr@mail.ignite.lab
- Password: 1234 (user’s password)
Now click on continue then choose manual config tab.
Enter your network IP as server hostname (192.168.1.1107) for incoming mail on port 143 and outgoing mail via port 25. Then click on done.
A new window will come up for security Exception click on tab Confirm security Exception given at bottom.
For sending mail we always need two users account one as sender another for receiver. Now type following command to add a new user.
adduser raj
Since we had already configure an account for user:sr in thunderbird , now create another mail account for usre:raj in thunderbird as created above.
Hence we are having two accounts in mail server for sending message
- Sender: raj@mail.ignite.lab
- Receiver: sr@mail.ignite.lab
Send mail using Thunderbird
Now write an Email from: sr@mail.ignite.lab to raj@mail.ignite.lab for testing mail server service as shown in given image. Click on send after typing message.
Open the inbox of receiver account where you will get a mail from sr@mail.ignite.lab as shown in given image.
In this way you can configure your own mail server for local network.
Sanjeet Kumar is a Information Security Analyst | Pentester | Researcher Contact Here
The post SMTP Pentest Lab Setup in Ubuntu appeared first on Hacking Articles.