Tuesday, February 22, 2011

Using find command in linux

"find" command is one of the important commands in Linux. It makes easy for us to find a file or a directory.We can also find the unused files from last few days and delete it. "find" command also makes it easy to search for files which have been modified few hours or days back.
Below are the some of the examples of using  find command :

Find files using name :
[root@localhost ~]#find /root -name anaconda-ks.cfg

Find files ignoring the case
[root@localhost ~]#find /usr/src -iname  makefile

Find with mindepth and maxdepth i.e limit search to specific directory
The command below gives the list of passwd file in whole /
[root@localhost ~]#find / -name passwd
/usr/bin/passwd
/usr/share/doc/nss_ldap-264/pam.d/passwd
/usr/lib/news/bin/auth/passwd
/etc/passwd
/etc/pam.d/passwd

Find files with inode numbers
Lets create the test file and note down its inode number

[root@localhost ~]# touch test-file
[root@localhost ~]# ls -il test-file
1632299 -rw-r--r-- 1 root root 0 2011-02-22 22:44 test-file

Now lets find the file by inode number
[root@localhost ~]# find -inum 1632299
./test-file

Find the  file by inode number  and rename it
[root@localhost ~]# find -inum 1632299 -exec mv {} new-test-file \;
[root@localhost ~]# ls -il
1632299 -rw-r--r--  1 root root     0 2011-02-22 22:44 new-test-file

Now if we want to search files just one directory level down
[root@localhost ~]#find / -maxdepth 2 -name passwd
/etc/passwd

If we want to search files two directories level down
/usr/bin/passwd
/etc/passwd
/etc/pam.d/passwd

If we want to find the files between subdirectory level 2 and 4
[root@localhost ~]#find / -mindepth 2 -maxdepth 5 -name passwd
/usr/bin/passwd
/etc/passwd
/etc/pam.d/passwd

Find the files and execute commands on them

first we create some files with .tmp and .c extension in /tmp directory 
[root@localhost ~]#cd /tmp
[root@localhost tmp]# touch file{1,2,3,4}.tmp
[root@localhost tmp]#touch file{1,2,3,4}.c
[root@localhost tmp]#l
file1.c    file1.tmp  file2.cpp  file3.c    file3.tmp  file4.cpp
file1.cpp  file2.c    file2.tmp  file3.cpp  file4.c    file4.tmp

Now lets search .tmp files and remove them
[root@localhost ~]#find /tmp -name *.tmp -exec rm -fr {} \;

Find all the files which has rw permission to owner/user

[root@localhost ~]#find  /root -perm -u=rw -type f -exec ls -l {} \;

Find files world writable and list them
[root@localhost ~]#find /root -perm -o=rw -exec ls -ld {} \;

Find file which has 666 permission:


[root@localhost ~]# find /root -perm 666 -type f -exec ls -l {} \;
No result as no file with 666 permission

Let's create a file with with permission 666
[root@localhost ~]# touch file11
[root@localhost ~]# chmod 666 file11

[root@localhost ~]# find /root -perm 666 -type f -exec ls -l {} \;
-rw-rw-rw- 1 root root 0 2011-02-22 23:24 /root/file11









Thursday, January 20, 2011

DHCP Server

Dynamic Host Configuration Protocol
Works on following ports:
# cat /etc/services | grep dhcp
bootpc          68/tcp          dhcpc           # BOOTP client
bootpc          68/udp          dhcpc
dhcpv6-client   546/tcp
dhcpv6-client   546/udp
dhcpv6-server   547/tcp
dhcpv6-server   547/udp
dhcp-failover   647/tcp                 # DHCP Failover
dhcp-failover   647/udp                 # DHCP Failover
dhcp-failover2  847/tcp                 # dhcp-failover 2
dhcp-failover2  847/udp                 # dhcp-failover 2
qip-qdhcp       2490/tcp                # qip_qdhcp
qip-qdhcp       2490/udp                # qip_qdhcp

bootps          67/tcp                          # BOOTP server
bootps          67/udp

DHCP is used for allocating the IP Addresses Automatically i.e Dynamically.

DHCP Lease Allocation Process:
It is very important to understand the lease allocation process of DHCP.

Allocation process is done in following 4 steps:
1. DHCPDISCOVER message: Client requests the DHCP Server in the network in the form  of broadcast packet
2. DHCPOFFER message: Any of the available DHCP server gives response to the Discover message
3. DHCPREQUEST message: A client can receive DHCP offers from multiple servers, but it will accept only one DHCP offer and broadcast a DHCP request message
4. DHCPACK message: When the DHCP server receives the DHCPREQUEST message from the client, the configuration process enters its final phase. The acknowledgement phase involves sending a DHCPACK packet to the client. This packet includes the lease duration and any other configuration information that the client might have requested. At this point, the IP configuration process is completed.

Now we will configure the basic DHCP server which will allocate IP, Netmask,Gateway and DNS information to the cleint.This configuration has been tested on CentOS- 5.5 

First search for required RPMs
# rpm -qa | grep -i dhcp
dhcpv6_client-0.10-33.el5
dhcp-3.0.5-3.el5
dhcp-devel-3.0.5-3.el5
dhcpv6-0.10-33.el5

If not available install it using yum
# yum -y install dhcp*

Edit the /etc/dhcpd.conf file as given below :
# vim /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
option wpad-url code 252 = text;
one-lease-per-client true;
subnet 192.168.1.0 netmask 255.255.255.0 
{
option routers                               192.168.1.1; # Default Gateway
option subnet-mask                       255.255.255.0;
option nis-domain                         "example";
option domain-name                     "example.com";
option domain-name-servers         192.168.1.3;
option time-offset                          -18000; # Eastern Standard Time
option ntp-servers                          192.168.1.1;
option netbios-name-servers          192.168.1.1;
range dynamic-bootp                     192.168.1.102 192.168.1.220;
default-lease-time                           86400;
max-lease-time                               604800;
next-server                                     192.168.1.3;  # For PXE-Boot
filename                                         "pxelinux.0";     # For PXE-Boot

}
# We want Lisa to appear at a fixed address
#1.Lisa Dsouza
      host node03.example.com
              {hardware ethernet  00:21:97:2C:09:A5;
               fixed-address 192.168.1.108;
              }

Following two lines will be used(as in the above configuration file) if you are doing the over the  network installation using DHCP/BOOTP and NFS. This will be covered in my other posts.
next-server                                     192.168.1.3;     # For PXE-Boot
filename                                         "pxelinux.0";     # For PXE-Boot

Some of the other configurations would be :
  • Fail Over DHCP Server : Primary and Secondary DHCP Servers
  • Configuring the Multiple DHCP Servers on Multiple LAN cards serving multiple subnets
  • Configuring single DHCP server serving multiple subnets
  • Configuring DHCP Relay Agent
  • Configuring DHCP PXE-BOOT Server
Most of the above mentioned options/configurations will be posted soon.

Tuesday, December 21, 2010

Why Linux?

Linux is booming every where and we hear Linux every where.Many of you would like to know what makes Linux so special.Why not discuss " Why Linux?" or must say "What makes Linux best choice?" In short advantages of Linux are mentioned in this blog. One of the best method to know what makes Linux special is to use it yourself,explore it and feel the experience.So try Linux and you will never look back to any other OS, I am sure. From my personal experience I would explain the advantages of Linux:
  • Linux is open source.With open source end user has the flexibility to modify Linux's source code. In short the user has freedom  to modify source code which in turn imparts more power to the end user.
  • Linux is network friendly as the network of servers,clients and  workstations can easily be setup. Linux facilitates sharing of network,cpu,modem and other such devices very easily.
  • Linux is almost free and is a low cost OS as most of the compilers,document viewers,browsers and other such applications come free with the OS. End user doesn't have to gain software licences as much of its software come with the GNU General Public License.
  • You can very well customize the Linux kernel to suit your needs.You can even make Linux as small as 1.4 Mb which can fit on even floppy drive.
  • Linux is very Reliable and Backwards-Compatible
  • Linux being open source,open source communities fix the security  vulnerabilities very fast.
  • Linux is almost free form viruses, worms, spy-ware, and other kinds of malware plagues.You don't need to get the Anti-virus Licences.
  • Linux and other Unix-like operating systems are well protected and are designed to be secure.
  •  Linux provides high performance on workstations and on networks and can  it handle unusually large numbers of users simultaneously. 
  • Linux is stable as it doesn't need to be rebooted periodically and doesn’t freeze up or slow down over time due to memory leaks.
  • Linux has excellent X windows System which is very flexible.
  • Linux is Multitasking.
  • Linux supports almost all the platforms like x86, AMD64, Intel® 64 and Itanium.
  • Linux has good community support in the form of forums,blogs etc.
  • Some Linux flavours like Ubuntu  gets updated automatically with latest bug patches, security patches automatically. 

Thursday, December 9, 2010

Linux Distributions

Many people are curious about various Linux Distributions available.Some of the widely used Linux Distributions available in market are given below.Its worth reading about Red Hat distributions, enterprise and open source versions both.

Also vist http://www.distrowatch.com  for information on several hundred distributions

DistroWatch is a website which provides news, popularity rankings, and other general information about various Linux distributions 

RedHat Linux,Fedora,RHEL and Centos

  • Red Hat Linux
Red Hat Linux, assembled by the company Red Hat, was a popular Linux based operating system until its discontinuation in 2004 Red Hat Linux 1.0 was released on November 3, 1994. It was originally called "Red Hat Commercial Linux Red launched various other version like 2.0 3.0...8.0 and Red Hat Linux 9, the final release, hit its official end-of-life on 2004-04-30. Since 2003, Red Hat has discontinued the Red Hat Linux line in favour of Red Hat Enterprise Linux (RHEL) for enterprise environments.
  • Fedora
Fedora, developed by the community-supported Fedora Project and sponsored by Red Hat, is the free version best suited for home use. Red Hat Linux 9,the final release, hit its official end-of-life on 2004-04-30, although updates were published for it through 2006 by the Fedora Legacy project until that shut down in early 2007.
Fedora Releases
  • Fedora Core 1–4
  • Fedora Core 5–6
  • Fedora 7
  • Fedora 8
  • Fedora 9
  • Fedora 10
  • Fedora 11
  • Fedora 12
  • Fedora 13
Fedora Core v/s Fedora 

Starting with Fedora 7, there is no more Core, and no more Extras; there is only Fedora.That is the biggest difference between Fedora Core 6 and Fedora 7 was the merging of the Red Hat "Core" and Community "Extras" repositories,and the new build system put in place to manage those packages.This release used entirely new build and compose tools that enabled the user to create fully-customized Fedora distributions that could also include packages from any third party provider.
  • CentOS
CentOS(Community ENTerprise Operating System) is a community-supported, mainly free software operating system based on Red Hat Enterprise Linux. It exists to provide a free enterprise class computing platform.CentOS developers use Red Hat's source code to create a final product very similar to Red Hat Enterprise Linux. Red Hat's branding and logos are changed because Red Hat does not allow them to be redistributed.CentOS is available free of charge. CentOS provides Technical Support through official mailing lists, web forums, and chat rooms. 
  •  Scientific Linux 
SL is a Linux release put together by Fermilab,CERN and various other labs and universities around the world. Its primary purpose is to reduce duplicated effort of the labs, and to have a common install base for the various experimenters.This product is derived from the free &  open source software made available by Red Hat Inc., but is not produced, maintained or supported by Red Hat. Specifically, this product is built from the source code for Red Hat Enterprise Linux versions, under the terms and conditions of Red Hat Enterprise Linux's EULA and the GNU GPL.

The base SL distribution is basically Enterprise Linux, recompiled from source.Main goal for the base distribution is to have everything compatible with Enterprise, with only a few minor additions or changes.It allows easy customization for a site, without disturbing the Scientific Linux base. The various labs are able to add their own modifications to their own site areas. By the magic of scripts, and the anaconda installer, each site is to be able to create their own distributions with minimal effort. Or, if a users wishes, they can simply install the base SL release.

Wednesday, December 8, 2010

Various Linux Certifications

Certification in Today's world is a must.It sets you apart form all others. Certified IT pros have a  advantage over their colleagues. While holding a current IT accreditation is no guarantee against being laid off, the more education, expertise, and skills you can demonstrate, the better. Certification qualifies employees for higher pay grades.In cases where two otherwise equal candidates are competing for the same lucrative job offer, one applicant’s certifications could prove the deciding factor.

Various Linux certifications available in market are:

2. CompTIA

3. Linux Professional Institute 

4. Novell

6. Ubuntu 
Ubuntu Certified Professional (UCP)

My personal choice is LPIC and RHCE.

But please note that All the Red Hat Certifications are Performance based and needs rigorous training and practice.So until and unless you practice  much and  get hands on Linux dont go for Red Hat certifications.


Monday, November 29, 2010

History of Unix and Linux



Unix History : Unix  is a computer operating system  developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thosmpos, Dennis Ritchie, Brian Kernighan, Douglas McIlroy and Joe Ossanna.In 1965 AT&T bell Labs,MIT and General Electric developed operating system called MULTICS (Multiplexed Information and Computing System).Bell Labs dropped out of the Multics project in April 1969.AT & T employee Ken Thompson and Dennis Ritchie lead an OS team and continued to work on the same project and developed UNICS (Uniplexed Information and Computing System).


Later on it was named UNIX.In 1973 Unix was written in C.Soon more than 600 companies started using UNIX.AT&T made Unix available to universities and commercial firms, as well as the United States government under licenses. The licenses included all source code including the machine-dependent parts of the kernel.Soon other companies began to offer commercial versions of UNIX.Some of the companeis and their unix flavours which exist today also are: Sun SunOS Microsoft Xenix Santa Cruz Operation (SCO) SCO Unix HP HPUX IBM AIX Berkley BSD Cray Research UNICOS Silicon Graphics IRIX Apple MacOsX SUN Solaris.

Linux History: Linux is a free Unix-like operating system kernel created by Linus Torvalds and released under the GNU General Public License.Linux is an open-source version of the UNIX operating system. Actually we should call it GNU Linux rather than just Linux. Linux is the kernel, one of the essential major components of the system. Learn more about calling it  GNU/Linux here http://simplel4linux.blogspot.com/2010/11/call-it-gnulinux-not-just-linux.html. But as this is the first article for those whom want to know more about Linux,we will time being call it just Linux. 

Linux is a generic term referring to Unix-like graphical user interface (GUI) based computer operating systems based on the Linux kernel.Linux is freely-distributable implementation of UNIX that runs on a number of hardware platforms, including Intel and Motorola microprocessors.Linux has a reputation as a very efficient and fast-performing system.

Linux was invented by Linus Torvalds in 1991, when Torvalds was a student at the University of Helsinki in Finland.Linux derived Linux form MINIX, a non-free Unix-like system.MINIX (from "mini-Unix") was first released in 1987, with its complete source code made available to universities for study in courses and research. It has been free and open source software since it was re-licensed under the BSD license in April 2000.While studying Linux began writing his own kernel. He started by developing device drivers and hard-drive access, and by September had a basic design that he called Version 0.01.

This kernel, which is called Linux, was afterwards combined with the GNU system to produce a complete free operating system. On October 5th, 1991, Torvalds sent a posting to the comp.os.minix newsgroup announcing the release of Version 0.02, a basic version that still needed Minix to operate, but which attracted considerable interest nevertheless. The kernel was then rapidly improved by Torvalds and a growing number of volunteers communicating over the Internet, and by December 19th a functional, stand-alone Unix-like Linux system was released as Version 0.11.On January 5, 1992, Linux Version 0.12 was released, an improved, stable kernel. The next release was called Version 0.95, to reflect the fact that it was becoming a full-featured system. After that Linux became an underground phenomenon, with a growing group of distributed programmers that continue to debug, develop, and enhance the source code baseline to this day.

Torvalds released Version 0.11 under a free-ware license of his own devising, but then released Version 0.12 under the well established GNU General Public License. More and more free software was created for Linux over the next several years.Linux continued to be improved through the 1990's, and started to be used in large-scale applications like web hosting, networking, and database serving, proving ready for production use. Version 2.2, a major update to the Linux kernel, was officially released in January 1999. By the year 2000, most computer companies supported Linux in one way or another, recognizing a common standard that could finally reunify the fractured world of the Unix Wars. 

The next major release was V2.4 in January 2001, providing (among other improvements) compatibility with the upcoming generations of Intel's 64-bit Itanium computer processors.Although Torvalds continued to function as the Linux kernel release manager, he avoided work at any of the many companies involved with Linux in order to avoid showing favouritism to any particular organization, and instead went to work for a company called Transmeta and helped develop mobile computing solutions, and made his home at the Open Source Development Labs (OSDL), which merged into The Linux Foundation.
Linux Torvald's posting to the comp.os.minix newsgroup
 
Hello everybody out there using minix - I'm doing a (free) operating system(just a hobby,
won't be big and professional like gnu) for 386(486) AT clones... 
I'd like to know what features most people would want. Any suggestions are welcome,but I
won't promise I'll implement them :-) 
- Linus Torvalds; Posting to comp.os.minix; 25 Aug. 1991.

GNU, GPL & Creative Commons

As the heading suggest we will be learning about Unix, GNU, GPL, Linux & Creative Commons. Brief study of all these concepts is very much essential to know how the open source OS like Linux system works.

Operating System:

An operating system is the system software responsible for the direct control and management of hardware and basic system operations. It provides a foundation upon which to run application software.An operating system is conceptually broken into three sets of components: a user interface (which may consist of a graphical user interface and/or a command line interpreter or "shell"), low-level system utilities, and a kernel--which is the heart of the perating system.The shell is an outer wrapper to the kernel, which in turn talks directly to the hardware.  
Hardware <-> Kernel <-> Shell <-> Applications 

Open Source: 

It refers to any program whose source code is made available for use or modification.Open source software is usually developed as a public collaboration and made freely available. Open Source is a certification mark owned by the Open Source Initiative (OSI). Developers of software that is intended to be freely shared and possibly improved and redistributed by others can use the Open Source trademark if their distribution terms conform to the OSI's Open Source Definition. Open source provides software which has better quality, higher reliability, more flexibility, lower cost, and an end to predatory vendor lock-in. 

FSF: 

The Free Software Foundation (FSF) is a non-profit corporation founded by Richard Stallman on 4 October 1985 to support the free software movement,a copyleft- based movement which aims to promote the universal freedom to create, distribute and modify computer software.FSF catalog useful free software that runs under free operating systems — particularly the GNU operating system and its GNU/Linux variants. 

GNU:

GNU is short for "GNU is Not Unix".The GNU Linux project was created for the development of a Unix-like operating system that comes with source code that can be copied, modified, and redistributed. Richard Stallman announced the GNU Linux project in 1983 and, with others,formed the Free Software Foundation in 1985.The philosophy behind GNU is to produce software that is non-proprietary. Anyone can download,modify and redistribute GNU software.

GPL:

The GNU General Public License (GNU GPL or simply GPL) is a widely used free software license, originally written by Richard Stallman for the GNU project.The GNU General Public License is a free, copyleft license for software and other kinds of works.General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs.Learn More about GPL here: 

GPL 3: 

Learn more about GPL3 at http://gplv3.fsf.org/

Creative Commons: 

It is a nonprofit organization that allows artists, authors, publishers and musicians the option of creating and defining a flexible copyright for their creative works. Creative Commons was officially launched in 2001 by a group of intellectual property experts, lawyers and web publishers. Creative Commons licenses cover art, music, and writing, but is not designed for software.A Creative Commons license allows creators to place conditions on their copyrights. Traditionally, copyrights restrict the rights of others from modifying or distributing copywritten works. Creative Commons licenses offer flexibility by allowing the creator (copyright holder) the ability to choose what limitations they want in place with respect to specific copywritten works.With CC you are free:
  • to Remix — to adapt the work

Under the following conditions:

Attribution You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).