Saturday, 29 June 2013

How many users are logging in system

Display total connect time of users

Ac command will display the statistics about the user’s connect time.

Connect time for the current logged in user

With the option –d, it will break down the output for the individual days. In this example, I’ve been logged in to the system for more than 6 hours today. On Dec 1st, I was logged in for about 1 hour.
 
# ac –d

Dec  1  total        1.08
Dec  2  total        0.99
Dec  3  total        3.39
Dec  4  total        4.50
Today   total        6.10

Connect time for all the users

To display connect time for all the users use –p as shown below. Please note that this indicates the cumulative connect time for the individual users.
 
# ac -p 
        harry                               3.64
        madison                             0.06
        sanjay                              88.17
        nitesh                              105.92
        rakesh                              111.42
        total 309.21

Connect time for a specific user

To get a connect time report for a specific user, execute the following:
# ac -d nitesh

Jul  2  total       12.85
Aug 25  total        5.05
Sep  3  total        1.03
Sep  4  total        5.37
Dec 24  total        8.15
Dec 29  total        1.42
Today   total        2.95

Basic Directory in Linux

DirectoryDescription
/This is the root directory which should contain only the directories needed at the top level of the file structure.
/binThis is where the executable files are located. They are available to all user.
/devThese are device drivers.
/etcSupervisor directory commands, configuration files, disk configuration files, valid user lists, groups, ethernet, hosts, where to send critical messages.
/libContains shared library files and sometimes other kernel-related files.
/bootContains files for booting the system.
/homeContains the home directory for users and other accounts.
/mntUsed to mount other temporary file systems, such as cdrom and floppy for the CD-ROM drive and floppy diskette drive, respectively
/procContains all processes marked as a file by process number or other information that is dynamic to the system.
/tmpHolds temporary files used between system boots
/usrUsed for miscellaneous purposes, or can be used by many users. Includes administrative commands, shared files, library files, and others
/varTypically contains variable-length files such as log and print files and any other type of file that may contain a variable amount of data
/sbinContains binary (executable) files, usually for system administration. For example fdisk and ifconfig utlities.
/kernelContains kernel files

Linux Basic Commands

CommandDescription
cat filenameDisplays a filename.
cd dirnameMoves you to the directory identified.
cp file1 file2Copies one file/directory to specified location.
file filenameIdentifies the file type (binary, text, etc).
find filename dirFinds a file/directory.
head filenameShows the beginning of a file.
less filenameBrowses through a file from end or beginning.
ls dirnameShows the contents of the directory specified.
mkdir dirnameCreates the specified directory.
more filenameBrowses through a file from beginning to end.
mv file1 file2Moves the location of or renames a file/directory.
pwdShows the current directory the user is in.
rm filenameRemoves a file.
rmdir dirnameRemoves a directory.
tail filenameShows the end of a file.
touch filenameCreates a blank file or modifies an existing file.s attributes.
whereis filenameShows the location of a file.
which filenameShows the location of a file if it is in your PATH.       

Grub recovering in linux

GRUB recover using rescue mode


Linux recover boot loader or filesystem corruption using Rescue Mode

Here are the steps to recover corrupted linux filesystem (with or without LVM) or boot loader:

1) Boot system using Linux OS (should be the same version which is installed or needs to recover) CD/USB

2) When prompted, type ''linux rescue''

3) This will ask You for some questions like need to enable network or not and mount system or not

In case of installation/repair or grub boot loader

4) Try to mount file system and use following command to install grub

#grub-install /dev/sda 

(should be a first partition where MBR resides)

run exit to reboot into new installed and recovered grub boot loader

In case of filesystem repair (skip step 4)

5) Do not mount partition

6) run following command over shell

#e2fsck -p /dev/sda{1,2,3....}     Partition which required to recover
#fsck -p /dev/sda{1,2,3}             Partition which required to recover

If all goes well reboot your system :)

In case of LVM filesystem repair (skip step 4 & 6)


7) In case of rescue mode, LVMs are not in active state we require to activate them manually

8) To check and activate LVMs run following commands:

#lvm pvscan             (Scan for PVs available and show them)
#lvm vgscan             (Scan for VGs available and show them)
#lvm vgchange VGName -a y 

(This will activate all VGs LVM volumes)

#lvm lvscan               (Scan LVMs available)

9) Now use Step 6 (change partition with LVMs partition number which is shown by ''lvm lvscan'')

Thats it!!! Plz mail me if u have any problem to perform any repair process.
Piyush.kumar100@gmail.com
piyushgupta@tetrain.com

Diffrence between ext2, ext3 and ext4

Differences between Ext2,Ext3 and Ext4 file systems

it is always a question in our mind what are the basic difference between ext2, ext3 and ext4 filesystems.
So here is the answer for you,

(Note:-) ext2, ext3 and ext4 are all filesystems created for Linux. This article explains the following:

    * High level difference between these filesystems.
    * How to create these filesystems.
    * How to convert from one filesystem type to another.


Ext2

    * Ext2 stands for second extended file system.
    * It was introduced in 1993. Developed by Rémy Card.
    * This was developed to overcome the limitation of the original ext file system.
    * Ext2 does not have journaling feature.
    * On flash drives, usb drives, ext2 is recommended, as it doesn’t need to do the over head of journaling.
    * Maximum individual file size can be from 16 GB to 2 TB
    * Overall ext2 file system size can be from 2 TB to 32 TB


Ext3

    * Ext3 stands for third extended file system.
    * It was introduced in 2001. Developed by Stephen Tweedie.
    * Starting from Linux Kernel 2.4.15 ext3 was available.
    * The main benefit of ext3 is that it allows journaling.
    * Journaling has a dedicated area in the file system, where all the changes are tracked. When the system crashes, the possibility of file system corruption is less because of journaling.
    * Maximum individual file size can be from 16 GB to 2 TB
    * Overall ext3 file system size can be from 2 TB to 32 TB
    * There are three types of journaling available in ext3 file system.
          o Journal – Metadata and content are saved in the journal.
          o Ordered – Only metadata is saved in the journal. Metadata are journaled only after writing the content to disk. This is the default.
          o Writeback – Only metadata is saved in the journal. Metadata might be journaled either before or after the content is written to the disk.
    * You can convert a ext2 file system to ext3 file system directly (without backup/restore).

Ext4

    * Ext4 stands for fourth extended file system.
    * It was introduced in 2008.
    * Starting from Linux Kernel 2.6.19 ext4 was available.
    * Supports huge individual file size and overall file system size.
    * Maximum individual file size can be from 16 GB to 16 TB
    * Overall maximum ext4 file system size is 1 EB (exabyte). 1 EB = 1024 PB (petabyte). 1 PB = 1024 TB (terabyte).
    * Directory can contain a maximum of 64,000 subdirectories (as opposed to 32,000 in ext3)
    * You can also mount an existing ext3 fs as ext4 fs (without having to upgrade it).
    * Several other new features are introduced in ext4: multiblock allocation, delayed allocation, journal checksum. fast fsck, etc. All you need to know is that these new features have improved the performance and reliability of the filesystem when compared to ext3.
    * In ext4, you also have the option of turning the journaling feature “off”.

How to create ext2, ext3, and ext4 partition.

Once you’ve partitioned your hard disk using fdisk command, use mke2fs to create either ext2, ext3, or ext4 file system.

Create an ext2 file system:
mke2fs /dev/sda1

Create an ext3 file system:
mkfs.ext3 /dev/sda1
(or)
mke2fs –j /dev/sda1

Create an ext4 file system:
mkfs.ext4 /dev/sda1
(or)
mke2fs -t ext4 /dev/sd

How to convert EXT2 partition to EXT3 in linux

Converting ext2 to ext3.

For example, if you are upgrading /dev/sda2 that is mounted as /home, from ext2 to ext3, do the following.
umount /dev/sda2
tune2fs -j /dev/sda2
mount /dev/sda2 /home

Note: You really don’t need to umount and mount it, as ext2 to ext3 conversion can happen on a live file system. But, I feel better doing the conversion offline.

What is Journaling...?

Journaling is only used when writing to a disk and it acts as a sort of punch clock for all writes. This fixes the problem of disk corruption when things are written to the hard drive and then the computer crashes or power is lost. Without a journal the operating system would have no way to know if the file was completely written to disk.
With a journal the file is first written to the journal, punch-in, and then the journal writes the file to disk when ready. Once it has successfully written to the disk, it is removed from the journal, punch-out, and the operation is complete. If power is lost while being written to disk the file system can check the journal for all operations that have not yet been completed and remember where it left off.
The biggest downside to journaling is that it sacrifices some performance in exchange for stability. There is more overhead to write a file to disk but file systems get around this overhead by not writing the full file to the journal. Instead only the file metadata, inode, or disk location is recorded before actually being written to disk.

Done.

IPTABLES CONFIGURATION

IP-TABLES Configuration

# iptables -I INPUT -p tcp -s 192.168.0.6 -m time --weekdays Tu  --dport 22 -j REJECT 

(Here a/c to this rule 22 port is block on every tuesday for this source)

# iptables -I INPUT -p tcp -s 192.168.0.6 -m time --weekdays Tu  -m time --timestart 17:00 --timestop 17:30 --dport 22 -j REJECT 


(Here a/c to this rule 22 port is block for source on tuesday only between
5:00 pm to 5:30 pm)# iptables -I INPUT -p tcp -s 192.168.0.6  -m time --datestart 2012-06-05 --datestop 2012-06-06 --dport 22 -j REJECT

(Here a/c to this rule 22 port block for source from 05-06-2012 to 06-06-2012)

# iptables -I INPUT -p tcp -s 192.168.0.6  -m time --datestart 2012-06-05T17:20 --datestop 2012-06-06T17:45 --dport 22 -j REJECT 

(Here a/c to this rule 22 port is block for source from 05-06-2012 to 06-06-2012 between 5:20 pm to 5:45 pm)

Allow Limited connection of ssh

If you want to allow limited connetion for specific service like ssh->
You can adjust the numbers yourself to limit connections further, so the following example will drop incoming connections which make more than 2 connection attempts upon port22 within ten minutes:


[root@piyush~]#iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent  --set


[root@piyush~]#iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent  --update --seconds 600 --hitcount 2 -j DROP

Adobe Flash Player installation on Linux

Install adobe flash player in linux

How can we install adobe flash player in linux-RHEL6


Download adobe rpm 


http://get.adobe.com/flashplayer/completion/?installer=Flash_Player_11.2_for_other_Linux_(.tar.gz)_64-bit

[ root @ piyush ~ ] # cd Download
[ root @ piyush ~ ] # ls

install_flash_player_11_linux.x86_64.tar.gz

[ root @ piyush ~ ] #gunzip install_flash_player_11_linux.x86_64.tar.gz

[ root @ piyush ~ ] # ls

[ root @ piyush ~ ]#tar -xvf  install_flash_player_11_linux.x86_64.tar

[ root @ piyush ~ ] # ls

readme.txt     usr   libflashplayer.so 

[ root @ piyush ~ ] # cp    libflashplayer.so  /usr/lib64/mozilla/plugins

[ root @  piyush~ ] # cp    -rvf    usr/*     /usr/

[ root @ piyush ~ ] # exit


Now Open Mozila and try to open 

www.youtube.com

Now u can see all videos.

**********************   enjoy ***************************

Mount and Access NTFS Partition in Linux ( RHEL, Cent-os )

Mount and Access NTFS Partition in RHEL

How to enable NTFS support on CentOS Linux version 5 or 6? 
How do I mount ntfs partition under RHEL 5 or 6?

First, you need to install EPEL repo as described here. The following command will turn in EPEL repo on RHEL / CentOS version 6.x:
# cd /tmp
#wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm
#rpm -ivh epel-release-6-5.noarch.rpm

NTFS-3G


NTFS-3G is a stable, open source, GPL licensed, POSIX, read/write NTFS driver for Linux. It provides safe handling of the Windows XP, Windows Server 2003, Windows 2000, Windows Vista, Windows Server 2008 and Windows 7 NTFS file systems.

How Do I Install NTFS-3G?

 # yum install ntfs-3g*   -y

How Do I Find Out NTFS Partition Name?

Simply type the following command:

# fdisk -l /dev/sda 

sample ouput: 
 
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf0000000
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      102400    7  HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2              14       60802   488281089    5  Extended
/dev/sda5              14       59767   479970304   83  Linux
/dev/sda6           59767       60802     8309760   82  Linux swap / Solaris

How Do I Mount /dev/sda1 NTFS Partition at /mnt/ntfs?

First, load the fuse driver, enter:

# modprobe fuse

Create a mount point, enter:

# mkdir /mnt/ntfs

To mount the ntfs partition, enter:

# mount -t ntfs-3g /dev/sda1 /mnt/ntfs

You can use regular Unix commands to copy or access the files:

# df -h
# mount
# cd /mnt/ntfs
# cp foo /tmp

How Do I Unmount NTFS Partition?

Type the following command:

# umount /mnt/ntfs

APACHE SERVER CONFIGURATION STEP BY STEP

Install Apache Webserver in CentOS 6.3 & RHEL

In this how-to tutorial I’ll show you how to install Apache and host a sample website using Apache.

Scenario

In this how-to tutorial, my test scenario setup are as follows

Webserver Details:

Operating System  :  CentOS 6.3 32bit server
Hostname          :  web.example.com
IP Address        :  192.168.1.250

Client Details:

Operating System  :  CentOS 6.3 32bit Desktop
Hostname          :  client.example.com
IP Address        :  192.168.1.251
 
I already have a DNS server in my setup and i had properly configured the DNS server with both server and client details.

Server side configuration

Prerequisites:

1. Set the hostname of web server

[root@web ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=web.example.com

2. Add the webserver hostname in ‘etc/hosts’ file

[root@web ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.250   web.example.com
192.168.1.250   www.example.com

3. Install Apache

Check and remove any previously installed packages
 
[root@web ~]# rpm -qa | grep httpd
or
 
[root@web ~]# yum list installed | grep httpd
 
Now install the ‘httpd’ package
 
[root@web ~]# yum install httpd* -y

4. Configure Apache

[root@web ~]# vi /etc/httpd/conf/httpd.conf 
## line no 262 - Set the server admin mail id which is used to receive mail generated by apache ##
ServerAdmin root@ostechnix.com
## line no 276 - Set the website name ##
ServerName www.ostechnix.com:80
## line no 292 - Set the web pages folder ##
DocumentRoot "/var/www/html"
## line no 402 - Sent the index or home page of the website ##
DirectoryIndex ostechnix.html

5. Create a sample index or home page

Create the index or home page html file in the ‘/var/www/html/’ directory
 
[root@web ~]# vi /var/www/html/example.html 
<html>
<body bgcolor=blue>
        <h1> Welcome to EXAMPLE Website </h1> 
</body>
</html>

6. Allow webserver through firewall

[root@web ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
 
Restart iptables to save changes
 
[root@web ~]# service iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]

7. Start Apache web server

[root@web ~]# service httpd start
Starting httpd:                                            [  OK  ]
[root@web ~]# chkconfig httpd on

Client side Configuration

1. Add the webserver and client ip address and hostname in the ‘/etc/hosts’ file

[root@client ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.251   client.ostechnix.com
192.168.1.250   www.ostechnix.com

2. Check Apache webserver

Open the firefox in client and type http://www.example.com in the address bar. The index page of example website will open now.

Global Yum Configuration




Global Yum configuration with  RPMForge repository in CentOS 6.3 / RHEL 6.3

RPMForge is one of the best known repository in Linux world. It is used to install third party softwares in RPM based distributions. It contains more than 5000 packages.

Install RPMForge repository in CentOS

The steps provided here are tested in CentOS 6.3 32 bit edition, though it will work on RHEL 6.x/Scientific Linux 6.x too.
First check your operating system version. Then download the relevent repository. To check OS version use “uname -a” command.
 
[root@mainserver ~]# uname -a
Linux mainserver.example.com 2.6.32-279.el6.i686 #1 SMP Fri Jun 22 10:59:55 UTC 2012 i686 i686 i386 GNU/Linux
To install Rpmforge repository for 32 bit use the following commands.
 
[root@mainserver ~]# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
--2013-01-31 15:40:06--  http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
Resolving packages.sw.be... 78.46.17.228
Connecting to packages.sw.be|78.46.17.228|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm [following]
--2013-01-31 15:40:07--  http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
Resolving pkgs.repoforge.org... 78.46.17.228
Connecting to pkgs.repoforge.org|78.46.17.228|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://rpmforge.sw.be/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm [following]
--2013-01-31 15:40:09--  http://rpmforge.sw.be/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
Resolving rpmforge.sw.be... 78.46.17.228
Connecting to rpmforge.sw.be|78.46.17.228|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://tree.repoforge.org/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm [following]
--2013-01-31 15:40:10--  http://tree.repoforge.org/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
Resolving tree.repoforge.org... 78.46.17.228
Connecting to tree.repoforge.org|78.46.17.228|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm [following]
--2013-01-31 15:40:12--  http://apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
Resolving apt.sw.be... 193.1.193.67
Connecting to apt.sw.be|193.1.193.67|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12732 (12K) [application/x-redhat-package-manager]
Saving to: `rpmforge-release-0.5.2-2.el6.rf.i686.rpm'
100%[======================================>] 12,732      9.60K/s   in 1.3s    
2013-01-31 15:40:15 (9.60 KB/s) - `rpmforge-release-0.5.2-2.el6.rf.i686.rpm' saved [12732/12732]
For 64 bit use the following command.
 
[root@mainserver ~]# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el4.rf.x86_64.rpm
[root@mainserver ~]# rpm -ivh rpmforge-release-0.5.2-2.el4.rf.x86_64.rpm
Then import the key and install RPMForge.
 
[root@mainserver ~]# rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
[root@mainserver ~]#  rpm -K rpmforge-release-0.5.2-2.el6.rf.*.rpm
rpmforge-release-0.5.2-2.el6.rf.i686.rpm: (sha1) dsa sha1 md5 gpg OK
[root@mainserver ~]# rpm -ivh rpmforge-release-0.5.2-2.el6.rf.i686.rpm 
Preparing...                ########################################### [100%]
   1:rpmforge-release       ########################################### [100%]

Test RPMForge Repository

Now let us install a sample package to verify whether Rpmforge repository is working or not.
 
[root@mainserver ~]# yum install htop
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror-fpt-telecom.fpt.net
 * extras: mirror-fpt-telecom.fpt.net
 * rpmforge: mirror-fpt-telecom.fpt.net
 * updates: ftp.iitm.ac.in
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package htop.i686 0:1.0.2-1.el6.rf will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package       Arch          Version                    Repository         Size
================================================================================
Installing:
 htop          i686          1.0.2-1.el6.rf             rpmforge           78 k
Transaction Summary
================================================================================
Install       1 Package(s)
Total download size: 78 k
Installed size: 186 k
Is this ok [y/N]: y
Downloading Packages:
htop-1.0.2-1.el6.rf.i686.rpm                             |  78 kB     00:01     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : htop-1.0.2-1.el6.rf.i686                                     1/1 
  Verifying  : htop-1.0.2-1.el6.rf.i686                                     1/1 
Installed:
  htop.i686 0:1.0.2-1.el6.rf                                                    
Complete!

Disable RPMForge Repository

To disable RPMForge repository navigate to /etc/yum.repos.d/, open the rpmforge.repo file and set enabled=0.
 
### Name: RPMforge RPM Repository for RHEL 6 - dag
### URL: http://rpmforge.net/
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/rpmforge
mirrorlist = http://apt.sw.be/redhat/el6/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
Thats it. Have a good day.

NFS Server configuration Steps



NFS Server configuration  Step by step on RHEL  & Cent-os


In this tutorial let us see how to install and configure NFS server and how to share files between NFS server and clients. Though i have tested these steps in CentOS 6.3 32 bit edition, it will work on RHEL/Scientific Linux 6.x too.

Scenario

NFS Server Operating System : CentOS 6.3 32 bit (Minimal server install)
NFS Client Operating System  : CentOS 6.3 32 bit (Minimal Desktop install)
NFS Server IP Address              : 192.168.1.200/24
NFS Client IP Address               : 192.168.1.29/24

1. Install NFS in Server

[root@server ~]# yum install nfs* -y

2. Start NFS service

[root@server ~]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Stopping RPC idmapd:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
[root@server ~]# chkconfig nfs on

3. Install NFS in Client

[root@vpn client]# yum install nfs* -y

4. Start NFS service in client

[root@vpn client]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Stopping RPC idmapd:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
[root@vpn client]# chkconfig nfs on

5. Create shared directories in server

Let us create a shared directory called ‘/home/piyush’ in server and let the client users to read and write files in the ‘home/piyush’ directory.
 
[root@server ~]# mkdir /home/piyush
[root@server ~]# chmod 755 /home/piyush/

6. Export shared directory on server

Open /etc/exports file and add the entry as shown below
 
[root@server ~]# vi /etc/exports
/home/piyush 192.168.1.0/24(rw,sync,no_root_squash,no_all_squash)
where,
 /home/piyush  - shared directory
192.168.1.0/24      - IP address range of clients to access the shared folder
rw                           – Make the shared folder to be writable
sync                        - Synchronize shared directory whenever create new files/folders
no_root_squash   – Enable root privilege  (Users can read, write and delete the files in the shared directory)
no_all_squash      - Enable user’s authority 
Now restart the NFS service.
 
[root@server ~]# /etc/init.d/nfs restart
Shutting down NFS daemon:                                  [  OK  ]
Shutting down NFS mountd:                                  [  OK  ]
Shutting down NFS services:                                [  OK  ]
Starting NFS services:                                     [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Stopping RPC idmapd:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]        -  

7. Mount shared directories in client

Create a mount point to mount the shared directories of server.
To do that create a directory called ‘/nfs/shared’ (You can create your own mount point)
 
[root@vpn client]# mkdir -p /nfs/shared
Now mount the shared directories from server as shown below
 
[root@vpn client]# mount -t nfs 192.168.1.200:/home/piyush/ /nfs/shared/
This will take a while and shows a connection timed out error for me. Well, don’t panic, firwall might be restricting  the clients to mount shares from server. Simply stop the iptables to rectify the problem or you can allow the NFS service ports through iptables.
To do that open the /etc/sysconfig/nfs file and uncomment the lines which are marked in bold.
 
[root@server ~]# vi /etc/sysconfig/nfs
#
# Define which protocol versions mountd 
# will advertise. The values are "no" or "yes"
# with yes being the default
#MOUNTD_NFS_V2="no"
#MOUNTD_NFS_V3="no"
#
#
# Path to remote quota server. See rquotad(8)
#RQUOTAD="/usr/sbin/rpc.rquotad"
# Port rquotad should listen on.
RQUOTAD_PORT=875
# Optinal options passed to rquotad
#RPCRQUOTADOPTS=""
#
#
# Optional arguments passed to in-kernel lockd
#LOCKDARG=
# TCP port rpc.lockd should listen on.
LOCKD_TCPPORT=32803
# UDP port rpc.lockd should listen on.
LOCKD_UDPPORT=32769
#
#
# Optional arguments passed to rpc.nfsd. See rpc.nfsd(8)
# Turn off v2 and v3 protocol support
#RPCNFSDARGS="-N 2 -N 3"
# Turn off v4 protocol support
#RPCNFSDARGS="-N 4"
# Number of nfs server processes to be started.
# The default is 8. 
#RPCNFSDCOUNT=8
# Stop the nfsd module from being pre-loaded
#NFSD_MODULE="noload"
# Set V4 grace period in seconds
#NFSD_V4_GRACE=90
#
#
#
# Optional arguments passed to rpc.mountd. See rpc.mountd(8)
#RPCMOUNTDOPTS=""
# Port rpc.mountd should listen on.
MOUNTD_PORT=892
#
#
# Optional arguments passed to rpc.statd. See rpc.statd(8)
#STATDARG=""
# Port rpc.statd should listen on.
STATD_PORT=662
# Outgoing port statd should used. The default is port
# is random
STATD_OUTGOING_PORT=2020
# Specify callout program 
#STATD_HA_CALLOUT="/usr/local/bin/foo"
#
#
# Optional arguments passed to rpc.idmapd. See rpc.idmapd(8)
#RPCIDMAPDARGS=""
#
# Set to turn on Secure NFS mounts. 
#SECURE_NFS="yes"
# Optional arguments passed to rpc.gssd. See rpc.gssd(8)
#RPCGSSDARGS=""
# Optional arguments passed to rpc.svcgssd. See rpc.svcgssd(8)
#RPCSVCGSSDARGS=""
#
# To enable RDMA support on the server by setting this to
# the port the server should listen on
#RDMA_PORT=20049 
Now restart the NFS service 
 
[root@server ~]# /etc/init.d/nfs restart
Shutting down NFS daemon:                                  [  OK  ]
Shutting down NFS mountd:                                  [  OK  ]
Shutting down NFS services:                                [  OK  ]
Starting NFS services:                                     [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Stopping RPC idmapd:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Add the lines shown in bold in  ‘/etc/sysconfig/iptables’ file.
 
[root@server ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
-A INPUT -m state --state NEW -m udp -p udp --dport 2049 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 32769 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 32803 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 892 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 892 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 875 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 875 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 662 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 662 -j ACCEPT:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Now restart the iptables service
 
[root@server ~]# service iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]
Again mount the share from client
 
[root@vpn client]# mount -t nfs 192.168.1.200:/home/piyush/ /nfs/shared/
Finally the NFS share is mounted without any connection timed out error.
To verify whether the shared directory is mounted, enter the mount command in client system.
 
[root@vpn client]# mount
/dev/mapper/vg_vpn-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.1.200:/home/piyush/ on /nfs/shared type nfs (rw,vers=4,addr=192.168.1.200,clientaddr=192.168.1.29)

8. Testing NFS

Now create some files or folders in the ‘/nfs/shared’ directory which we mounted in the previous step.
 
[root@vpn shared]# mkdir test
[root@vpn shared]# touch file1 file2 file3
Now go to the server and change to the ‘/home/piyush’ directory.
 
[root@server ~]# cd /home/ostechnix/
[root@server ostechnix]# ls
file1  file2  file3  test
[root@server ostechnix]# 
Now the files and directories are listed which are created from the client. Also you can share the files from server to client and vice versa.

9. Automount the Shares

If you want to mount the shares automatically instead mounting them manually at every reboot, add the following lines shown in bold in the ‘/etc/fstab’ file of client system.
 
[root@vpn client]# vi /etc/fstab 
#
# /etc/fstab
# Created by anaconda on Wed Feb 27 15:35:14 2013
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_vpn-lv_root /                       ext4    defaults        1 1
UUID=59411b1a-d116-4e52-9382-51ff6e252cfb /boot                   ext4    defaults        1 2
/dev/mapper/vg_vpn-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
192.168.1.200:/home/piyush /nfs/shared nfs rw,sync,hard,intr 0 0

10. Verify the Shares

Reboot your client system and verify whether the share is mounted automatically or not.
 
[root@vpn client]# mount
/dev/mapper/vg_vpn-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.1.200:/home/piyush on /nfs/shared type nfs (rw,sync,hard,intr,vers=4,addr=192.168.1.200,clientaddr=192.168.1.29)nfsd on /proc/fs/nfsd type nfsd (rw)
Thats it. Have a Good day!!

Create Virtual CD on Ubantu


Create Virtual CD And DVD Drives using CDemu in Ubuntu 12.10

CDemu is a Software suite to mount your images such as ISO, IMG, BIN and MDF (CD or DVD Images) in Linux without having to write in physical media. For more information visit the Official Website.To install CDemu, open the 

Terminal by pressing CTRL+ALT+T and add its PPA archive:
Then run the commands to update the Repositories and install CDemu:

To start CDemu, Click Menu -> System Settings -> gCDemu. An icon will be displayed in your task bar.


Click the gCDemu icon to get started. Select Device #00 or Device #01 to
mount your images. Click “Load” and browse the ISO to load:


The ISO will be mounted in your File manager:

To unload your ISO after the usage, simply press the “Unload” in the gCDemu window or eject from the file manager:



Thats it. Enjoy!!!

Local Yum Configuration Steps


Setup Local YUM Server in Cent-os and RHEL


Yellowdog updater, Modified (Yum) is a software package manager that installs, updates and removes packages on RPM-based Linux distributions. Yum makes it easier to maintain groups of machines without having to manually update each one using rpm.
Features:
  • Support for multiple repositories.
  • Simple configuration.
  • Automatic dependency calculation.
  • Fast operation.
  • RPM-consistent behavior.
  • Package group support, including multiple-repository groups.
  • Simple interface.
Yum uses an online repository by default, but you can also configure it to use a local repository of packagesY
Let us install a local yum server using CentOS 6.3. The steps provided here are tested in CentOS 6.3. But it will work fine in RHEL 6.x and Scientific Linux 6.x too.
In this example the hostname of the server is myserver.example.com and IP Address is 192.168.56.101. Login to your system and Mount the contents of your CentOS 6.3 DVD in the /mnt directory or wherever you want. In the Terminal window, type the following command:

# mount /dev/cdrom1 /mnt/ (Here cdrom1 is my local cdrom device)


Install vsftpd package, so that we can use this as a FTP server to share our repository in the client systems.
Change to the directory where you mounted CentOS DVD. In our example we have mounted the CentOS DVD in /mnt directory.

# cd /mnt/Packages
# rpm -ivh vsftpd-2.2.2-11.el6.i686.rpm

Start the FTP Service:

# service vsftpd start


Install createrepo package if it is not installed. This is package is used to create our local repository.

# rpm -ivh createrepo-0.9.8-5.el6.noarch.rpm

Oops!! It shows us the dependency problem. Let us the install missing dependencies first:

# rpm -ivh deltarpm-3.5-0.5.20090913git.el6.i686.rpm

Then install the another one:

# rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.i686.rpm


 Now install the createrepo package:


Create a folder called localyumserver (You can use your own) in /var/ftp/pub directory to save all the packages from the CentOS DVD. Copy all the files in the Packages folder from the DVD to /var/ftp/pub/localyumserver folder:

# mkdir /var/ftp/pub/localyumserver
# cp -ar *.* /var/ftp/pub/localyumserver


It will take a while to copy all the packages in the DVD. Please be patient. After all packages are copied, create a repo file called localyumserver.repo in /etc/yum.repos.d/ directory.

# nano /etc/yum.repos.d/localyumserver.repo

Type the following entries and save the file (CTRL+O to save and CTRL+X to exit):

Where,

[localyumserver] ==> Name of the Local Repository.
comment ==> Information about the Repository.
baseurl ==> Path of the Repository (i.e where we had copied the contents from CentOS DVD)
gpgcheck ==> Authentication of the Repository, which is disabled in our case.
Now it is time to create our repository. Enter the following command in the Terminal:

# createrepo -v /var/ftp/pub/localyumserver
Now the local YUM repository creation process will begin.


Note: Delete or rename all the other repo files except the newly created repo file i.e in our example it is localyumserver.repo
Next update the repository:
  • yum clean all
  • yum update
You’re done now.

Client side configuration:
Create a repo file in your client system as mentioned above in the /etc/yum.repos.d/ directory and remove or rename the existing repositories. Then modify the baseurl as mentioned below:
 
[localyumserver]
comment ="My Local Repository"
baseurl=ftp://myserver.ostechnix.com/pub/localyumserver
gpgcheck=0
enabled=1 
(or)
[localyumserver]
comment ="My Local Repository"
baseurl=ftp://192.168.56.101/pub/localyumserver
gpgcheck=0
enabled=1
Thats it. Start using Yum. Enjoy!!

FTP Server Configuration Steps



Setup FTP Server step by step in CentOS 6 / RHEL5


Install FTP in CentOS 6.3:

This tutorial shows you how to install and configure FTP server in CentOS 6.3. Though the steps provided here are tested in CentOS 6.3, it should work on RHEL 6. In this tutorial my ftp server ip and hostname are 192.168.1.200 and mainserver.example.com respectively. I have already configured a local repository and i am gonna to install FTP from my local repository.
Before proceed, stop the firewall.
 
[root@mainserver ~]# service iptables stop
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
 
[root@mainserver ~]# service ip6tables stop
ip6tables: Flushing firewall rules:                        [  OK  ]
ip6tables: Setting chains to policy ACCEPT: filter         [  OK  ]
ip6tables: Unloading modules:                              [  OK  ]
 
[root@mainserver ~]# chkconfig iptables off
[root@mainserver ~]# chkconfig ip6tables off
[root@mainserver ~]# 
Now let us install FTP service.
 
[root@mainserver ~]# yum install -y vsftpd
[root@mainserver ~]# Start vsftpd service.
[root@mainserver ~]# service vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]
 
[root@mainserver ~]# 
Enable vsftpd in multi-user levels.
 
[root@mainserver ~]# chkconfig vsftpd on
Now edit the /etc/vsftpd/vsftpd.conf file. Uncomment and edit the lines in the vsftpd.conf file which are shown in bold.
 
[root@mainserver ~]# cat /etc/vsftpd/vsftpd.conf 
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
ascii_upload_enable=YES
ascii_download_enable=YES
#
# You may fully customise the login banner string:
ftpd_banner=Welcome to example FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
use_localtime=YES
Now let us restart the vsftpd service and try to connect to ftp server.
 
[root@mainserver ~]# service vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
Connect to the ftp server.
Note: Root is not allowed to connect to ftp server by default for security purpose. So lets us create a new user called piyush.
 
[root@mainserver ~]# useradd piyush
[root@mainserver ~]# passwd piyush
Changing password for user piyush.
New password: 
BAD PASSWORD: it is based on a dictionary word
Retype new password: 
passwd: all authentication tokens updated successfully.
Connet to FTP server using the new user piyush.
 
[root@mainserver ~]# ftp 192.168.1.200
-bash: ftp: command not found
[root@mainserver ~]# 
Oops! ftp package is not installed. So let us install ftp package first.
 
[root@mainserver ~]# yum install -y ftp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ftp.i686 0:0.17-51.1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package       Arch           Version                 Repository           Size
================================================================================
Installing:
 ftp           i686           0.17-51.1.el6           localrepo            55 k
Transaction Summary
================================================================================
Install       1 Package(s)
Total download size: 55 k
Installed size: 91 k
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : ftp-0.17-51.1.el6.i686                                       1/1 
  Verifying  : ftp-0.17-51.1.el6.i686                                       1/1 
Installed:
  ftp.i686 0:0.17-51.1.el6                                                      
Complete!
[root@mainserver ~]# 

Again connect to the FTP server.
 
[root@mainserver ~]# ftp 192.168.1.200
Connected to 192.168.1.200 (192.168.1.200).
220 Welcome to example FTP service.
Name (192.168.1.200:root): ostechnix
331 Please specify the password.
Password:
500 OOPS: cannot change directory:/home/ostechnix
Login failed.
ftp> 
It shows a error that the user cannot change to his $HOME directory. Type exit to return back from the ftp console and allow vsftpd daemon to change users into their $HOME directories. To do that update SELinux configuration using the command below.
 
[root@mainserver ~]# setsebool -P ftp_home_dir on
And finally connect to the FTP server.
 
[root@mainserver ~]# ftp 192.168.1.200
Connected to 192.168.1.200 (192.168.1.200).
220 Welcome to Example FTP service.
Name (192.168.1.200:root): piyush
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/home/piyush"
ftp> 
Its working now. You can use your FTP server.

Postfix, Webmail Server Configuration Steps



Setup Mail Server using Postfix, Dovecot and SquirrelMail in CentOS/RHEL/ step by step

Before install postfix, remove sendmail from the server. Because sendmail is the default MTA in Redhat/CentOS.

 
[root@server ~]# yum remove sendmail

Prerequisites:

  • The mail server should contain a valid MX record in the DNS server.
  • Firewall and SELinux should be disabled.
[root@server ~]# service iptables stop
[root@server ~]# service ip6tables stop
[root@server ~]# chkconfig iptables off
[root@server ~]# chkconfig ip6tables off
[root@server ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
Reboot the server.

Scenario

In this tutorial my test box
Hostname     = server.example.com
IP Address    = 192.168.1.200/24
And my server is configured with proper MX record in DNS server.

Installation

Postfix is installed by default. If it is not installed, use the below command to install postfix.
 
[root@server ~]# yum install postfix

Configuration

Open the postfix config file /etc/postfix/main.cf. Find the below lines and edit them as shown below.
 
[root@server ~]# vi /etc/postfix/main.cf
myhostname = server.example.com ##line no 75 - uncomment and enter your host name
mydomain = example.com  ##line no 83 - uncomment and enter your domain name 
myorigin = $mydomain  ##line no 99 - uncomment
inet_interfaces = all  ##line no 116 - change to all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  ##line no 164 - add $domain at the end
mynetworks = 192.168.1.0/24, 127.0.0.0/8  ##line no 264 - uncomment and add your network range
home_mailbox = Maildir/  ##line no 419 - uncomment
Start the postfix service.
 
[root@server ~]# service postfix start
Starting postfix:                                          [  OK  ]
[root@server ~]# chkconfig postfix on

Test Postfix

The commands shown in bold letters should be entered by the user. 
Note: The dot after the test command is important.
 
[root@server ~]# telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 server.ostechnix.com ESMTP Postfix
ehlo localhost
250-server.ostechnix.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<user1>
250 2.1.0 Ok
rcpt to:<user1>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test
.
250 2.0.0 Ok: queued as 117113FF18
quit
221 2.0.0 Bye
Connection closed by foreign host.

Check Mail

Navigate to the user mail directory and check for the new mail.
 
[root@server ~]# cd /home/user1/Maildir/new/[root@server new]# ls
1360236956.Vfd00I35afM181256.server.example.com
[root@server new]# cat 1360236956.Vfd00I35afM181256.server.example.com Return-Path: <user1@example.com>
X-Original-To: user1
Delivered-To: user1@example.com
Received: from localhost (localhost [IPv6:::1])
 by server.example.com (Postfix) with ESMTP id 117113FF18
 for <user1>; Thu,  7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <20130207113547.117113FF18@server.example.com>
Date: Thu,  7 Feb 2013 17:05:32 +0530 (IST)
From: user1@example.com
To: undisclosed-recipients:;
test
Thats it. Postfix working now.

Install Dovecot

[root@server ~]# yum install dovecot

Configure Dovecot

Open the dovecot config file /etc/dovecot/dovecot.conf. Find and uncomment the line as shown below.
 
[root@server ~]# vi /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp
Open the file /etc/dovecot/conf.d/10-mail.conf and uncomment the line as shown below.
 
[root@server ~]# vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir  ##line no 24 - uncomment
Open the /etc/dovecot/conf.d/10-auth.conf and edit as shown below.
 
[root@server ~]# vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no  ##line no 9 - uncomment and change from yes to no.
auth_mechanisms = plain login  ##line no 97 - add the text "login"
Open the /etc/dovecot/conf.d/10-master.conf and edit as shown below.
 
unix_listener auth-userdb {
    #mode = 0600
    user = postfix  ##line no 83 - uncomment and enter postfix
    group = postfix  ##line no 84 - uncomment and enter postfix
Start the dovecot service.
 
[root@server ~]# service dovecot start
Starting Dovecot Imap:                                     [  OK  ]
[root@server ~]# chkconfig dovecot on 

Test Dovecot

 The commands shown in bold should be entered by the user.
 
[root@server ~]# telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user user1
+OK
pass user1
+OK Logged in.
list
+OK 1 messages:
1 428
.
retr 1
+OK 428 octets
Return-Path: <user1@example.com>
X-Original-To: user1
Delivered-To: user1@example.com
Received: from localhost (localhost [IPv6:::1])
 by server.example.com (Postfix) with ESMTP id 117113FF18
 for <user1>; Thu,  7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <20130207113547.117113FF18@server.example.com>
Date: Thu,  7 Feb 2013 17:05:32 +0530 (IST)
From: user1@example.com
To: undisclosed-recipients:;
test
.
quit 
+OK Logging out.
Connection closed by foreign host.
[root@server ~]# 
Dovecot is working now.

Install Squirrelmail

Install SquirrelMail package via yum.
 
[root@server ~]# yum install squirrelmail
[root@server ~]# service httpd start
Starting httpd:                                            [  OK  ]
[root@server ~]# chkconfig httpd on
[root@server ~]# 

Configure Squirrelmail

Go to the squirrelmail config directory and use the command ./conf.pl to start configure as shown below.
 
[root@server ~]# cd /usr/share/squirrelmail/config/
[root@server config]# ./conf.pl 
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database
10. Languages
D.  Set pre-defined settings for specific IMAP servers
C   Turn color off
S   Save data
Q   Quit
Command >>1 

Select option 1 and set organization details.
 
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1.  Organization Name      : Example
2.  Organization Logo      : ../images/sm_logo.png
3.  Org. Logo Width/Height : (308/111)
4.  Organization Title     : Welcome to Example webmail
5.  Signout Page           : 
6.  Top Frame              : _top
7.  Provider link          : http://example.com
8.  Provider name          : Example
R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit
Command >>R 

Press R to return main menu and select option 2. Enter your domain name and select dovecot in the Sendmail or SMTP parameter.
 
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1.  Domain                 : ostechnix.com
2.  Invert Time            : false
3.  Sendmail or SMTP       : SMTP
A.  Update IMAP Settings   : localhost:143 (uw)
B.  Update SMTP Settings   : localhost:25
R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit
Command >> S
Once you done, press S to save datas and press Q to exit.
Add the following lines in the httpd.conf file at the end.
 
[root@server ~]# vi /etc/httpd/conf/httpd.conf
Alias /squirrelmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all
</Directory>
 
Restart the httpd service.
[root@server ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@server ~]# 

Create Users

[root@server ~]# useradd user1
[root@server ~]# useradd user2
[root@server ~]# passwd user1
[root@server ~]# passwd user2
Open the browser from any clients. Type the following in the address bar.
http://serveripaddress/webmail
or
http://yourdomainname/webmail
 

If you have any query then please leave a reply.
With Regards
Piyush Gupta


 

DNS Server Configuration Steps

Setup DNS Server step by step in CentOS 6.3 / RHEL 6.3 / Scientific Linux 6.3.

DNS (Domain Name System) is the core component of network infrastructure. The DNS service resolves hostname into ip address and vice versa. For example if we type http://www.example.com in browser, the DNS server translates the domain name into its corresponding ip address. So it makes us easy to remember the domain names instead of its ip address.

DNS Server Installation in CentOS 6.3.

Scenario

Here are my test setup scenario

[A] Primary(Master) DNS Server Details:

Operating System     : CentOS 6.3 32 bit (Minimal Server)
Hostname             : masterdns.example.com
IP Address           : 192.168.1.200/24

[B] Secondary(Slave) DNS Server Details:

Operating System     : CentOS 6.3 32 bit (Minimal Server)
Hostname             : slavedns.example.com
IP Address           : 192.168.1.201/24  

Setup Primary(Master) DNS Server

[root@masterdns ~]# yum install bind* -y

1. Configure DNS Server

The main configuration of the DNS will look like below. Edit and add the entries below which are marked as bold in this configuration files.
[root@masterdns ~]# vi /etc/named.conf 
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
 listen-on port 53 { 127.0.0.1; 192.168.1.200;};                      ## Master DNS IP ##
 listen-on-v6 port 53 { ::1; };
 directory  "/var/named";
 dump-file  "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
 allow-query     { localhost; 192.168.1.0/24; };                      ## IP Range ##
 allow-transfer { localhost; 192.168.1.201; };                        ## Slave DNS IP ##  
 recursion yes;
 dnssec-enable yes;
 dnssec-validation yes;
 dnssec-lookaside auto;
 /* Path to ISC DLV key */
 bindkeys-file "/etc/named.iscdlv.key";
 managed-keys-directory "/var/named/dynamic";
};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
zone "." IN {
 type hint;
 file "named.ca";
};
zone "example.com" IN {
 type master;
 file "fwd.example.com";
 allow-update { none; };
};
zone "1.168.192.in-addr.arpa" IN {
 type master;
 file "rev.example.com";
 allow-update { none; };
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

2. Create Zone files

Now we should create forward and reverse zone files which we mentioned in the ‘/etc/named.conf’ file.

[A] Create Forward Zone

Create ‘fwd.example.com’ file in the ‘/var/named’ directory and add the entries for forward zone as shown below.
[root@masterdns ~]# vi /var/named/fwd.example.com 
$TTL 86400
@   IN  SOA     masterdns.example.com. root.example.com. (
        2011071001  ;Serial
        3600        ;Refresh
        1800        ;Retry
        604800      ;Expire
        86400       ;Minimum TTL
)
@ IN  NS      masterdns.example.com.
@ IN  NS      slavedns.example.com.  masterdns     IN  A    192.168.1.200
slavedns      IN  A    192.168.1.201

[B] Create Reverse Zone

Create ‘rev.example.com’ file in the ‘/var/named’ directory and add the entries for reverse zone as shown below.
[root@masterdns ~]# vi /var/named/rev.example.com 
$TTL 86400
@   IN  SOA     masterdns.example.com. root.example.com. (
        2011071001  ;Serial
        3600        ;Refresh
        1800        ;Retry
        604800      ;Expire
        86400       ;Minimum TTL
)
@ IN  NS      masterdns.example.com.
@ IN  NS      slavedns.example.com.
masterdns IN  A   192.168.1.200
slavedns  IN  A   192.168.1.201
200       IN  PTR     masterdns.example.com.
201       IN  PTR     slavedns.example.com.

3. Start the bind service

[root@masterdns ~]# service named start
Generating /etc/rndc.key:                                  [  OK  ]
Starting named:                                            [  OK  ]
[root@masterdns ~]# chkconfig named on

4. Allow DNS Server through iptables

Add the lines shown in bold letters in ‘/etc/sysconfig/iptables’ file. This will allow all clients to access the DNS server.
[root@masterdns ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -p udp -m state --state NEW --dport 53 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 53 -j ACCEPT-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

5. Restart iptables to save the changes

[root@masterdns ~]# service iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]

6. Test syntax errors of DNS configuration and zone files

[A] Check DNS Config file

[root@masterdns ~]# named-checkconf /etc/named.conf 
[root@masterdns ~]# named-checkconf /etc/named.rfc1912.zones 

[B] Check zone files

[root@masterdns ~]# named-checkzone example.com /var/named/fwd.example.com 
zone example.com/IN: loaded serial 2011071001
OK
[root@masterdns ~]# named-checkzone example.com /var/named/rev.example.com 
zone example.com/IN: loaded serial 2011071001
OK
[root@masterdns ~]#

7. Test DNS Server

Method A:

[root@masterdns ~]# dig masterdns.example.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6_3.6 <<>> masterdns.example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11496
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1
;; QUESTION SECTION:
;masterdns.example.com. IN A
;; ANSWER SECTION:
masterdns.example.com. 86400 IN A 192.168.1.200
;; AUTHORITY SECTION:
 example.com.  86400 IN NS masterdns.example.com.
 example.com.  86400 IN NS slavedns.example.com.
;; ADDITIONAL SECTION:
slavedns.example.com. 86400 IN A 192.168.1.201
;; Query time: 5 msec
;; SERVER: 192.168.1.200#53(192.168.1.200)
;; WHEN: Sun Mar  3 12:48:35 2013
;; MSG SIZE  rcvd: 110

Method B: 

[root@masterdns ~]# dig -x 192.168.1.200
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6_3.6 <<>> -x 192.168.1.200
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40891
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;200.1.168.192.in-addr.arpa. IN PTR
;; ANSWER SECTION:
200.1.168.192.in-addr.arpa. 86400 IN PTR masterdns.example.com.
;; AUTHORITY SECTION:
1.168.192.in-addr.arpa. 86400 IN NS masterdns.example.com.
1.168.192.in-addr.arpa. 86400 IN NS slavedns.example.com.
;; ADDITIONAL SECTION:
masterdns.example.com. 86400 IN A 192.168.1.200
slavedns.example.com. 86400 IN A 192.168.1.201
;; Query time: 6 msec
;; SERVER: 192.168.1.200#53(192.168.1.200)
;; WHEN: Sun Mar  3 12:49:53 2013
;; MSG SIZE  rcvd: 150

Method C:

[root@masterdns ~]# nslookup masterdns
Server:  192.168.1.200
Address: 192.168.1.200#53
Name: masterdns.example.com
Address: 192.168.1.200
 
Thats it. Now the Primary DNS server is ready

Setup Secondary(Slave) DNS Server

[root@slavedns ~]# yum install bind* -y

1. Configure Slave DNS Server

Open the main configuration file ‘/etc/named.conf’ and add the lines as shown in bold letters.
[root@slavedns ~]# vi /etc/named.conf
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
listen-on port 53 { 127.0.0.1; 192.168.1.201; }; ## Slve DNS IP ##
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query     { localhost; 192.168.1.0/24; }; ## IP Range ##
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
zone "." IN {
type hint;
file "named.ca";
};
zone "example.com" IN {
type slave;
file "slaves/example.fwd";
masters { 192.168.1.200; };
};
zone "1.168.192.in-addr.arpa" IN {
type slave;
file "slaves/example.rev";
masters { 192.168.1.200; };
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

2. Start the DNS Service

[root@slavedns ~]# service named start
Generating /etc/rndc.key:                                  [  OK  ]
Starting named:                                            [  OK  ]

[root@slavedns ~]# chkconfig named on
Now the forward and reverse zones are automatically replicated from Master DNS server to Slave DNS server. 
To verify, goto DNS database location(i.e ‘/var/named/slaves’) and use command ‘ls’.

[root@slavedns ~]# cd /var/named/slaves/

[root@slavedns slaves]# l
example.fwd  example.rev
The forward and reverse zones are automatically replicated from Master DNS. Now check the zone files whether the correct zone files are replicated or not.

[A] Check Forward zone:

[root@slavedns slaves]# cat example.fwd
$ORIGIN .
$TTL 86400 ; 1 day
ostechnix.com IN SOA masterdns.example.com. root.example.com. (
2011071001 ; serial
3600       ; refresh (1 hour)
1800       ; retry (30 minutes)
604800     ; expire (1 week)
86400      ; minimum (1 day)
)
NS masterdns.example.com.
NS slavedns.example.com.
$ORIGIN example.com.
masterdns A 192.168.1.200
slavedns A 192.168.1.201

[B] Check Reverse zone:

[root@slavedns slaves]# cat example.rev

$ORIGIN .
$TTL 86400 ; 1 day
1.168.192.in-addr.arpa IN SOA masterdns.example.com. root.example.com. (
2011071001 ; serial
3600       ; refresh (1 hour)
1800       ; retry (30 minutes)
604800     ; expire (1 week)
86400      ; minimum (1 day)
)
NS masterdns.example.com.
NS slavedns.example.com.
$ORIGIN 1.168.192.in-addr.arpa.
200 PTR masterdns.example.com.
201 PTR slavedns.example.com.
masterdns A 192.168.1.200
slavedns A 192.168.1.201

3. Add the DNS Server details to all systems

[root@slavedns ~]# vi /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 192.168.1.200
nameserver 192.168.1.201
nameserver 8.8.8.8

4. Test DNS Server

Method A: 

[root@slavedns ~]# dig slavedns.example.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6_3.6 <<>> slavedns.example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39096
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1
;; QUESTION SECTION:
;slavedns.example.com. IN A
;; ANSWER SECTION:
slavedns.example.com. 86400 IN A 192.168.1.201
;; AUTHORITY SECTION:
example.com. 86400 IN NS masterdns.example.com.
example.com. 86400 IN NS slavedns.example.com.
;; ADDITIONAL SECTION:
masterdns.example.com. 86400 IN A 192.168.1.200
;; Query time: 7 msec
;; SERVER: 192.168.1.200#53(192.168.1.200)
;; WHEN: Sun Mar  3 13:00:17 2013
;; MSG SIZE  rcvd: 110

Method B:

[root@slavedns ~]# dig masterdns.example.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6_3.6 <<>> masterdns.example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12825
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1
;; QUESTION SECTION:
;masterdns.example.com. IN A
;; ANSWER SECTION:
masterdns.example.com. 86400 IN A 192.168.1.200
;; AUTHORITY SECTION:
example.com. 86400 IN NS masterdns.example.com.
example.com. 86400 IN NS slavedns.example.com.
;; ADDITIONAL SECTION:
slavedns.example.com. 86400 IN A 192.168.1.201
;; Query time: 13 msec
;; SERVER: 192.168.1.200#53(192.168.1.200)
;; WHEN: Sun Mar  3 13:01:02 2013
;; MSG SIZE  rcvd: 110

Method C:

[root@slavedns ~]# nslookup slavedns
Server: 192.168.1.200
Address: 192.168.1.200#53
Name: slavedns.example.com
Address: 192.168.1.201

Method D:

[root@slavedns ~]# nslookup masterdns
Server: 192.168.1.200
Address: 192.168.1.200#53
Name: masterdns.example.com
Address: 192.168.1.200

Method E:

[root@slavedns ~]# dig -x 192.168.1.201
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6_3.6 <<>> -x 192.168.1.201
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56991
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;201.1.168.192.in-addr.arpa. IN PTR
;; ANSWER SECTION:
201.1.168.192.in-addr.arpa. 86400 IN PTR slavedns.example.com.
;; AUTHORITY SECTION:
1.168.192.in-addr.arpa. 86400 IN NS masterdns.example.com.
1.168.192.in-addr.arpa. 86400 IN NS slavedns.example.com.
;; ADDITIONAL SECTION:
masterdns.example.com. 86400 IN A 192.168.1.200
slavedns.example.com. 86400 IN A 192.168.1.201
;; Query time: 6 msec
;; SERVER: 192.168.1.200#53(192.168.1.200)
;; WHEN: Sun Mar  3 13:03:39 2013
;; MSG SIZE  rcvd: 150

Method F:

[root@slavedns ~]# dig -x 192.168.1.200

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6_3.6 <<>> -x 192.168.1.200
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42968
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;200.1.168.192.in-addr.arpa. IN PTR
;; ANSWER SECTION:
200.1.168.192.in-addr.arpa. 86400 IN PTR masterdns.example.com.
;; AUTHORITY SECTION:
1.168.192.in-addr.arpa. 86400 IN NS slavedns.example.com.
1.168.192.in-addr.arpa. 86400 IN NS masterdns.example.com.
;; ADDITIONAL SECTION:
masterdns.example.com. 86400 IN A 192.168.1.200
slavedns.example.com. 86400 IN A 192.168.1.201
;; Query time: 4 msec
;; SERVER: 192.168.1.200#53(192.168.1.200)
;; WHEN: Sun Mar  3 13:04:15 2013
;; MSG SIZE  rcvd: 150
Thats it. Both Primary and Secondary DNS Server is ready to use. Have a Good day!!!