Search This Blog

Loading...

Tuesday, September 10, 2013

INTERNET PACKET (IP) FORWARDING


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

RE-INSTALL BOOTSTRAP CODE (GRUB)


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

DELETE FILES OLDER THAN x DAYS IN LINUX.


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

RETRIVING PACKAGE INFORMATION


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 
follows:

[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>
 OR
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
/usr/share/doc/pinentry-0.7.6/AUTHORS
/usr/share/doc/pinentry-0.7.6/COPYING
/usr/share/doc/pinentry-0.7.6/ChangeLog
/usr/share/doc/pinentry-0.7.6/NEWS
/usr/share/doc/pinentry-0.7.6/README
/usr/share/doc/pinentry-0.7.6/THANKS
/usr/share/doc/pinentry-0.7.6/TODO
/usr/share/info/pinentry.info.gz

=> 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 
/etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
/etc/yum.repos.d/adobe-linux-x86_64.repo
=> We can also list the files in the installed package using following command:
# rpm -ql packageName
For example,
 [root@PC1 ~]#rpm -ql httpd
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/etc/httpd/conf.d/welcome.conf


Friday, August 16, 2013

NETSTAT COMMAND FOR QUICK NETWORK RELATED INFORMATION


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:192.168.1.17  Bcast:192.168.1.255  Mask:255.255.255.0 
          inet6 addr: fe80::21d:7dff:fe80:181b/64 Scope:Link 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1 
          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:127.0.0.1  Mask:255.0.0.0 
          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

NETSTAT COMMAND FOR QUICK NETWORK RELATED INFORMATION


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 192.168.1.28:45021          del01s06-in-f22.1e100:https ESTABLISHED 
tcp        1      0 192.168.1.28:38722          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

SHELL SCRIPT TO REDIECT ALL STDOUT FROM SUBSHELL.


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
:i
#!bin/bash
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

)>/tmp/sh 
#The data is redirected to temporary folder.
:wq

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

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