# Linux System Admin Project(Mail Server,DNS)

1. Login via SSH
    

To start the SquirrelMail installation, login to your CentOS 9 VPS via SSH as user root

```abap
ssh root@IP_address -p PORT_NUMBER
```

VPS Name: test1.linuxreview.co.in

```plaintext
hostnamectl set-hostname test1.linuxreview.co.in
hostnamectl(to verify)
```

Username:goutam

Root Password:goutam@123

```plaintext
useradd goutam
passwd goutam ********
```

IP:103.234.116.177

SSH Port:22

### Configure DNS Server

Mapped DNS Records:

[test1.linuxreview.co.in](http://test1.linuxreview.co.in). IN A 103.234.116.177

[mail.test1.linuxreview.co.in](http://mail.test1.linuxreview.co.in). IN A 103.234.116.177

[webmail.test1.linuxreview.co.in](http://webmail.test1.linuxreview.co.in). IN A 103.234.116.177

[test1.linuxreview.co.in](http://test1.linuxreview.co.in). IN MX 10 [test1.linuxreview.co.in](http://test1.linuxreview.co.in).

1. Prerequisites
    
2. Install Bind Package
    
3. Configure Bind Service
    
4. Create Zone File
    
5. Start Bind Service
    
6. Verify DNS Resolution
    

## **Install Bind Package:**

```plaintext
sudo yum update -y
sudo yum install bind bind-utils
```

## **Configure Bind Service:**

```plaintext
sudo vi /etc/named.conf
```

Add the following line at the end of the file to define the local domain zone:

```plaintext
zone "linuxreview.co.in" IN {
    type master;
    file "/var/named/linuxreview.co.in";
    allow-update { none; };
};
```

## **Create Zone File:**

After defining the local domain zone, you need to create the zone file. Run the following command to create the zone file:

```plaintext
sudo vi /var/named/linuxreview.co.in
```

Add the following lines to the file to define the domain name and IP address mapping:

```plaintext
$TTL 86400
@   IN  SOA ns1.linuxreview.co.in. admin.linuxreview.co.in. (
    2016042201  ;Serial
    3600        ;Refresh
    1800        ;Retry
    604800      ;Expire
    86400       ;Minimum TTL
)
@   IN  NS  ns1.linuxreview.co.in.
@   IN  A   103.234.116.177
ns1 IN  A   103.234.116.177
test1.linuxreview.co.in. IN A 103.234.116.177 

mail.test1.linuxreview.co.in. IN A 103.234.116.177 

webmail.test1.linuxreview.co.in. IN A 103.234.116.177 

test1.linuxreview.co.in. IN MX 10 test1.linuxreview.co.in.
```

## **Start Bind Service:**

After creating the zone file, start the Bind service by running the following command:

```plaintext
sudo systemctl start named
```

To enable the Bind service to start automatically at boot time, run the following command:

```plaintext
sudo systemctl enable named
```

## **Verify DNS Resolution:**

To verify that your DNS server is working correctly, use the dig command to query the DNS server:

```plaintext
dig linuxreview.co.in
```

# *LAMP Setup*

1. Setup Apache and host the website for [test1.linuxreview.co.in](http://test1.linuxreview.co.in) on this server
    
2. Install Mariadb and PHP latest stable version on the server
    
3. Install Wordpress and PHPMyAdmin on the server
    
4. Enable Gzip compression on the web server and on the hosted WP website.
    
5. Check incoming and outgoing requests on the server logs.
    
6. Increase the no of workers and threads on the Apache server
    
7. Enable Letsencrypt SSL on this domain to prevent any SSL errors
    

```plaintext
Install and setup Apache with virtual host:

sudo yum install httpd
sudo systemctl start httpd
sudo systemctl enable httpd

sudo echo "ServerName localhost" >> /etc/httpd/conf/httpd.conf

sudo systemctl restart httpd
sudo mkdir -p /var/www/test1.linuxreview.co.in/public_html

sudo chown -R apache:apache /var/www/test1.linuxreview.co.in/public_html

sudo chmod -R 755 /var/www
sudo cp /etc/httpd/conf.d/vhost.conf /etc/httpd/conf.d/test1.linuxreview.co.in.conf
sudo vi /etc/httpd/conf.d/test1.linuxreview.co.in.conf
sudo systemctl reload httpd
```

### Install MariaDB and PHP:

```plaintext

sudo yum install mariadb-server mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
sudo yum install php php-mysql php-gd php-mbstring
sudo systemctl restart httpd
```

### Install WordPress and PHPMyAdmin:

```abap
Install WordPress and 
PHPMyAdmin:

sudo yum install wget
cd /var/www/test1.linuxreview.co.in/public_html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xvzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz
sudo systemctl restart httpd
sudo yum install phpMyAdmin
sudo vi /etc/httpd/conf.d/phpMyAdmin.conf
sudo systemctl restart httpd
```

```abap
sudo mysql
sudo mysql -u root -p
CREATE USER 'ata'@'localhost' IDENTIFIED BY 'pa$$word';
GRANT ALL PRIVILEGES ON *.* TO 'ata'@'localhost' WITH GRANT OPTION;
exit
Navigate to http://your_domain_or_IP/phpmyadmin, where your_domain_or_IP 
is the IP address or the DNS record pointing to your phpMyAdmin server.
On the Welcome to phpMyAdmin page that loads, type in the username and 
password you created from the previous section and click Go.
```

### Enable Gzip compression:

```plaintext


sudo vi /etc/httpd/conf.d/deflate.conf
sudo systemctl restart httpd


Check server logs for incoming/
outgoing requests:

sudo tail -f /var/log/httpd/access_log
sudo tail -f /var/log/httpd/error_log


Increase workers and threads on Apache:

sudo vi /etc/httpd/conf/httpd.conf
sudo systemctl restart httpd
```

### Enable Letsencrypt SSL:

```plaintext

sudo yum install certbot python3-certbot-apache
sudo certbot --apache
```

# POSTFIX for SMTP (Simple Mail Transfer Protocol): Used for Sending the Emails.

# DOVECOT for POP3 (Post Office Protocol): Used for Receiving the Emails.

# SQUIRRELMAIL for IMAP (Internet Message Access Protocol): Used for Front Web End Mail Client.

# Server Configuration: RHEL 7 IP Address: 103.234.116.177

1. Set the hostname in the machine.
    

```abap
hostnamectl set-hostname test1.linuxreview.co.in
```

Add hostname entries in /etc/hosts file as shown below:

# vim /etc/hosts

Add the following 103.234.116.177 [test1.linuxreview.co.in](http://test1.linuxreview.co.in) test1

1. Disable or make permissive the SELINUX
    

```abap
setenforce 0
getenforce
```

1. Install EPEL Repository:
    

```abap
wget https://dl.fedoraproject.org/pub/epel...
rpm -ivh epel-release-latest-7.noarch.rpm
yum install -y epel-release
```

1. Allow the Apache default port 80 through your firewall/router:
    

```abap
firewall-cmd --permanent --add-port=80/tcp
```

Reload firewall using command:

```abap
firewall-cmd --reload
```

1. Install the Postfix Package.
    

```abap
yum install postfix -y
```

1. Configuring PostFix
    

```abap
vim /etc/postfix/main.cf
```

## Line no 77 - Uncomment and set your mail server FQDN

myhostname = [test1.linuxreview.co.in](http://test1.linuxreview.co.in)

## Line 85 - Uncomment and Set domain name

mydomain = [linuxreview.co.in](http://linuxreview.co.in)

## Line 101 - Uncomment

myorigin = $mydomain

## Line 115 - Uncomment and Set ipv4

inet\_interfaces = all

## Line 121 - Change to all

inet\_protocols = all

## Line 166 - Comment

#mydestination = $myhostname, [localhost](http://localhost).$mydomain, [localhost](http://localhost),

## Line 167 - Uncomment

mydestination = $myhostname, [localhost](http://localhost).$mydomain, [localhost](http://localhost), $mydomain

## Line 266 - Uncomment and add IP range

mynetworks = 103.234.116.0/24, 127.0.0.0/8

## Line 421 - Uncomment

home\_mailbox = Maildir/

Save and exit the file.

Start/restart Postfix service now:

```abap
systemctl restart postfix
systemctl enable postfix
systemctl status postfix
```

1. Test the Postfix Server:
    

Add the user account.

```abap
useradd goutam
passwd goutam    (Configuring Password)
```

Install Telnet Package

```abap
yum install -y telnet
```

Check telnet

```abap
telnet localhost smtp

ehlo localhost     (Type the commands)
mail from:goutam
rcpt to:goutamkumar
50 5.1.1 <goutamkumar>: Recipient address rejected: User unknown in local recipient table
(It means user is not created,create the user and try again)
data
welcome to Postfix Mail Server(mentioned their below)
.   (write dot)
250 2.0.0 Ok: queued as 4FA2022DDD25
quit
221 2.0.0 Bye
Connection closed by foreign host.
```

```abap
.
quit
ll /home/goutamkumar/Maildir/new/ (verifying the same)
total 4
-rw-------. 1 goutamkumar goutamkumar 455 Sep 23 11:45 1695449745.Vfd00I22f4f98M693658.test1.linuxreview.co.in
```

Open the file with name using cat.

1. ***Install Dovecot Package***
    

```abap
yum install -y dovecot
Configure Dovecot vim /etc/dovecot/dovecot.conf
```

## Line 24 - umcomment

protocols = imap pop3 lmtp (after that save this)

Edit file /etc/dovecot/conf.d/10-mail.conf file

```abap
vim /etc/dovecot/conf.d/10-mail.conf
```

## Line 24 - uncomment

mail\_location = maildir:~/Maildir (save this)

Edit /etc/dovecot/conf.d/10-auth.conf

```abap
vim /etc/dovecot/conf.d/10-auth.conf
```

And make the changes as shown below:

## line 10 - uncomment##

disable\_plaintext\_auth = yes

## Line 100 - Add the word: "login"

auth\_mechanisms = plain login (save)

Edit file /etc/dovecot/conf.d/10-master.conf,

```abap
vim /etc/dovecot/conf.d/10-master.conf
```

Make changes as shown below:

## Line 91, 92 - Uncomment and add "postfix"

#mode = 0600 user = postfix group = postfix \[...\]

Start Dovecot service:

```abap
systemctl start dovecot
systemctl enable dovecot
```

Testing Dovecot

```abap
telnet localhost pop3
user goutamkumar 
pass linux
retr 1 (retrive the recipient)
. 
quit
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695456422147/b4eff5a2-02a0-47c5-b763-556391c280d4.png align="center")

quit

1. ***Install Squirrel mail Package***
    

```abap
yum install squirrelmail
```

Or Follow this process(if the squirrelmail not found then follow this process)

1. Download SquirrelMail from [here on the squirrelmail site](https://squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fprdownloads.sourceforge.net%2Fsquirrelmail%2Fsquirrelmail-webmail-1.4.22.zip).(zip file)
    
2. Open Terminal and navigate to Downloads:
    
    ```abap
    cd Downloads
    ```
    
3. Unzip downloaded zip file.
    
    ```abap
    unzip squirrelmail-webmail-1.4.22.zip
    or
    tar -xvf squirrelmail-webmail-1.4.22.tar.gz
    ```
    
4. Run configure file:
    
    ```abap
    ./configure 
    ```
    

Or

Configuring Squirrel-Mail

```abap
cd /usr/share/squirrelmail/config/
./conf.pl
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696144089563/d54c64e4-11a1-43f3-8d68-24084942ba11.png align="center")

Enter 1 Enter 1 and change the organization Name Press S Press R for previous menu

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696144149727/88e2a48f-5195-41e2-bb5b-ea5967401797.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696144236255/244a6058-1010-4212-8f4a-28defb65ef79.png align="center")

Type S and Press Q for quit

Type R return to main menu

Enter 2 for Server settings

Press 1 and type: **test1.linuxreview.co.in** (Name of Domain)

Press 3 (SMTP)

Press 2 for switching from Send Mail to SMTP

Type S and Press Q for quit

1. Create a squirrelmail vhost in apache config file:
    

```abap
vim /etc/httpd/conf/httpd.conf
```

Go to the bottom and ,Enter the following:

```abap
Alias /webmail /usr/share/squirrelmail 
<Directory /usr/share/squirrelmail>
Options Indexes FollowSymLinks 

RewriteEngine On 

AllowOverride All 

DirectoryIndex index.php 

Order allow,deny 

Allow from all 

</Directory>
```

```abap
systemctl restart httpd
systemctl enable httpd
```

Enter the following command:

```abap
setsebool httpd_can_network_connect=1(To enable the link opwn in browser)
```

Open Web Browser and type in address bar the following. And Use User Credentials to Login. [http://103.234.116.177/webmail](http://103.234.116.177/webmail)

Your Dovecot Server is working.
