Sunday, 4 May 2014

MAIL SERVER CONFIGURATION USING SQUIRREL MAIL WEB MAIL SERVER

(1) SET HOST NAME  
[root@www ~]# hostname www.arunmail.com
[root@www ~]# vi /etc/sysconfig/network

































[root@www ~]# vi /etc/hosts




(2) Configure DNS Server

For DNS  There are 3 Utility. Before configure DNS we  have to install following packages using yum.


[root@www ~]# yum install bind
[root@www ~]# yum install bind-utils
[root@www ~]# yum install caching-nameserver

[root@www ~]# vi /etc/named.conf




[root@www ~]# cd /var/named/
[root@www named]# ll
total 40
drwxr-x--- 5 root  named 4096 May  4 04:47 chroot
drwxrwx--- 2 named named 4096 Dec  2  2011 data
-rw-r----- 1 root  named  198 Dec  2  2011 localdomain.zone
-rw-r----- 1 root  named  195 Dec  2  2011 localhost.zone
-rw-r----- 1 root  named  427 Dec  2  2011 named.broadcast
-rw-r----- 1 root  named 1892 Dec  2  2011 named.ca
-rw-r----- 1 root  named  424 Dec  2  2011 named.ip6.local
-rw-r----- 1 root  named  426 Dec  2  2011 named.local
-rw-r----- 1 root  named  427 Dec  2  2011 named.zero
drwxrwx--- 2 named named 4096 Dec  2  2011 slaves

[root@www named]# cp localhost.zone for
[root@www named]# cp localhost.zone rev



## Edit for file like this 


[root@www named]# vim for




## Edit Rev file Like This

[root@www named]# vim rev





[root@www named]# service named restart
Stopping named:                                            [  OK  ]
Starting named:                                            [  OK  ]

[root@www named]# chkconfig named  --list
named           0:off   1:off   2:off   3:off   4:off   5:off   6:off
[root@www named]# chkconfig named on

[root@www named]# nslookup www.arunmail.com
Server:         192.168.88.140
Address:        192.168.88.140#53

Name:   www.arunmail.com
Address: 192.168.88.140

[root@www named]# nslookup 192.168.88.140
Server:         192.168.88.140
Address:        192.168.88.140#53

140.88.168.192.in-addr.arpa     name = www.arunmail.com.

(3) Configure Postfix MTA (MAIL TRANSPORT AGENT)

[root@www ~]# yum install postfix*


Make change in configuration file as bellow

[root@www ~]# vi /etc/postfix/main.cf

(1) myhostname = www.arunmail.com.
#myhostname = virtual.domain.tld

(2)mydomain = arunmail.com

(3)#myorigin = $myhostname
myorigin = $mydomain

(4)inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost


(5)mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain




[root@www named]# alternatives --config mta

There are 2 programs which provide 'mta'.

  Selection    Command
-----------------------------------------------
*  1           /usr/sbin/sendmail.sendmail
 + 2           /usr/sbin/sendmail.postfix

Enter to keep the current selection[+], or type selection number: 2


[root@www named]# chkconfig sendmail off

[root@www named]# service postfix restart
Shutting down postfix:                                     [FAILED]
Starting postfix:                                          [  OK  ]

[root@www named]# chkconfig postfix on


(4) Now Configure Dovecot MRA( Mail Retrieving Agent ) 



[root@www named]# yum install dovecot*



## Make change in the configuration file like bellow

[root@www named]# vi /etc/dovecot.conf

protocols = imap imaps pop3 pop3s



[root@www named]# service dovecot restart
Stopping Dovecot Imap:                                     [FAILED]
Starting Dovecot Imap:                                     [  OK  ]
[root@www named]# service dovecot restart
Stopping Dovecot Imap:                                     [  OK  ]
Starting Dovecot Imap:                                     [  OK  ]

[root@www named]# chkconfig dovecot on







(5) Now configure Squirrel mail web mail server


[root@www named]# yum install  squirrelmail*

[root@www ~]# cd /usr/share/squirrelmail/config/
[root@www config]# ll
total 188
-rwxrwxrwx 1 root root  29548 Oct  5  2009 config_default.php
lrwxrwxrwx 1 root root     45 May  4 06:13 config_local.php -> ../../../../etc/squirrelmail/config_local.php
lrwxrwxrwx 1 root root     39 May  4 06:13 config.php -> ../../../../etc/squirrelmail/config.php
-rwxrwxrwx 1 root root 148706 Oct  5  2009 conf.pl
-rwxrwxrwx 1 root root    492 Oct  5  2009 index.php

root@www config]# ./conf.pl











(6) Now Configure Apache web Server 


[root@www named]# yum install  httpd*


## Make change in the configuration file like bellow


[root@www named]# vi /etc/httpd/conf/httpd.conf

(1) ServerName www.arunmail.com:80


(2) NameVirtualHost 192.168.88.140:80

(
3)
  <VirtualHost 192.168.88.140:80>
#    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /usr/share/squirrelmail
    ServerName www.arunmail.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>

[root@www named]# vi /etc/httpd/conf/httpd.conf
[root@www named]# service httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd:                                            [  OK  ]
[root@www named]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]


[root@www named]# chkconfig httpd on




(7) Now add 2 user for testing.



(1) root@www ~]# useradd arun
[root@www ~]# passwd arun
Changing password for user arun.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.


(2) [root@www ~]# useradd gaurav
[root@www ~]# passwd gaurav
Changing password for user gaurav.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.



(8) Open Firefox and open the url www.arunmail.com






















Saturday, 4 January 2014

Find Command in Linux with Examples

FIND:- Find  - searches for files in a directory hierarchy

FIND command  uses and example

(1) Find all files whose name is abc in pwd (Present Working Directory)
[root@CLIENT ~ ] #  find . -name abc
./abc

(2) Find all file in /home directory  whose name is abc
[root@CLIENT ~ ] # find  /home  -name  abc

(3) Find all file whose name is abc ignoring case senstivity
[root@CLIENT ~ ] # find /home  -iname abc

(4) Find a directory in  /home directory  whose name is arun
[root@CLIENT ~ ] # find /home -type d -name arun
/home/arun

(5) Find all html files in Linux file system
[root@CLIENT ~ ] # find  / -type f -name "*.html"

(6) Find files base on their permissions
[root@CLIENT ~ ] # find  / -type f   -perm 700

(7) Find all files with their permission 700 and change permission with  600
[root@CLIENT ~ ] # find  / -type  f  -perm 700 -exec chmod 600 {} \;

(8) Find all files  base on user arun
[root@CLIENT ~ ] # find  /  -user arun

(9) Find all files  base on group Linux
[root@CLIENT ~ ] # find  /  -group Linux

(10) Find a particular file named abc.txt of user arun
[root@CLIENT ~ ] # find  /  -type f -user arun -name abc.txt

(11) Find files and directory on base of date and time

-atime    access time              |          +90          more than 90 days back
-mtime   modified time           |           90           exact 90 days back
-ctime    change time             |           -90          less than 90 days back

[root@CLIENT ~ ] #  find  / -ctime +90

(12) Find  files whose size is less than 10 MB
[root@CLIENT ~ ] #  find  /  -size  -10M

(13) Find  files whose size is less than 100 MB and more than 50 MB
[root@CLIENT ~ ] #  find  /  -size  -100M  -size  +50M











Thursday, 2 January 2014

Boot Process of Linux

There are 6 process occurs during booting process of kernel

(1) BIOS
(2) MBR
(3) GRUB
(4) KERNEL
(5) INIT
(6) RUN LEVEL PROGRAMS


BIOS:- BIOS stands for Basic Input Output System
Bios search , loads & execute boot loader program.Once the boot loader program is detected & loaded into memory.Bios gives control to it.


MBR:- MBR stands for master boot record
 The first sector  of bootable device is MBR
Its size is 512 bytes


 446 Bytes
 (Primary Bootloader Info)
64 Bytes
 (Partition table info) 
2Bytes (validation check)




GRUB:- GRUB stands Grand Unified Bootloader 
It loads and execute the defaults kernel image as specified in grub configuration file /boot/grub/grub.conf


KERNEL:- Mount the root file system . Kernel execute the /sbin/init .INIT is the first prog executed in Linux kernel .Kernel contains device driver compiled inside which help to access the hardware.

INIT:- INIT decide the run levels. These run levels are mention in /etc/inittab file
There are 7 run levels in linux

0  -->  Halt
1  -->  Single user mode
2  -->  Multiuser mode without NFS
3  -->  Full multiuser mode
4  -->  Unused
5  -->  Graphical
6  -->  Reboot

RUN LEVEL PROGRAMS:- When the Linux system booting up various services getting started.
for example   httpd ---- OK
                     named----OK
                     vsftpd -----OK
Depending on your default init level setting , the system will execute the programs from one of the following directory.


Run level 0 – /etc/rc.d/rc0.d/
Run level 1 – /etc/rc.d/rc1.d/
Run level 2 – /etc/rc.d/rc2.d/
Run level 3 – /etc/rc.d/rc3.d/
Run level 4 – /etc/rc.d/rc4.d/
Run level 5 – /etc/rc.d/rc5.d/
Run level 6 – /etc/rc.d/rc6.d/

Difference Between Soft Link & Hard Link in Linux

Soft Link :- soft links are the shortcut to the original file .If u delete the original file the shortcuts will fail.Soft links have different inode number than source file

Command to create  soft link:-  ln -s  /root/file1  /root/Desktop/file2 


Hard Link :-  Hard Links are mirror copy of  source file .If we changes in file 1 it appears in file 2. Hard links have same inode number as of source file

Command to create  soft link:-  ln   /root/file1  /root/Desktop/file2 

RAID (Redundant Array of Independent Disks) in Linux with Practical

RAID (Redundant Array of Independent Drives (or Disks)
A. A Redundant Array of Independent Drives (or Disks), also known as Redundant Array of Inexpensive Drives (or Disks) (RAID) is an term for data storage schemes that divide and/or replicate data among multiple hard drives. RAID can be designed to provide increased data reliability or increased I/O performance, though one goal may compromise the other.

Mainly there are 3 types of RAID :

RAID  0
RAID  1
RAID  5



RAID 0 (Striping)
This level is achieved by grouping 2 or more hard disks into a single unit with the total size equaling that of all disks used. Practical example: 3 disks, each 80GB in size can be used in a 240GB RAID 0 configuration.

RAID 0 works by breaking data into fragments and writing to all disk simultaneously. This significantly improves the read and write performance. On the other hand, no single disk contains the entire information for any bit of data committed. This means that if one of the disks fails, the entire RAID is rendered inoperable, with unrecoverable loss of data.

RAID 0 is suitable for non-critical operations that require good performance, like the system partition or the /tmp partition where lots of temporary data is constantly written. It is not suitable for data storage.



RAID 1 (Mirroring)

This level is achieved by grouping 2 or more hard disks into a single unit with the total size equaling that of the smallest of disks used. This is because RAID 1 keeps every bit of data replicated on each of its devices in the exactly same fashion, create identical clones. Hence the name, mirroring. Practical example: 2 disks, each 80GB in size can be used in a 80GB RAID 1 configuration. On a side note, in mathematical terms, RAID 1 is an AND function, whereas RAID 0 is an OR.

Because of its configuration, RAID 1 reduced write performance, as every chunk of data has to be written n times, on each of the paired devices. The read performance is identical to single disks. Redundancy is improved, as the normal operation of the system can be maintained as long as any one disk is functional. RAID 1 is suitable for data storage, especially with non-intensive I/O tasks.






RAID 5

This is a more complex solution, with a minimum of three devices used. Two or more devices are configured in a RAID 0 setup, while the third (or last) device is a parity device. If one of the RAID 0 devices malfunctions, the array will continue operating, using the parity device as a backup. The failure will be transparent to the user, save for the reduced performance.

RAID 5 improves the write performance, as well as redundancy and is useful in mission-critical scenarios, where both good throughput and data integrity are important. RAID 5 does induce a slight CPU penalty due to parity calculations.





PRACTILE  OF RAID USING RAID 1
First create 3 partitions sda10,sda11,sda12 of raid type
[root@www ~]# mdadm -C /dev/md0 -l 1 -n 2 /dev/md10 /dev/md11
C-- create
l-- level
n-- numder of device
[root@www ~]# mdadm --detail /dev/md0
[root@www ~]# mdadm --detail /dev/md0
/dev/md0:
        Version : 00.90.03
  Creation Time : Sun Jan 13 22:11:49 2013
     Raid Level : raid1
     Array Size : 104320 (101.89 MiB 106.82 MB)
  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 2
  Total Devices : 2
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sun Jan 13 22:24:07 2013
          State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           UUID : 63a6d6db:ced50964:3fb69cfe:6b30dd55
         Events : 0.6


    Number   Major   Minor   RaidDevice State
       0       8       10        0      active sync   /dev/sda10
       1       8       12        1      active sync   /dev/sda11

      

[root@www ~]# mkfs.ext3 /dev/md0
[root@www ~]# mkdir /raid
[root@www ~]# mount /dev/md0 /raid
now add a spare device
[root@www ~]# mdadm --add /dev/md0 /dev/md12
/dev/md0:
        Version : 00.90.03
  Creation Time : Sun Jan 13 22:11:49 2013
     Raid Level : raid1
     Array Size : 104320 (101.89 MiB 106.82 MB)
  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 2
  Total Devices : 3
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sun Jan 13 22:24:07 2013
          State : clean
 Active Devices : 2
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 1

           UUID : 63a6d6db:ced50964:3fb69cfe:6b30dd55
         Events : 0.6

    Number   Major   Minor   RaidDevice State
       0       8       10        0      active sync   /dev/sda10
       1       8       11        1      active sync   /dev/sda11
       2       8       12        2      spare sync   /dev/sda12
[root@www ~]# cp -rvf /etc /raid
[root@www ~]# mdadm --fail /dev/md0 /dev/sda11
[root@www ~]#  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 2
  Total Devices : 3
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sun Jan 13 22:23:54 2013
          State : clean, degraded, recovering
 Active Devices : 1
Working Devices : 2
 Failed Devices : 1
  Spare Devices : 1

 Rebuild Status : 50% complete

           UUID : 63a6d6db:ced50964:3fb69cfe:6b30dd55
         Events : 0.4

    Number   Major   Minor   RaidDevice State
       0       8       10        0      active sync   /dev/sda10
       2       8       12        1      spare rebuilding   /dev/sda12

       3       8       11        -      faulty spare   /dev/sda11

[root@www ~]# mdadm --detail /dev/md0
/dev/md0:
        Version : 00.90.03
  Creation Time : Sun Jan 13 22:11:49 2013
     Raid Level : raid1
     Array Size : 104320 (101.89 MiB 106.82 MB)
  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 2
  Total Devices : 3
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sun Jan 13 22:23:54 2013
          State : clean, degraded, recovering
 Active Devices : 1
Working Devices : 2
 Failed Devices : 1
  Spare Devices : 1

 Rebuild Status : 94% complete

           UUID : 63a6d6db:ced50964:3fb69cfe:6b30dd55
         Events : 0.4

    Number   Major   Minor   RaidDevice State
       0       8       10        0      active sync   /dev/sda10
       2       8       12        1      spare rebuilding   /dev/sda12

       3       8       11        -      faulty spare   /dev/sda11








Monday, 30 December 2013

Scripts to Check Policies in Linux Such as Grub BootLoader Password, Prompting Password in Single user mode

(1) CTR ALT DEL SHUTDOWN POLICY


#!/bin/bash
echo "This script Check CTR ALT DEL POLICY Working or NOT "
f="/etc/inittab"

if [ -e $f ]
then
cd /etc

echo " U R in `pwd` "
s=`cat inittab | grep "^ca::ctrlaltdel:/sbin/shutdown -t3 -r now"`

if [ ! -n "$s" ]
then
echo " POLICY not Working "

else
echo "POLICY Working Properly "

fi
fi


 output
[root@CLIENT ~]# ./CtrAltDel.sh
This script Check CTR ALT DEL POLICY Working or NOT
 U R in /etc
POLICY Working Properly






(2) PASSWORD PROTECTING GRUB


#!/bin/bash
echo "This script check grub bootloader is password protected or not"
f="/boot/grub/grub.conf"

if [ -e $f ]
then
cd /boot/grub

echo " U R in `pwd` "
s=`cat grub.conf | grep "^password --md5"`

echo " PASSWORD OF GRUB IS  $s "
if [ ! -n "$s" ]

then
echo "Not Verified"

else
echo "Password  Implemented "

fi
fi


output

[root@CLIENT ~]# ./grub.sh
This script check grub bootloader is password protected or not
 U R in /boot/grub
 PASSWORD OF GRUB IS  password --md5 $1$cnO6W1$Oc3iMBjHIVVukIGkXkeFD0
Password  Implemented


(3) PROMPTING FOR PASSWORD IN SINGLE USER MODE


#!/bin/bash
echo "This script Check Prompting Password in Singl Usrmod POLICY Working or NOT "
f="/etc/inittab"

if [ -e $f ]
then
cd /etc

echo " U R in `pwd` "
s=`cat inittab | grep "^~~:S:wait:/sbin/sulogin"`

if [ ! -n "$s" ]
then
echo " POLICY not Working "

else
echo "POLICY Working Properly "

fi
fi


output
[root@CLIENT ~]# ./singleuser.sh
This script Check Prompting Password in Singl Usrmod POLICY Working or NOT
 U R in /etc
 POLICY not Working



Scripts to Check Linux Logs Message such as Mail Events,Authentication Message Logs

(1)  Display General Message Logs

#!/bin/bash
echo  "This script shows the General Message Logs "
f= "/var/log/messages"

if [  -e $f  ]
then

cd /var/log
echo  " Welcome to the LOG directory `pwd`  "

head -5 messages  > sample1
echo "Demo of the logs message "

cat sample1
echo "task complete "

fi

ouptput
This script shows the General Message Logs
 Welcome to the LOG directory /var/log 
Demo of the logs message
Dec 29 03:45:20 CLIENT syslogd 1.4.1: restart.
Dec 29 03:45:20 CLIENT nmbd[2423]:   Got SIGHUP dumping debug info.
Dec 29 03:45:20 CLIENT nmbd[2423]: [2013/12/29 03:45:20, 0] nmbd/nmbd_workgroupdb.c:dump_workgroups(282)
Dec 29 03:45:20 CLIENT nmbd[2423]:   dump_workgroups()
Dec 29 03:45:20 CLIENT nmbd[2423]:    dump workgroup on subnet       10.0.2.15: netmask=  255.255.255.0:
task complete


(2)  Display Authentication Message Logs


#!/bin/bash
echo "This script shows the Authentication Message Logs "
f="/var/log/secure"

if [ -e $f  ]
then

cd /var/log
echo " Welcome to the LOG directory `pwd`  "

head -5 secure  > sample2
echo "Demo of the logs message "

cat sample2
echo "task complete "
fi

output
[root@CLIENT ~]# ./secure.sh
This script shows the Authentication Message Logs
 Welcome to the LOG directory /var/log 
Demo of the logs message
Dec 30 04:18:34 CLIENT sshd[2312]: Server listening on :: port 22.
Dec 30 04:18:34 CLIENT sshd[2312]: Server listening on 0.0.0.0 port 22.
Dec 30 04:20:27 CLIENT gdm[2593]: pam_unix(gdm:session): session opened for user root by (uid=0)
Dec 30 05:21:47 CLIENT su: pam_unix(su-l:session): session opened for user alice by root(uid=0)
Dec 30 05:22:20 CLIENT su: pam_unix(su-l:session): session closed for user alice
task complete


(3) Display Mail Event Logs

#!/bin/bash
echo "This script shows the  Mail Events Logs "
f="/var/log/maillog"
if [ -e $f  ]
then
cd /var/log
echo " Welcome to the LOG directory `pwd`  "
head -5 maillog  > sample3
echo "Demo of the logs message "
cat sample3
echo "task complete "
 
output
root@CLIENT ~]# ./maillog.sh
This script shows the  Mail Events Logs
 Welcome to the LOG directory /var/log 
Demo of the logs message
Dec 29 03:45:35 CLIENT sendmail[3685]: rBSMFZHo003685: from=root, size=228, class=0, nrcpts=1, msgid=<201312282215.rBSMFZHo003685@CLIENT>, relay=root@localhost
Dec 29 03:45:35 CLIENT sendmail[3686]: rBSMFZTx003686: from=<root@CLIENT>, size=457, class=0, nrcpts=1, msgid=<201312282215.rBSMFZHo003685@CLIENT>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Dec 29 03:45:35 CLIENT sendmail[3685]: rBSMFZHo003685: to=root, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30228, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (rBSMFZTx003686 Message accepted for delivery)
Dec 29 03:45:35 CLIENT sendmail[3687]: rBSMFZTx003686: to=<root@CLIENT>, ctladdr=<root@CLIENT> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30647, dsn=2.0.0, stat=Sent
Dec 29 04:02:06 CLIENT sendmail[3833]: rBSMW3Gb003833: from=root, size=3843, class=0, nrcpts=1,
task complete