Tuesday, September 10, 2013


Packet forwarding is the process relaying of packets from one network segment to another by nodes in a computer network.  It can easily be implemented in CentOS 6.4 by enabling the following option in /etc/sysctl.conf file as follows :
# Kernel sysctl configuration file for Red Hat Linux


# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and

# sysctl.conf(5) for more details.

# Controls IP packet forwarding

[root@dhcppc13 ~]# net.ipv4.ip_forward = 1
The above file can be opened in any editor (vim,nano,etc) preferred by the user.
User can confirm the settings  as below : 
[root@dhcppc13 ~]# /sbin/sysctl -p
The sample output is :
warning: /etc/sysctl.conf(7): invalid syntax, continuing...

net.ipv4.conf.default.rp_filter = 1

net.ipv4.conf.default.accept_source_route = 0

kernel.sysrq = 0

kernel.core_uses_pid = 1

net.ipv4.tcp_syncookies = 1

kernel.msgmnb = 65536

kernel.msgmax = 65536

kernel.shmmax = 68719476736

kernel.shmall = 4294967296

Thursday, September 5, 2013


When the system is repaired from using backup like data dump or TAR it may result in overwriting of master boot record (MBR). 
Thus, user needs to repair the bootstrap area before booting the system. Re-installation of bootstrap code (GRUB) can be 
performed in following steps :
=> Boot the system from CentOS 6.4 installation disc.
The above procedure results in boot menu from which select “Rescue installed system” 

=> Filesystems are mounted in read-write mode.

=> The root user is changed to real root on the hard disk using following command :
  #chroot /mnt/sysimage

Now Re-install bootstrap code (GRUB) as:

To re-install GRUB to the MBR on SCSI or SATA disk (/dev/sda)
 #grub-install /dev/sda

To re-install GRUB to the partition boot record (PBR) of Partition ,for example , second partition of SCSI or SATA disk (/dev/sda2) 
 # grub-install /dev/sda2

To re-install GRUB to the MBR on An IDE disk (/dev/hda)
 # grub-install /dev/hda

To re-install GRUB to the MBR on a HP Smart disk (/dev/cciss/c0d0):
 # grub-install /dev/cciss/c0d0

Wednesday, August 28, 2013


Linux has find utility to delete the files in the specified folder older than x days where value of x is entered by the user.
The example below illustrates the implementation of this utility:

# find /path/to/files* -mtime +x -exec rm {} \;

In the example above ,

The first argument /path/to/files is the location of the folder from where the files are deleted.

The second -mtime specifies number of days old that the file is. For example, +x will find files older than x days.

The third argument – exec allows user  to pass in a command such as rm while {} \; at the end is required to end the command.

Wednesday, August 21, 2013


YUM (Yellow Updater,Modified) and rpm  (Red Hat Package Manager) are used as package managment tool. These are frequently 
used for management but comprise of less frequently  used options as follows which save the time of system administrator to 
retrieve system related information :

=> rpm can be used to find all the packages which are installed outside CentOS repositories , that is , third party repositiories as 

[root@PC1 ~]# rpm -qa --qf '%{NAME} %{VENDOR}\n' | grep -v CentOS
The sample output is:
flash-plugin Adobe Systems Inc.
crash-trace-command Fujitsu Limited
adobe-release-x86_64 Adobe Systems Inc.
gpg-pubkey (none)
gpg-pubkey (none)

=> We can quickly view the documentation related to a package using either of the two commands as below:
rpm -qd <packagename>
rpm -qdf /path/to/file
The    first command gives the documentation present in  the rpm  while second option gives the documentation in the package 
which owns the file.For example:
 [root@PC1 ~]# rpm -qd pinentry-0.7.6-6.el6.x86_64

=> The       following command is used to list the file stored inside the rpm file
# rpm -qpl file.rpm
For        example,
  [root@PC1 ~]# rpm -qpl Downloads/adobe-release-x86_64-1.0-1.noarch.rpm 
=> We can also list the files in the installed package using following command:
# rpm -ql packageName
For example,
 [root@PC1 ~]#rpm -ql httpd

Friday, August 16, 2013


Netstat is a command which displays detailed information about system's mode of communication in a network. This 
command has advantage of displaying very  detailed information about network including network connections , 
protocol-specific networking statics, and overall network which is helpful in troubleshooting network related issues.

Nestat command when used with -a flag displays the state of all sockets used by system processes.

[root@cbitss ~]# netstat -a  | more 
Active Internet connections (servers and established) 
Proto Recv-Q Send-Q Local Address               Foreign Address  State      
tcp        0      0 *:rquotad                   *:*                         LISTEN      
tcp        0      0 *:38924                     *:*                         LISTEN      
tcp        0      0 *:59853                     *:*                         LISTEN      
tcp        0      0 *:sunrpc                    *:*                         LISTEN      
tcp        0      0 *:37589                     *:*                         LISTEN      

In the above example netstat command is piped with more pagination to display result page by page.
All tcp ports can be listed as follows:

User can also find the Kernel interface table which is similar to ifconfig command by using -ie flag with netstat as follows:

[root@dhcppc15 ~]# netstat -ie 

The sample output of above command is as follows:
Kernel Interface table 
eth0      Link encap:Ethernet  HWaddr 00:E0:E8:66:44:11  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1 
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b) 
          Interrupt:20 Base address:0xc000 

eth1      Link encap:Ethernet  HWaddr 00:1D:7D:80:18:1B  
          inet addr:  Bcast:  Mask: 
          inet6 addr: fe80::21d:7dff:fe80:181b/64 Scope:Link 
          RX packets:34628 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:26093 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:37288056 (35.5 MiB)  TX bytes:2928416 (2.7 MiB) 

lo        Link encap:Local Loopback  
          inet addr:  Mask: 
          inet6 addr: ::1/128 Scope:Host 
          UP LOOPBACK RUNNING  MTU:16436  Metric:1 
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:0 
          RX bytes:960 (960.0 b)  TX bytes:960 (960.0 b)

Thursday, August 15, 2013


All ports can be listed using following command:
[root@cbitss ~]# netstat -a  | more 
Active Internet connections (servers and established) 
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 *:rquotad                   *:*                         LISTEN      
tcp        0      0 *:38924                     *:*                         LISTEN      
tcp        0      0 *:59853                     *:*                         LISTEN      
tcp        0      0 *:sunrpc                    *:*                         LISTEN      
tcp        0      0 *:37589                     *:*                         LISTEN      

All tcp ports can be listed as follows:
[root@cbitss ~]# netstat -at 
Active Internet connections (servers and established) 
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 *:rquotad                   *:*                         LISTEN      
tcp        0      0 *:38924                     *:*                         LISTEN      
tcp        0      0 *:59853                     *:*                         LISTEN      
tcp        0      0 *:sunrpc                    *:*                         LISTEN      
tcp        0      0 *:37589                     *:*                         LISTEN      
tcp        0      0 *:ssh                       *:*                         LISTEN      
tcp        0      0 localhost:ipp               *:*                         LISTEN      
tcp        0      0 localhost:smtp              *:*                         LISTEN      
tcp        0      0 *:34394                     *:*                         LISTEN      
tcp        0      0 *:nfs                       *:*                         LISTEN      
tcp        0      0 *:962                       *:*                         LISTEN      
tcp        0      0 *:36034                     *:*                         LISTEN      
tcp        0      0 *:36103                     *:*                         LISTEN      
tcp        0      0          del01s06-in-f22.1e100:https ESTABLISHED 
tcp        1      0          a96-17-181-51.deploy.a:http CLOSE_WAIT  
tcp        0      0 *:40170                     *:*                         LISTEN      
tcp        0      0 *:54990                     *:*                         LISTEN      
tcp        0      0 *:sunrpc                    *:*                         LISTEN

Wednesday, August 14, 2013


Here is a simple interactive shell script to redirect all stdout from the subshell.For example if the user wants to 
redirect contents of files entered to the file in temporary folder /tmp/sh, it can be done as follows :

Vim Script_Name.sh
echo -n "Enter the file whose content is to be redirected using subshell: "

read file_path 
#enter the path of the file whose data is to be redirected.Multiple files can be given.


cat $file_path

#The data is redirected to temporary folder.

The above script can be executed directly as follows:
# bash Script_Name.sh
#  sh Script_Name.sh

The script can also be executed  by giving execute permission as follows:
# chmod +x Script_Name
# ./Script_Name

Tuesday, August 13, 2013


The bash prompt can be customized in numberous ways depending on user specific customization or sytem wide configuration.

For user specific configuration we edit ~/.bashrc and add customization below the line “# User specific aliases and functions”. 
For example the sample `/.bashrc for user named test is as follows:

# .bashrc

# Source global definitions

if [ -f /etc/bashrc ]; then

        . /etc/bashrc


# User specific aliases and functions

PS1='\u@\H:\w\$ '

In the above example the prompt will have user_name@hostname.domain.tld:/working/directory$ sequence yielding following 


Users can also implement colourful prompt using following syntax :
PS1='\[\033[02;32m\]\u@\H:\[\033[02;34m\]\w\$\[\033[00m\] '

Above Prompt Setter will give colorful prompt as :

Bash supports a range of colour as listed below:
Black             0;30     Dark Gray     1;30
Blue               0;34     Light Blue    1;34
Green             0;32     Light Green   1;32
Cyan              0;36     Light Cyan    1;36
Red                0;31     Light Red     1;31
Purple            0;35     Light Purple  1;35
Brown            0;33     Yellow        1;33
Light Gray      0;37     White         1;37

'h' is used instead of 'H' to display hostname only and not complete url.

System-wide Configuration

To implement prompt setting system-wide the changes are made in /etc/bashrc file as follows :
36 #[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "

Comment 36 line number.

For example we can add terminal in which user is logged in bash prompt by uncommenting following lines in /etc/bashrc file :
40               if [ "$PS1" ]; then

41                        PS1="[\u@\h:\l \W]\\$ "

42               fi

The above gives bash prompt as follows:
[root@cbitss:tty1 Desktop]#

Thus, user can change bash prompt as per the requirement.

Monday, August 12, 2013

Cloud Computing

Cloud computing is Internet based computing.In cloud computing virtual shared servers provide software, infrastructure, platform,devices,hosting and other resources to customers on a pay-as-you-use basis.
In cloud computing all information that digitized system has to offer is provided as a service.User can access these services on Internet cloud.
There are four different kind of deployment models of cloud  computing:-
1.Public Cloud
2.Community Cloud
3.Hybrid Cloud
4.Private Cloud
Benefits of Cloud computing:-

*Allows the enterprise to focus on its core business
*Increased competitive advantage
*Easy to maintain as they don't have to be installed on each user's computer

Sunday, August 11, 2013

Post of load balancing

 Load balancing is especially important for networks where it's difficult to predict the number of requests that will be issued to a server.
Distributing processing and communications activity evenly across a computer network so that no single device is overwhelmed..Busy web sites typically employ two or more web servers in a load balancing scheme. If one server starts to get swamped, requests are forwarded to another server with more capacity. Load balancing can also refer to the communications channels themselves.
Load balancing is usually provided by dedicated software or hardware, such as a multilayer switch/domain name system server process.Lately, some load balancers have evolved to support databases; these are called database load balancers.
For Internet services, the load balancer is usually a software program that is listening on the port where external clients connect to access services.
The term load balancing refers to distributing incoming HTTP requests across Web servers in a server farm, to avoid overloading any one server because load balancing distributes the requests based on the actual load at each server, it is excellent for ensuring availability and defending against denial of service attacks.

Friday, August 9, 2013


Here is a simple interactive shell script to display concatenation of two strings entered by the user and display  the length the        resultant string.

Vim Script_Name.sh
echo -n "Enter the file path : "
#Display user the message to enter file path.
read file_path
#Input the path.
echo "The fourth and fifth line of file are as follows:"
cat $file_path | head -5 | tail -2
#Display fourth and fifth line.

The above script can be executed directly as follows:
# bash Script_Name.sh
#  sh Script_Name.sh

The script can also be executed  by giving execute permission as follows:
# chmod +x Script_Name
# ./Script_Name

Thursday, August 8, 2013


Here is a simple interactive shell script to display concatenation of two strings entered by the user and display the length the resultant string.

Vim Script_Name.sh
echo -n "Enter  the first string: "                                              
read  str1                                                                   # input the first string.
echo -n "Enter the second string: "
read str2                                                                    # input the second string
str3=$str1$str2                                                         # concatenate   the above two input strings.
len=`echo $str1 | wc -c`                                         # find the length of first  input string.
len1=`echo $str2 |wc -c`                                       # find the length of second input string.
len2=`echo $str3 | wc -c`                                     # find the length of concatenated string.
echo "The length of first string is : `expr $len – 1`"            # display the length of first string.
echo "The length of second string is : `expr $len1 – 1`"   # display the length of second string.
echo "THe lenght of concatenated string is : `expr $len2 – 1`" # display the length of concatenated string.

The above script can be executed directly as follows:
# bash Script_Name.sh
#  sh Script_Name.sh

The script can also be executed  by giving execute permission as follows:
# chmod +x Script_Name
# ./Script_Name

Tuesday, August 6, 2013


The htpasswd is the command used to give password to the various users who try to access a particular webpage in Apache 
Web Server.The following commands are executed to provide the user-based authentication:

 # htpasswd -cm /etc/httpd/conf/.htpasswd User_Name

Change the directory to http configuration file where the above file (.htpasswd) is created.
 # cd /etc/httpd/conf

Check the content of the file created using following command which will  show the encrpyted password:
 # ls -a

the above command shows the hidden files.

Next create the access file in the directory where webpages are  placed as follows:
 # vim /var/www/html/WebPage_Dir/.htaccess

Make the following entries in the above file :
 AuthType Basic  #AuthType directive selects that method that is used to authenticate the user. The most common method is 
Basic AuthName “Server Authentication”    #This directive sets the Realm to be used in authentication which is presentd to user 
as part of password dialog box as well as client uses it to determine what password to send for given authenticated area.
 AuthUserFile  /etc/httpd/conf/.htpasswd       #AuthUserFile directive sets the name of a textual file containing the list of users 
and passwords for user authentication.
 Require valid-user           #Grant access to all successfully authenticated users.

Finally, to implement the changes make the following changes in th configuration file of apache server which is 
 # vim /etc/httpd/conf/httpd.conf
 <directory /var/www/html/WePage_Dir>
  AllowOverride Authconfig

Now restart the service daemon and access the site from the client-end.
 # service httpd restart


The yum-plugin-priority associate a priority to the repositories so that packagesfrom repositories with lower priority will not be used to upgrade packages which were initially installed from higher priority repository. The users can also set the priorities to the repositories so that the packages are installed from higher priority repository if present in multiple repository.This plugin help user to update sytem from repositories which help in maintaining the functioning of CentOS.

To enable the priority-plugin the option of plugin should be enabled in /etc/yum.conf file as follows:

# vim /etc/yum.conf











The priorities plugin is available at two locations:
By default enabled CentOS Extras Repository where yum-plugin-priority can be installed using following command :

  # yum install yum-plugin-priorities
yum-utils sources which has README file with instructions to install the plugin in the archieve directory.

Once the package is installed it should also be enabled in the /etc/yum/pluginconf.d/priorities.conf :


  enabled = 1

Following the above steps enables the plugin.Now we can add priorities to the repositories by appending following line

to the targeted repository,where N is integer ranging from 1 to 99. Repositories with the lowest numerical value have the highest 
priority. It is best practice to give CentOS base and update repositories very high priority.
The default priority for repositories is 99.

Monday, August 5, 2013


Here is a simple shell script to reverse the digits of the number entered by the user.

echo "Enter the number to be reversed where the first digit should have range from 1-9"   #prompt the message to enter the 
number such that first digit is not zero
read number                                                       #enter the number
var=${#number}                                               #find the number of the digits in the  number                                                           
for((i=1;i<=$var;i++))                                       # initiate the loop
var1=$((number%10))                                        #find the last digit of the number
echo -n "$var1"                                                 #display the last digit such that output should not trail to the new line.
number=$((number/10))                                  #remove the last digit     
done                                                                    #terminate the loop
echo                                                                  #change to new line

The above script is simple technique to reverse any number entered by the user.
Note : The script can be executed by giving execute permission as below:
                     # chmod +x Script_Name
        # ./Script_Name
Executing the script directly as follows:
                      # bash Script_Name
                     #  sh Script_Name


Here is a simple script which reads and display each word of the file separated by a blank space whose path is entered by 
the user. The IFS(Internal File Separator) of the file is blank space in other case it should be changed accordingly.

echo -n "Enter the path to file whose content is to be read line by line :  "
#ask user to enter the path of the file whose data is to be read word by word
read file_path
#input the path
for i in `cat $file_path`
#start the loop 
echo $i
#display each word of file separated by blank space
#terminate the loop

Note: The above script can be executed by giving it execute permission as follows:
 #chmod +x Script_Name
Directly executing the script as follows:
 #bash Script_name
 #sh Script_Name

Friday, August 2, 2013


Ntfs-3g is GPL licensed,cross-palteform and read/write driver used in Linux which  is provides safe handling of files in 
NTFS format. 
The basic requisite is to install the package which facilitate the mounting of nts partition in linux.This utility is provided by ntfs-3g 
package which are available    in EPEL Repository.
 # yum -y install ntfs-3g
The EPEL Repository for CentOS6.4 can be downloaded using following steps.
#wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
#rpm -ivh epel-release-6*.rpm
# yum install fuse
With FUSE it is possible to implement a fully functional filesystem in a userspace program.  Features include:
  • Simple library API
  • Simple installation (no need to patch or recompile the kernel)
  • Secure implementation
  • Userspace - kernel interface is very efficient
  • Usable by non privileged users
  • Runs on Linux kernels 2.4.X and 2.6.X
  • Has proven very stable over time

Install and load FUSE driver to mount detected devices
# modprobe fuse
Next,make the directory where the partition is to be mounted.
# mkdir /mnt/ntfs_partition
Temporary mounting can be done by following command.
# mount -t ntfs-3g /dev/sda1 /mnt/ntfs_partition
For permanent mounting make the following entry in /etc/fstab file:
/dev/sdx    /mnt/usb    ntfs-3g        defaults    0    0

where /dev/sdx is hard disk partition with NTFS file system.
Thus, the data can now be accessed by changing directory where partition is mounted.

Thursday, August 1, 2013


A simlpe shell script to read any file line by line 
where the name of file is passed as the argument:
~]# touch navneet.sh
~]# chmod 755 navneet.sh
~]# vi navneet.sh
 file_name=$1                                         #positional parameter $1 is passed as the argument to the script
flag=0                                                       #initialize the variable read the file
cat $file_name | while read LINE       #pipe the content of file to while loop
let flag++                                                #post increment of flag counter
echo "$flag $LINE"                              #display each line with line number
done                                                      #termination of loop 
esc:wq                                                  #save file

The above script displays the content of the file name entered by line.

Tuesday, January 1, 2013

Ken Thompson biography

Kenneth Lane Thompson (born February 4, 1943), commonly referred to as ken in hacker circles is an American pioneer of computer science.Kenneth Lane Thompson was the principal inventor of UNIX. Even today, more than 35 years later, UNIX and its descendants are still widely regarded as the best computer operating systems to have ever been developed.He received a Bachelor of Science in 1965 and a master's degree in 1966, both in Electrical Engineering and Computer Science, from the University of California, Berkeley, where his master's thesis advisor was Elwyn Berlekamp.Having worked at Bell Labs for most of his career.Thompson designed and implemented the original Unix operating system.In the 1960s, Thompson and Dennis Ritchie worked on the Multics operating system. While writing Multics, Thompson created the Bon programming language. The two left the Multics project when Bell Labs withdrew from it, but they used the experience from the project, and in 1969, Thompson and Ritchie became the principal creators of the Unix operating system.Thompson decided that Unix needed a system programming language and created B, a precursor to Ritchie's C language.Thompson was elected to the National Academy of Engineering in 1980 for designing UNIX, an operating system whose efficiency, breadth, power, and style have guided a generation's exploitation of minicomputers.

Lessons we learn from Ken Thompson

Thompson, like Linus Torvalds, the founder of Linux, is another example of history being shaped by the right person being ready at the right time.It is also an example of how a single person with an idea and dedication can accomplish something that eludes large organizations with huge concentrations of talent and massive budgets.He created great works not with any intention for personal profit but rather because of their dedication to their craft and their desire to improve it, with the result that the world is also improved.