Buscar este blog

miércoles, 27 de julio de 2011

Configuring a DHCP Server CentOS 6.

DHCP server installation:

# yum search dhcp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.mirror.xtratelecom.es
 * extras: centos.mirror.xtratelecom.es
 * updates: centos.mirror.xtratelecom.es
=== Matched: dhcp ====================================================
dhcp-devel.i686 : Development headers and libraries for interfacing to the DHCP server
dhclient.i686 : Provides the dhclient ISC DHCP client daemon and dhclient-script
dhcp.i686 : Dynamic host configuration protocol software
sblim-cmpi-dhcp.i686 : SBLIM WBEM-SMT DHCP
sblim-cmpi-dhcp-devel.i686 : SBLIM WBEM-SMT DHCP - Header Development Files
sblim-cmpi-dhcp-test.i686 : SBLIM WBEM-SMT DHCP - Testcase Files
dnsmasq.i686 : A lightweight DHCP/caching DNS server
avahi-autoipd.i686 : Link-local IPv4 address automatic configuration daemon (IPv4LL)
avahi-dnsconfd.i686 : Configure local unicast DNS settings based on information published in mDNS

Select dhcp.i686

#yum install dhcp.i686

Sample DHCP server config file: 

#nano /etc/dhcp/dhcpd.conf 

DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'
#   A slightly different configuration for an internal subnet.
  subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.10 192.168.1.254;
  option domain-name-servers 62.14.2.1, 62.14.63.14;
  option domain-name "mydomain.net";
  option routers 192.168.1.1;
  option broadcast-address 192.168.1.255;
  default-lease-time 7200;
  max-lease-time 86400;
}

Save and exit file /etc/dhcp/dhcpd.conf

Starting DHCP server:

/etc/init.d/dhcpd start

lunes, 25 de julio de 2011

How to Synchronize Two Directories in a Local Server.

To sync two directories in a local computer, use the following rsync -vrupAogEh command.
rsync -vrupAogEh  /mnt/remote-fs/shares/ /srv/shares/

sending incremental file list
folders1/folders2/subfolder/subfolder1/subfolder2/namefileCASTELLANO.PDF
folders1/folders2/subfolder/subfolder1/subfolder2/namefileCATALAN.PDF
folders1/folders2/subfolder/subfolder1/subfolder2/namefileEUSKERA.PDF
folders1/folders2/subfolder/subfolder1/subfolder2/old/
folders1/folders2/subfolder/subfolder1/subfolder2/old/namefileCASTELLANO.PDF
folders1/folders2/subfolder/subfolder1/subfolder2/old/namefileCATALAN.pdf
folders1/folders2/subfolder/subfolder1/subfolder2/old/namefileEUSKERA.pdf

Linux burn ISO images to Cds and CD-RW/DVD-+R howto

List device and Get an overview of drives and their addresses.

cdrskin -scanbus

# cdrskin -scanbus
cdrskin 0.7.0 : limited cdrecord compatibility wrapper for libburn
cdrskin: scanning for devices ...
cdrskin: ... scanning for devices done
Using libburn version '0.7.0'.
scsibus1:
        1,0,0     0) 'HL-DT-ST' 'DVD-ROM GDRH20N ' 'D8E4' Removable CD-ROM
Select 1,0,0     0) 'HL-DT-ST' 'DVD-ROM GDRH20N ' 'D8E4' Removable CD-ROM

List device: lsscsi

# lsscsi
[0:0:0:0]    tape    HP       Ultrium 2-SCSI   T65D  /dev/st0
[1:0:0:0]    cd/dvd  HL-DT-ST DVD-ROM GDRH20N  D8E4  /dev/sr0 
 

Write ISO-9660 filesystem image as only one to blank or formatted media: 


# cdrskin -v dev=/dev/sr0 speed=12 fs=8m \ blank=as_needed -eject padsize=300k my_image.iso
 

jueves, 21 de julio de 2011

How to change the hostname of a Linux system

Permanent hostname change on RedHat based systems

RedHat based system use the file /etc/sysconfig/network to read the saved hostname at system boot. This is set using the init script /etc/rc.d/rc.sysinit

/etc/sysconfig/network
NETWORKING=yes
HOSTNAME="plain.domainname.com"
GATEWAY="192.168.0.1"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"

So in order to preserve your change on system reboot edit this file and enter the appropriate name using the HOSTNAME variable.


 
 

miércoles, 20 de julio de 2011

Linux install and configure NTP to synchronize the system clock

Procedure

Login as the root user
Type the following command to install ntp
# yum install ntp

Turn on service
# chkconfig ntpd on

Synchronize the system clock with 0.pool.ntp.org server:
# ntpdate pool.ntp.org

Start the NTP:
# /etc/init.d/ntpd start

Kill process in Linux or terminate a process in Linux systems

kill process using PID (process id)
Above command tell you PID (3486) of lighttpd process. Now kill process using this PID:
# kill 3486

OR
# kill -9 3486

Where,
  • -9 is special Kill signal, which will kill the process.

killall command examples

You can also use killall command. The killall command kill processes by name (no need to find PID):
# killall -9 lighttpd
Kill Firefox process:
# killall -9 firefox-bin

Linux Creating a Partition Size Larger than 2TB

Linux desktop user generally uses small hard disk and partition, but on server you need a large partition. For example, you cannot create 4TB partition size (RAID based) using fdisk command. It will not allow you to create a partition that is greater than 2TB. In this tutorial, you will learn more about creating Linux filesystems greater than 2 Terabytes to support enterprise grade operation under any Linux distribution.
To solve this problem use GNU parted command with GPT. It supports Intel EFI/GPT partition tables. Partition Table (GPT) is a standard for the layout of the partition table on a physical hard disk. It is a part of the Extensible Firmware Interface (EFI) standard proposed by Intel as a replacement for the outdated PC BIOS, one of the few remaining relics of the original IBM PC. EFI uses GPT where BIOS uses a Master Boot Record (MBR).
GUID Partition Table
(Diagram illustrating the layout of the GUID Partition Table scheme. Each logical block (LBA) is 512 bytes in size. LBA addresses that are negative indicate position from the end of the volume, with −1 being the last addressable block. Imaged Credit Wikipedia)

GPT Kernel Support

EFI GUID Partition support works on both 32bit and 64bit platforms. You must include GPT support in kernel in order to use GPT. If you don't include GPT support in Linux kernelt, after rebooting the server, the file system will no longer be mountable or the GPT table will get corrupted. By default Redhat Enterprise Linux / CentOS comes with GPT kernel support. However, if you are using Debian or Ubuntu Linux, you need to recompile the kernel. Set CONFIG_EFI_PARTITION to y to compile this feature.
File Systems
   Partition Types
     [*] Advanced partition selection
     [*] EFI GUID Partition support (NEW)
....

Linux create 3TB partition size

One of my clients has Raid 5 Array -7x500GB hard disks to store large data. To create partition start GNU parted as follows:
# parted /dev/sdx
Output:
GNU Parted 1.8.1
Using /dev/sdx
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)
Creates a new GPT disklabel i.e. partition table:
mklabel gpt
Create 3TB partition size:
mkpart primary 0 3001G
Quit and save the changes:
quit
Use mkfs to format file system:
# mkfs.ext3 /dev/sdx1
Note: Replace /dev/sdx with actual RAID or disk name or block Ethernet device such as /dev/etherd/e0.0 . Don't forget to update /etc/fstab, if necessary.

BASH: Prepend A Text / Lines To a File

BASH: Prepend A Text / Lines To a File


Q. I can append text to a file using >> operator but how do I prepend a text to a file? I want the opposit of >> operation?

A.
There is no prepend operator, however there are many ways to do the same. You can use ed, sed, perl, awk and so on.

Prepend a text using a temporary file

Here is simple solution using a temporary file to prepend text:
echo 'line 1' > /tmp/newfile
echo 'line 2' >> /tmp/newfile
cat yourfile >> /tmp/newfile
cp /tmp/newfile yourfile

viernes, 15 de julio de 2011

Linux Tape Backup With mt And tar Command Howto

Magnetic tape is a non-volatile storage medium consisting of a magnetic coating on a thin plastic strip. Nearly all recording tape is of this type, whether used for video, audio storage or general purpose digital data storage using a computer. How do I make backup using tapes under Linux operating systems?


Linux (and other Unixish system) use mt command to control magnetic tape drive operation. You need to use mt command while working with tape drive. It allows you to reading and writing to tape.


The default tape drive under Linux is /dev/st0 (first SCSI tape device name). You can read more about tape drives naming convention used under Linux here. Following paragraph summaries command you need to use control tape drive for backup/restore purpose.



Rewind tape drive:
# mt -f /dev/st0 rewind

Backup directory /www and /home with tar command (z - compressed):
# tar -czf /dev/st0 /www /home

Restore /www directory:

# cd /
# mt -f /dev/st0 rewind
# tar -xzf /dev/st0 www

Find out what block you are at with mt command:
# mt -f /dev/st0 tell

Display list of files on tape drive:
# tar -tzf /dev/st0

Display status information about the tape unit:
# mt -f /dev/st0 status

Fast format:
# dd if=/dev/zero of=/dev/st0 bs=512 count=1

Erase the tape:#
# mt -f /dev/st0 erase

Unload the tape:
# mt -f /dev/st0 offline


You can go BACKWARD or FORWARD on tape with mt command itself:

Go to end of data:
# mt -f /dev/nst0 eod(b)

Goto previous record:
# mt -f /dev/nst0 bsfm 1(c)
Forward record:#
# mt -f /dev/nst0 fsf 1


Linux Tape Backup Example


To backup to multiple tape use the following command (backup /home file system):
# tar -clpMzvf /dev/st0 /home
To compare tape backup, enter:
# tar -dlpMzvf /dev/st0 /home
To restore tape in case of data loss or hard disk failure:
# tar -xlpMzvf /dev/st0 /home
Where,


    * d : find differences between archive and file system
    * x : extract files from an archive
    * l : list the contents of an archive
    * p : ignore umask when extracting files
    * M : create/list/extract multi-volume archive (multiple tapes)
    * z : Compress backup using gzip
    * v : verbosely list files processed
    * f /dev/st0 : Tape device name
    * /home : Backup /home file system

State process by command ps

State process command CP


ps -aux |grep cp


Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
root        17  0.0  0.0      0     0 ?        S<   Jul11   0:00 [kacpid]
root      6374  1.0  0.0   4356   824 pts/0    D+   15:45   0:02 cp -i -pru /srv/shares/ /media/iomega/

How to disable directory browsing using httpd.conf – Apache Web Server

Apache Web Server

Disable directory browsing using httpd.conf:

Open server ssh.
#vim /etc/httpd/conf/httpd.conf 

Find in file httpd.conf loock for Options Indexes 

Original line:       #    Options Indexes FollowSymLinks
Change line:              Options -Indexes FollowSymLinks

Change the Indexes to -Indexes if Option Indexes exists or else add the Options -Indexes line
Save file
Restart your apache web server. Send command  /etc/init.d/httpd restart

The directory browsing feature should be disable by now

Enabling and disabling services during start up in GNU/Linux

1) Red Hat Method

Red Hat and Red Hat based Linux distributions make use of the script called chkconfig to enable and disable the system services running in Linux.

For example, to enable the apache webserver to start in certain run levels, you use the chkconfig script to enable it in the desired run levels as follows:
# chkconfig httpd --add
# chkconfig  httpd  on --level 2,3,5
This will enable the apache webserver to automatically start in the run levels 2, 3 and 5. You can check this by running the command:
# chkconfig --list httpd
One can also disable the service by using the off flag as shown below:
# chkconfig httpd off
# chkconfig httpd --del
Red Hat also has a useful script called service which can be used to start or stop any service. Taking the previous example, to start apache webserver, you execute the command:
# service httpd start
and to stop the service...
# service httpd stop

Fully disabling SELinux

Fully Disabling SELinux

Fully disabling SELinux goes one step further than just switching into permissive mode. Disabling will completely disable all SELinux functions including file and process labelling. In Fedora Core and RedHat Enterprise, edit /etc/selinux/config and change the SELINUX line to SELINUX=disabled:

# 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 - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted