Thursday, August 23, 2012

Script to Find Out Lun ID of Give mount point of EMC storage.

#!/bin/bash

read -e -p "Enter mount point which u want to find lun ID eg./data3: " mount_point
#read mount_point;
lvname=`mount | grep $mount_point | cut -d " " -f1`;
#echo $lvname;
physical_vol_name=`lvdisplay -m $lvname | grep "Physical volume" | awk '{print $3}'|sed -e 's/.*\/dev\///' -e 's/\/.*//'|sed 's/[0-9]*//g'`;
#echo $physical_vol_name
lun_id=`powermt display dev=$physical_vol_name | grep -i "Logical device ID"`
echo "$lun_id  is Lun ID of mount point $mount_point"

Thursday, April 12, 2012

CHECK NTP IS DOING ITS JOB OR NOT

There are a number of utilities available to check if NTP is doing it's job. The ntpq -p command will print out your system's current time status.
# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*cudns.cit.corne ntp0.usno.navy.  2 u  832 1024  377   43.208    0.361   2.646
 LOCAL(0)        LOCAL(0)        10 l   13   64  377    0.000    0.000   0.008

The ntpdc -c loopinfo will display how far off the system time is in seconds, based upon the last time the remote server was contacted.

# ntpdc -c loopinfo
offset:               -0.004479 s
frequency:            133.625 ppm
poll adjust:          30
watchdog timer:       404 s
 

ntpdc -c kerninfo will display the current remaining correction.

# ntpdc -c kerninfo
pll offset:           -0.003917 s
pll frequency:        133.625 ppm
maximum error:        0.391414 s
estimated error:      0.003676 s
status:               0001  pll
pll time constant:    6
precision:            1e-06 s
frequency tolerance:  512 ppm
pps frequency:        0.000 ppm
pps stability:        512.000 ppm
pps jitter:           0.0002 s
calibration interval: 4 s
calibration cycles:   0
jitter exceeded:      0
stability exceeded:   0
calibration errors:   0
 

A slightly more different version of ntpdc -c kerninfo is ntptime

# ntptime
ntp_gettime() returns code 0 (OK)
  time c35e2cc7.879ba000  Thu, Nov 13 2003 11:16:07.529, (.529718),
  maximum error 425206 us, estimated error 3676 us
ntp_adjtime() returns code 0 (OK)
  modes 0x0 (),
  offset -3854.000 us, frequency 133.625 ppm, interval 4 s,
  maximum error 425206 us, estimated error 3676 us,
  status 0x1 (PLL),
  time constant 6, precision 1.000 us, tolerance 512 ppm,
  pps frequency 0.000 ppm, stability 512.000 ppm, jitter 200.000 us,
  intervals 0, jitter exceeded 0, stability exceeded 0, errors 0.

Yet another way to see how well NTP is working is with the ntpdate -d command. This will contact an NTP server and determine the time difference but not change your system's time.

# ntpdate -d 132.236.56.250
13 Nov 14:43:17 ntpdate[29631]: ntpdate 4.1.1c-rc1@1.836 Thu Feb 13 12:17:20 EST 2003 (1)
transmit(132.236.56.250)
receive(132.236.56.250)
transmit(132.236.56.250)
receive(132.236.56.250)
transmit(132.236.56.250)
receive(132.236.56.250)
transmit(132.236.56.250)
receive(132.236.56.250)
transmit(132.236.56.250)
server 132.236.56.250, port 123
stratum 2, precision -17, leap 00, trust 000
refid [192.5.41.209], delay 0.06372, dispersion 0.00044
transmitted 4, in filter 4
reference time:    c35e5998.4a46cfc8  Thu, Nov 13 2003 14:27:20.290
originate timestamp: c35e5d55.d69a6f82  Thu, Nov 13 2003 14:43:17.838
transmit timestamp:  c35e5d55.d16fc9bc  Thu, Nov 13 2003 14:43:17.818
filter delay:  0.06522  0.06372  0.06442  0.06442
         0.00000  0.00000  0.00000  0.00000
filter offset: 0.000036 0.001020 0.000527 0.000684
         0.000000 0.000000 0.000000 0.000000
delay 0.06372, dispersion 0.00044
offset 0.001020

13 Nov 14:43:17 ntpdate[29631]: adjust time server 132.236.56.250 offset 0.001020 sec

If you want actually watch the system synchronize you can use ntptrace.

# ntptrace 132.236.56.250
cudns.cit.cornell.edu: stratum 2, offset -0.003278, synch distance 0.02779
truetime.ntp.com: stratum 1, offset -0.014363, synch distance 0.00000, refid 'ACTS'

If you need your system time synchronized immediately you can use the ntpdate remote-servername to force a synchronization. No waiting!
# ntpdate 132.236.56.250
13 Nov 14:56:28 ntpdate[29676]: adjust time server 132.236.56.250 offset -0.003151 sec

Sunday, April 8, 2012

DHCP SERVER on RHEL 6


DHCP SERVER ON REDHAT 6
lab scenario := 
server IP =192.168.0.10
server Hostname = server.example.com
-----------------------------------------------------------------------------------------------------
1st step := Install dhcp package 
# yum -y install dhcp* 
then 
2nd step := copy the dhcpd.sample.conf file 
# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
 
3rd step := edit the dhcpd.conf below like this
# dhcpd.conf

#

# Sample configuration file for ISC dhcpd

#



# option definitions common to all supported networks...

option domain-name "example.org";

option domain-name-servers ns1.example.org, ns2.example.org;



default-lease-time 600;

max-lease-time 7200;



# Use this to enble / disable dynamic dns updates globally.

#ddns-update-style none;



# If this DHCP server is the official DHCP server for the local

# network, the authoritative directive should be uncommented.

#authoritative;



# Use this to send dhcp log messages to a different log file (you also

# have to hack syslog.conf to complete the redirection).

log-facility local7;



# No service will be given on this subnet, but declaring it helps the 

# DHCP server to understand the network topology.



subnet 10.152.187.0 netmask 255.255.255.0 {

}



# This is a very basic subnet declaration.



subnet 10.254.239.0 netmask 255.255.255.224 {

  range 10.254.239.10 10.254.239.20;

  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;

}



# This declaration allows BOOTP clients to get dynamic addresses,

# which we don't really recommend.



subnet 10.254.239.32 netmask 255.255.255.224 {

  range dynamic-bootp 10.254.239.40 10.254.239.60;

  option broadcast-address 10.254.239.31;

  option routers rtr-239-32-1.example.org;

}



# A slightly different configuration for an internal subnet.

#subnet 10.5.5.0 netmask 255.255.255.224 {

 # range 10.5.5.26 10.5.5.30;

  #option domain-name-servers ns1.internal.example.org;

  #option domain-name "internal.example.org";

  #option routers 10.5.5.1;

  #option broadcast-address 10.5.5.31;

  #default-lease-time 600;

  #max-lease-time 7200;

#}



subnet 192.168.0.0 netmask 255.255.255.0 {

  range 192.168.0.80 192.168.0.100;

  option domain-name-servers server.example.com;

  option domain-name "server.example.com";

  option routers 10.5.5.1;

  option broadcast-address 10.5.5.31;

  default-lease-time 600;

  max-lease-time 7200;

}

# Hosts which require special configuration options can be listed in

# host statements.   If no address is specified, the address will be

# allocated dynamically (if possible), but the host-specific information

# will still come from the host declaration.



host passacaglia {

  hardware ethernet 0:0:c0:5d:bd:95;

  filename "vmunix.passacaglia";

  server-name "toccata.fugue.com";

}



# Fixed IP addresses can also be specified for hosts.   These addresses

# should not also be listed as being available for dynamic assignment.

# Hosts for which fixed IP addresses have been specified can boot using

# BOOTP or DHCP.   Hosts for which no fixed address is specified can only

# be booted with DHCP, unless there is an address range on the subnet

# to which a BOOTP client is connected which has the dynamic-bootp flag

# set.

host fantasia {

  hardware ethernet 08:00:07:26:c0:a5;

  fixed-address fantasia.fugue.com;

}



# You can declare a class of clients and then do address allocation

# based on that.   The example below shows a case where all clients

# in a certain class get addresses on the 10.17.224/24 subnet, and all

# other clients get addresses on the 10.0.29/24 subnet.



class "foo" {

  match if substring (option vendor-class-identifier, 0, 4) = "SUNW";

}



shared-network 224-29 {

  subnet 10.17.224.0 netmask 255.255.255.0 {

    option routers rtr-224.example.org;

  }

  subnet 10.0.29.0 netmask 255.255.255.0 {

    option routers rtr-29.example.org;

  }

  pool {

    allow members of "foo";

    range 10.17.224.10 10.17.224.250;

  }

  pool {

    deny members of "foo";

    range 10.0.29.10 10.0.29.230;

  }

}

 save and quit 

and start the service 
# /etc/init.d/dhcpd start 

DNS SERVER ON RHEL 6


Lab scenario:- 
Server Ip = 192.168.0.10
Server Hostname = server.example.com
Client IP = 192.168.0.40
Client Hostname = client.example.com
1step := setting up your hostname 

 # vim /etc/host 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.0.10  server.example.com server


# vim /etc/sysconfig/network
NETWORKING=yes

HOSTNAME=server.example.com

# hostname server.example.com [press enter]
2nd step := add entry in resolve.conf file
# vim /etc/resolve.conf
# Generated by NetworkManager

search example.com

nameserver 192.168.0.10





3rd step := Install BIND package 
# yum -y install bind* 

4rth step := Edit the named.conf 
1st backup this file
# cp -avr /etc/named.conf /etc/named.conf.org
# vim /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 { 192.168.0.10; };

 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     { any; };

 recursion yes;



 dnssec-enable yes;

 dnssec-validation no;

 dnssec-lookaside auto;



 /* Path to ISC DLV key */

 bindkeys-file "/etc/named.iscdlv.key";

};



logging {

        channel default_debug {

                file "data/named.run";

                severity dynamic;

        };

};



zone "." IN {

 type hint;

 file "named.ca";

};



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




save and quit 
5th step := Edit /etc/named.rfc1912.zones like this
// named.rfc1912.zones:

//

// Provided by Red Hat caching-nameserver package 

//

// ISC BIND named zone configuration for zones recommended by

// RFC 1912 section 4.1 : localhost TLDs and address zones

// and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt

// (c)2007 R W Franks

// 

// See /usr/share/doc/bind*/sample/ for example named configuration files.

//



zone "example.com" IN {

 type master;

 file "forward.zone";

 allow-update { none; };

};



zone "localhost" IN {

 type master;

 file "named.localhost";

 allow-update { none; };

};



zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {

 type master;

 file "named.loopback";

 allow-update { none; };

};



zone "0.168.192.in-addr.arpa" IN {

 type master;

 file "reverse.zone";

 allow-update { none; };

};



zone "0.in-addr.arpa" IN {

 type master;

 file "named.empty";

 allow-update { none; };

};


Save AND Quit 





6th step := create forware.zone nad reverse.zone file in /var/named/  like this 
 # cp named.localhost forward.zone

 #  cp named.loopback reverse.zone


7th step := edit the forward and reverse.zone like this 
$TTL 1D

@ IN SOA server.example.com. root.server.example.com. (

     0 ; serial

     1D ; refresh

     1H ; retry

     1W ; expire

     3H ) ; minimum

 IN NS server.example.com.

server  IN A     192.168.0.10

 

8th step Edit the reverse.zone like this 
$TTL 1D

@ IN SOA server.example.com. root.server.example.com. (

     0 ; serial

     1D ; refresh

     1H ; retry

     1W ; expire

     3H ) ; minimum

       IN NS server.exmaple.com.

10     IN PTR server.example.com.

save file 

9th step := change the group of forward.zone and reverse.zone
 #  chgrp named forward.zone 
 #   chgrp named reverse.zone 
10th step := start the service 

# service named restart 
the test the DNS server 
# dig -x 192.168.0.10
# nslookup 192.168.0.10

Monday, March 26, 2012

Shell Script to crate user from old server to new server

Shell Script to crate user from old server to new server.

1) copy /etc/passwd file from old server to new server password.txt in same location where you execute same script

shell script

#!/bin/bash
# Script to add a user to Linux system
# -------------------------------------------------------------------------

groupadd -g 501 amco
#echo "Default Group Amco created"
usernamelist="`cat password.txt | cut -d ":" -f1 `"
#fullname="`cat password.txt |cut -d":" -f5`"
for i in $usernamelist
do
if [ $(id -u) -eq 0 ]; then
        
#    read -p "Enter username : " username
    #read -s -p "Enter password : " password
    username="$i"
    password="123456"
    fullname="`grep -i $username password.txt | cut -d":" -f5`"
    useruid="`grep -i $username password.txt | cut -d":" -f3`"
    egrep -w "^$username" /etc/passwd >/dev/null
    if [ $? -eq 0 ]; then
        echo "$username exists!"
#        exit 1
    else
        pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
        useradd -m -u "$useruid" -G amco -c "$fullname" -p "$pass" -d /home/$username "$username"
        [ $? -eq 0 ] && echo "User $username has been added to system!" || echo "Failed to add a user $username!"
        #`chage -d 0 $username`   
    fi
else
    echo "Only root may add a user to the system"
    exit 2
fi
done




BLOCK USB to connect linux server

BLOCK USB to connect linux server

echo 'blacklist usb_storage' >/etc/modprobe.d/blacklist-usb_storage
echo 'modprobe -r usb-storage' >> /etc/rc.local

Tuesday, March 20, 2012

ISCSI TARGET ON RHEL 6


ISCSI TARGET SERVER HOW TO ON REDHAT6-----------------------------------------------------------
(THIS Practical is created in vmware machine )

lab setup :-

server : ip add 192.168.0.10
hostname = server.example.com

client= ip add 192.168.0.100
hostname= client1.exmaple.com

-------------------------------------------********************************-------------------------------------------------------
# install following package
# yum -y install scsi*
then
# chkconfig tgtd on

step 2 add vitual hardisk and create lvm on that hardisk
and mount it the


step 3
# vim /etc/tgt/targets.conf
And add this line at end of the file
<target iqn.2011-2012.com.exmaple:server.target1>

backing-store /dev/wgroup/whare

</target>


then test discover the iSCSI target from the target server itself, using the following command:
#iscsiadm -m discovery -t sendtargets -p 192.168.0.10
  192.168.0.10:3260,1 iqn.2011-2012.com.exmaple:server.target1

then u succseefully created ISCSI TARGET SERVER
 ------------------------------------------------------------------------------------------------------------
Client side := 1st step Run follwing command

 # iscsiadm -m discovery -t st -p 192.168.0.10(serverip)


 192.168.0.10:3260,1 iqn.2011-2012.com.exmaple:server.target1


 then copy only for (iqn.2011-2012.com.exmaple:server.target1)


 and past it like this


 # iscsiadm -m node -T iqn.2011-2012.com.exmaple:server.target1 –login

 it will give mesg successful


# then run the fdisk -l itwill show u server side disk thats it



Monday, March 19, 2012

UMOUNT FORCEFULLY COMMAND


  • umount file system when device is busy


          # umount /data
              Umount /dev/sdb1 : device is busy
               Umount /dev/sdb1 : device is busy
         So
                   # fuser –m /data
                      /data     : 4582c

               Then give command
                  # ps –ef |grep 4582

              And kill the process

                Then unmount the file system
 Or 

give command for umount 

# umount -l /data 

SWAP COMMAND


  • Clear the swap space in linux


First we want to see what is currently being use

    # free

Then checkout swap use or not


Then give command

# swapoff –a and

# free


Then
# swapon  -a

# free


Rsync command and tar.gz commands


  • If u want to transfer data 1 server to another server give following command

               # rsync –auv source file path or file name                            remotepath(192.168.252.212:/home/amol/Desktop)




·        List the contents of a tar.gz file


             #  tar –tvf  file.tar.gz

·        List the contents of a tar.bz2 file

# tar -jtvf file.tar.bz2


  • How to extract tar.gz file in another directory

         # tar –zxvf  file.tar.gz  -C destination path(/amol)


  • How to create tar.gz file
   #  tar –zcvf  file.tar.gz  your file name like file1

finding package of particuler file belonging


  • How to check that a particular filebelong to which package.
           Ans.

       Before this run command

      # which  rescan-scsi-bus.sh
       /usr/bin/ rescan-scsi-bus.sh

      Then go to that path and run below command


       # rpm –qf  /usr/bin/rescan-scsi-bus.sh
        sg3_utils-1.27-17.7

GRUB PASSWORD IN SUSELINUX11


                                                         SETTING GRUB PASSWORD IN SUSE LINUX 11

1st step

# grub-md5-crypt
Passwor: 
Reenterpassword:
Sdfdsfdsfsdafdasfsdf$$$$

# then copy the encrypted password in menu.lst

Like this
# vim /boot/grub/menu.lst

Add line below
Default 0
Timeoute 0

Password –md5  Sdfdsfdsfsdafdasfsdf$$$$


Then restart the server 

DENY ROOT SSH LOGIN


ALLOW   NORMAL USER  LOGIN VIA PUTTY


In SLES 11

Server :-  192.168.0.101

Edit the line

# vim /etc/ssh/sshd_config
unComment the PermitRootLogin     Yes
and change like this
 
PermitRootLogin   no

And save the file

Then restart the ssh service

Create normal user ( amol)



Client machine :- 192.168.0.50

SSH BANNER


                 Setting up banner when Putty through Login

In SLES 11 =:

Edit like this

#   cat /etc/issue

                                      BSE  Ltd.



       "This system is for the use of authorized personnel only. Unauthorized or improper use of this system may
result in administrative disciplinary action and/or legal action by the BSE Ltd. management. By continuing to use
this system indicate your awareness of IS policies of BSE Ltd. and adhering to the same."




#  vim /etc/ssh/sshd_config

Add following line
Or
Edit the Banner none line 

# no default banner path
Banner /etc/issue

Then restart the ssh service

Pure-ftpd configuration on SUSE Linux


                                  Pure-ftpd configuration on SUSE Linux


Lab scenario :

ftp-server :192.168.0.102
client :192.168.0.101

on ftpserver we create 3 users

·          ftpadmin = were all data keeping in like as
/home/ftpadmin/data/i586/

And change the ownership like this

#Chown –R  ftpadmin.users /home/ftpadmin/data

Next  user is bsembr6385

And change the ownership like this

# chown –R ftpadmin:users  /home/bsembr6385

We change the ownership becoz client side bsembr6385 login and acess the data in /home/ftpadmin/data


Or

If u want restrict the /home/ftpadmin/data to bsembr6385

Then run the follwing command

# chmod 744 –R  /home/ftpadmin/data

Then bsembr6385 cannot see te content of the Data directory



1step

Install pure-ftpd package from dvd od sles11

2nd step

Start the service

# /etc/init .d /pure-ftpd restart

 The go to client side




REAR OSBACKUP IMAGE


                                                          RELAX AND RECOVER (OS BACKUP)
------------------------------------------------------------------------------------------------------------------------------------------------


Rear server – 192.168.0.102
# install rear package
# showmount –e 192.168.0.101
Export lisr for 192.168.0.101
/rear_backup *
# vi m /e tc/rear/local.conf
BACKUP = N ETFS
NETFS_URL=nfs://192.168.0.101/rear_backup
OUTPUT=ISO
MODULES_LOAD=(vmxnet)
# rear mkbackup
Relax & Recover Version 1.7.23/2009-12-09
Warning ! the NETFS backup method should not be your primary
Backup solution , because it does not fulfill the requirement
The preparatipon  phase ok
Physical devices that will be recover :/dev/sda
Creating root fs layout ok
Copy files and directory ok
Copy kernel moduls ok
Create initiramfs ok
Creating archive nfs://192.168.0.102/rear_backup /santy/backup.tar.gz
Archive size is 25 mb

NFS server 192.168.0.102
# cd /rear_backup/rear
Backup.tar.gz
Backup.txt
README
Rear.iso
VERSION
# copy REAR.iso on vmhost and boot from Rear .iso

YUM SERVER IN RHEL 5


On server side

Ip add = 192.168.0.25
Hostname = server1
# mount /dev/cdrom /me        dia
# cp –r /media/RHEL/Server /var/ftp/pub/
# rm –r /var/ftp/pub/Server/repodata
# createrepo –g /media/RHEL/Server/repodata/comps-rhel5-server-core.xml /var/ftp/pub/Server/
# cp /etc/yum.repos.d/rhel.debuginfo.repo /ftp.repo
#edit file like that for local yum
[server]
name=server
baseurl=file:///var/ftp/pub/Server
enabled=1
gpgcheck=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release


Then run 

# yum list

-----------------------------------------------------------
And for client on vsftpd service and then
Edit the file of client before editing move all file in yum.repose.d  and move only one file and edit this file like

# mv /etc/yum.repos.d/* /
#cp /centos-base.repo /etc/yum.repos.d/
#mv /etc/yum.repos.d/centos-base.repo /etc/yum.repos.d/ftpserver.repo
# vim /etc/yum.repos.d/ftpserver.repo
[ftpserver]
name=base
baseurl=ftp://192.168.0.25/var/ftp/pub/Server/
enable=1
gpgcheck=0