Archive for April, 2010

Adding Multiple IP Address to A NIC Card

It is possible to bind more than one ip address on a single network interface card in linux.

copy your existing network card  configuration file as shown:

#cd /etc/sysconfig/network-scripts
#cp ifcfg-eth0 ifcfg-eth0:1

>>ifcfg-eth0 looks like this :

# File: ifcfg-eth0

Change the device name and the ip address parameters

File : ifcfg-eth0:1

#save the fiel and then restart the network

#service network restart

How to retrieve file

You can retrieve file by issuing the following command

dig . ns >

or download from this location :

Grub reinstall in rescue mode

You can re-install grub boot loader in rescue mode by issuing the following command :

#grub-install /dev/sda1 or hda1 ( based on your boot partition)

if it is scsi drive it would be sda and hda if it is ide drive.

If you get something like this :

” Error /dev/hdx or sdx does not have any corresponding bios drive ”  then issue the following command :

#grub-install –recheck /dev/sda or hda

Hope it helps

Save File as in VI Editor

You can save file as another file in vi editor after you make changes to the current file, so that you can quit without saving and still retain the changes in another file.

:w! newfile.txt


:w! /var/newfile.txt


Introduction to String Processing

Introduction to string Processing


Head and tail command are used to view the first and last few lines of a file respectively.

By default these commands generate 10 number of lines.

# head /etc/passwd (shows first 10 lines)

# tail /etc/passwd (shows last 10 lines)

One very handful command to monitor log messages

#tail -f /var/log/messages  (this is used to see the online activities)

wc: Word count

This command is used to count number of lines, words or characters in a file

Syntax: wc <option> filename

options: -l counts number of lines

-w counts number of words

-c counts number of characters

# wc -wlc *

Cut: cut command cut the specified field from the file of known formats or to cut first few characters

#cut <option> <file name>

options:  d -delimiter or field separator

-f{number} -field number

-c -to cut the characters

#cut -d: -f1 /etc/passwd (shows only the first field of /etc/passwd’s contents

#cut -d: -f1-3 /etc/passwd (shows only first second and third fields of /etc/passwd contents)

#cut -c1-10 /etc/passwd (shows first 10 characters of file’s line)


sorting is the arrangement of data/information in increasing (ascending) or decreasing(descending) pattern.

#sort <options> file name

options: -r -reverse order

-n -numeric order

-t -as field separator, delimiter

-k position

-u unique sort

#sort /etc/passwd

#sort -r /etc/passwd

#cut -d:-f7 /etc/passwd|sort -u

#sort -t: -K1 /etc/passwd

Uniq: uniq moves the duplication and returns only the unique items.

# cut -d -f7 /etc/passwd|uniq -c (also counts number of counts for the item)

Managing Partitions

*Mounting filesystem

#mount (fs-type> -o <options> <partition_name> <mount_point>

fs_type=vfat,ext2,ext3,iso9660 etc

options=rw    ro

exec        noexec

dev      nodev

auto    noauto

suid    nosuid

user    nouser or (owner, noowner)

async sync

the above options are default keywords

additional options




#mount /dev/hdax /personnel (only for temporary or this session only)

(kernel-rpm.rpm for kernel of fat32 supported system)

The above commands only for current serrions.

#vi /etc/fstab -contains mount info of  partitions to permanently mount partitons


[partition_name/label_name]  [mount_point]  [fs_type] [options] [dump_freq] [fsck_order]



0–> not a candidate oof dump (backup command)

1–> To create dump backup daily

2–> To create dump backup every alternate day




& so on



0–> Not a candidate oof fsck {filesystem check command)

1–>first candidate of fsck

2–>second ,,       ,,   ,,




& so on


[p_name/lable           [mount_point]  [fs_type]  [options] [dump_freq]  [fsck_order]

or lable name]


/dev/hdax       /personnel     ext3       defaults      0 or 1     1 or 2



* to active the changes of /etc/fstab

#mount -a –To activate nnew entry in /etc/fstab

#df -h


use options in options filed like


for remount command

#mount -o remount /sbogati


#cd /sbogati

#cat >file


Adding Swap space

1. As a partition

#fdisk /dev/hda


2. create swap signature

#mkswap /dev/hdax

3. To activate swap

#free  (displays memory info)

a. temporary  activation

#swapon /dev/hdax


note: to deactivate swap #swap /dev/hdax


b. permanent  activation

# vi /etc/fstab

/dev/hdax       swap       swap      defaults  0 0


after returning for vi editor


#swapon -a –> top activate nnew swap entry in /etc/fstab


adding partition as a file

#dd of=/dev/zero oof=/swapfille(can be give any name) bs=1M count=128000 (128mb)

bs can be write as bs=1K

/dev/zero –> is called inifinite sink

#cd /

#ls -lh swapfile

#mkswap /swapfile (given swap file name)


#swapon /swapfile


#swapon /swapfile


#vi /etc/fstab

/swaapfile swap /swap defaults 0 0

save and exit from here

#swapon -a


Linux Filesystem Management

Linux Filesystem management

–>File system Ids

ext2/ext3  –>83

linux swap  ->82

RAID       –>fd

LVM        –>83

above id no. are based on hex system

#fdisk -l

-> Disk partitioning tools

.fdisk -> post-installaton disk partitioning tool (other disk partition tools

sfdiks – can be used in scripts

parted- advanced disk partitioning tool (partition can be resize though this tool)

.fdisk -l (lists partition table of all the disks)

to create new partition

#fdisk /dev/hda1

m –>lists all the fdisk commands & theier jobs

p –>prints partition table

n –>to create new partition

t –>to specify file system id

d –>to delete a partition

q –>to quit without save

w –>to write  (ie. save) the changes into disk & quit

press n to create new partition

#partprobe – updates new partition table

#partprobe – updates new partition table

#partprobe – updates new partition table

–Creating file system (ie. formatiing)

a. mkfs -t <fs_type> <partition_name>


#mkfs ext3 /dev/hdax (x is last created partition nukber)


b.  #mke2fs.<fs_type> <partition_name>

ie. #mkfs.ext3 /dev/hdax


mke2fs [options] [partition_name]

options= -j – to create ext3 with journaling

-b <block_size in byte>

-l <label name>

-c to check for badblocks before creating file system


#cd /

#mkdir directory (ie. personnel)

mke2fs -j -b 2048 -l /personnel /dev/hdax

#e2label /dev/hdax (to chck label)

#e2lable /dev/hdax new /newlabel

Linux Hardware and Kernel

* Hardware Resources

–>Kudzu – .It is hardware detection program that typically runs during boot time to detect any added or removed h/w.

.It refers the file/etc/sysconfig/hwconf to deletct any added/removed h/w.

#hwbrowser . Graphical tool that displays the list of detected h/w.

#cd /usr/share/hwdata – This dir. contains the catalogue of supported moniors, v                        ga etc.


—> Controlling Kernel Modules (Dynamically loadable device drivers)

* Kernel Module management tools


#lsmod — Lists all the kernel modules that are currently loaded into memory (RAM

#rmmod <module_name> – to remove the specified kernel module, if not in use

#insmod <module_name> – to load the specified kernel module. It does not load the dependent modules

#modprob <module_name> – to load the specified kernel module along with its depe                              ndent modules. It refers the kernel /etc/modules.conf b                         efore loading the module.

#modinfo <module_name> – Displays detasil info about the specified kernel module.

locaton of modules


#vi /etc/modules.conf – kernel module config file.

alias <alias_name> <drive name> ie. alias eth0 8139too

inside the modules.conf,







see more in #man modules.conf


#ifconfig eth0 down/up to enable/disable ehternet card

#rmmod 8139too – to remove ethernet card driver

#ifup eth0 (to enable the removed driver for ethernet card)

to add ehternet card driver manually


#insmod 8139too (this command does not determines the depencies server)

Driver path for ehternet driver


#vi /etc/modules.conf

pre-install 8139too server sshd stop

#moprobe 8139too

#lsmod |grep 8139too

#service sshd status

#modinfo 8139too (to see the module info)

— /proc filesystem

.it is vertual filesystem that contains info of running kernel.

.contains system info. providing fles like: cpuinfo, meminfo partitions etc…

#cd /


cd proc


#cat cpyinfo


#cat meminfo

#man proc or #man procinfo

* to turn off ping response

#cat /proc/sys/net/ipv4/icmp_echo_ignore_all (0 for accept incoming echo and

1 for block all request)

#echo “1” >/proc/sys/net/ipv4/icmp_echo_ignore_all (it blocks ping request) this ony for current session

#vi /etc/sysctl.conf

net.ipv4.icmp_echo_ignore_all=1  – to turn off

#sysctl -p ->to activaye changes into the file /etc/sysctl.conf

conclusion (you should know about these things)

1. installaton

2. grub related problem (/etc/grub,conf, gru cli)

.init initialiazation /etc/inittab

.service management (chkconfig & service)

3.  lsmod,rmmod,modprobe /etc/modules.conf

.to turn off ping responses

Controlling Services in Linux

–> Controlling services

service management tools:

1 .chkconfig

.it is noninteractive tool that can be used in shell scripts.

.xinetd-based services comes into immediate effect if actived/de-activated

with this tool.

.Stand-Alone service comes into effect only on next rebootif

activated/de-activated using this tool. [to avoid reboot, use ‘service


2. Service

.It is used to activate/de-activate stand-alone services for the current

session only.

Other tools


#redhat-config-services — GUI-based tool

#ntsysv – text based interactive tool.

Note: The location of service package

/etc/xinetd.d  ( dependencies services)

/etc/rc.d/init.d (stand-alone services )

#chkconfig –list telnet status

#service xinetd status

#chkconfig –list telnet

#chkconfig –list xinetd

#chkconfig –list (displays status of all the services)

#chkconfig –list (service_name ie. telnet) — Displays the status of the

specified service

#chkconfig <xinetd_based service ie. telnet ) on/off — To activate/de-activate                                                         xinetd

#service xinetd status [must be running for xinetded services to work

#chkconfig <stand-alone_service> on/off — Activate/De-activate the stand-alone                                            service

. Effect on next reboot only.

#chkconfig <runlevel> <standalone service> on/off

Runlevel defines only for the particular runlevel ie runlevel


#chkconfig –level <runlevels> <stand-alaone service> on/off

ie. #chkconfig –level 35 xinetd on (its run only runlevel 3 and 5)

check after #service xinetd status

#service <stand-alone-service> status/stop/start/restart/reload (syntax of                                                                   service command)


Linux Daemons

Deamons (what is deamons)


.Background process are called deamons and sometimes called services)



Two types:

1. Stand-alone deamon

.Location: /etc/rc.d/init.d/*

.Keeps running all the time

2. Transient deamon (service)

.Controled by super-deamon ‘xinetd’

.Location: /etc/xinetd.d/*

.Also called xniedtd-based deamons (or services)

Note: The list of /etc/rc.d/* contains runlevel specifiec shell scripts

The list of /etc/rc.d/rc3.d/* contains symbolic links

Format of symbolic links


meaning of above formats

S- to start the service

K- to kill (ie. stop) the service

X- .No. that represents priority to start/stop the sevices

.lower no. has higer priority

Service_name- Symbolic link of the services in /etc/rc.d/init.d


rc-> This shell executes at the time system booting as well as when the system changes its runlevel.

.This shell scripts starts/stops runlevel specific services contained in


* to switch to “n” terminal

#chrt n ie. #chrt 3

#init q to re-examine /etc/inittab