Saturday, March 19, 2011

How to Block Ping/ICMP request on Linux box

We can make Linux box to ignore ping requests by edit the /etc/sysctl.conf file and add the below line,

net.ipv4.icmp_echo_ignore_all = 1

else use the below command to append the entry

# echo "net.ipv4.icmp_echo_ignore_all = 1" >> /etc/sysctl.conf

To activate the kernel parameters added in /etc/sysctl.conf file immediately at runtime, use below commands

# sysctl –p

Now the box which you have added the above parameter will not be pingable, it ignores the icmp requests.

Wednesday, February 2, 2011

Command to remove the defunct/zombie Process in Solaris

A defunct/zombie process is one whose exit status is yet to be reaped by its parent. Few parent process may not exit for a very long time and thus leave zombies on the system. Such defunct/zombie processes do not normally impact system operation, but they do consume a small amount of system resource.


# preap pid ( Force a defunct process to be reaped by its parent )

# preap -F pid ( -F option forces the parent to reap the child by overriding safety checks )

Saturday, January 22, 2011

Linux Box Hardware Info..!

1.) /etc/sysconfig/hwconf

The file "/etc/sysconfig/hwconf" has the complete database of the hardware components attached to the server & /etc/sysconfig/hwconf file will get updated by kudzu service as it detects the current hardware when it gets started.

2.) dmidecode

"dmidecode" command will also give hardware details, this commands fetches the details from BIOS (i.e) it is stored, in which you can get the details of the server manufacturer, Serial number & etc. Also you can get few more hardware details like processor information, number of memory slots, cache information & etc.

Refer man page for more options used in the command, below are few examples

Eg:

[root@redhat ~]# dmidecode -s baseboard-manufacturer
Intel Corporation
[root@redhat ~]# dmidecode -s baseboard-product-name
440BX Desktop Reference Platform
[root@redhat ~]# dmidecode -s system-manufacturer
VMware, Inc.
[root@redhat ~]# dmidecode -s system-serial-number
VMware-56 4d b7 bf 13 66 65 14-7b d6 db f2 d7 a7 df 0b
[root@redhat ~]#

Friday, January 21, 2011

Load Average - Linux

Most of us (not all may be guys like me ) are having misconception about load average in Linux, pls go through this. It will make you clear.

Linux follows the standard of traditional UNIX and computes its load average as the average number of runnable or running processes (R state), and the number of processes in uninterruptable sleep (D state) over the specified interval. Some other operating systems calculate their load averages simply by looking at processes in R state. On those systems, load average is synonymous with the run queue -- high load averages mean that the box is CPU bound. This is not the case with Linux. On Linux the load average is a measurement of the amount of "work" being done by the machine (without being specific as to what that work is).This "work" could reflect a CPU intensive application (compiling a program or encrypting a file), or something I/O intensive (copying a file from disk to disk, or doing a database full table scan), or a combination of the two.

Source: https://access.redhat.com/kb/docs/DOC-2044

Exit Codes

We can determine the exit status of command executed by command `echo $?` if it returns the value 0 its success & any non zero is failure.

Few examples,

1.)

[root@redhat ~]# w
10:02:20 up 27 min, 1 user, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/1 192.168.164.1 09:36 0.00s 0.04s 0.00s w
[root@redhat ~]# echo $?
0
[root@redhat ~]# asda
-bash: asda: command not found
[root@redhat ~]# echo $?
127
[root@redhat ~]#

2.)

[root@redhat ~]# grep asdasf /etc/passwd
[root@redhat ~]# echo $?
1
[root@redhat ~]# grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
[root@redhat ~]# echo $?
0
[root@redhat ~]#

Hope these examples have given more clarity.



Few Exit Codes & its meaning,

1 - Catchall for general errors
2 - Misuse of shell built-ins according to Bash documentation.
126 - Command invoked cannot execute
127 - command not found, may be path issue or misspelt commands
128 - Invalid argument to exit
128 - +n Fatal error signal "n"
130 - Script terminated by Control-C (Control-C is fatal error signal 2, (130 = 128 + 2, see above))
255 - Exit status out of range

Linux Printing Commands

Few basic printing commands used in linux

# lpr xyz.doc (Print xyz.doc on default printer)

# export PRINTER=hp3000 (Change the default printer)

# lpr -Php3300 #2 xyz.doc (Use printer hp3300 and print 2 copies)

# lpq (Check the queue on default printer)

# lpq -l -P hp3300 (Queue on printer hp3300 with verbose)

# lprm - (Remove all users jobs on default printer)

# lprm -P hp3300 1500 (Remove job 1500, Find job number with lpq)

# lpc status (List all available printers)

# lpc status hp3300 (Check if printer is online and the queue length)