Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

2009

RAHULGUPTA

[ REDHATLINUXRHEL5SERVER ]
INTHISFILEIWILLTELLYOUALLABOUTLINUXBASICCOMMANDSANDSERVERS

INDEX

1.
2.
3.
4.
5.

6.

HistoryofLinux
LINUXPRINCIPLE
LinuxDirectoryStructure
INSTALLATION
LinuxBasicCommands
a. Directorycommands
b. FileCommands
c.

Hi storyo f Linu x
In1969,FourprogrammerKenThompson,DennisRitchie,RuddCanady&DougMcElroymadea
programinBelllabswhichdoesnothaveanynameinyear1969.

Brian Kernighan checked that program & found it is very good so]ware for client & networking
purpose.HegavethenameUnixtothisprogramon1stJanuary1970(epochbme).FirstOperabngSystem.
ThatbmethatprogramwaswrideninAssemblylanguage.

In1972,aprogrammerDennisRitchiestartedconverbngthisprograminClanguage.(Alsocalled
founderofClanguage).

1973UnixinClanguage.

1980 Berkeley So]ware Development (a part of research program of Berkeley University)


launchesopenBSD(asmallprogramwrideninasingleoppy).

PaulAllen&BillGatesaretheemployeeofBellLabs.

In 1981, they both started Microso] with 9 more candidates & they gave a programme named
Xenix(1980)butitwasopped.

In1981LaunchedMSDOS1.0

In1984UNIXopensource

In1985FirstGraphicalBasedOSWin2.0

In 1991, Linus Benedict Torvalds, Btech Iind year Computer Science, 23 years old student of
UniversityofHelensiki(Finland)madeKernel(25thAugust1991).

In1994RedHatCompany(collecbonofLinuxSets)cameintoexistence.

96.8%serversofLinuxbll2009.

LINU X PRINCIPLE

1.
2.
3.
4.
5.

Everythingisale.
Small,singlepurposeprogrammers.
AbilitytoChainprogrammerstogethertoperformcomplextasks.
Avoidcapbveuserinterfaces.
Congurabondatastoredintext.

Linu xDi re ctory Stru cture


1. /home

2. /bin

3. /usr/bin
4. /sbin,/usr/sbin
5./usr/local/bin
6./etc

7./boot

8./root

9./mnt,/media
10./dev

11./var,/svr
12./proc,/sys
13./lib/usr/share

Usershome(allusersfolders)
Commands(userexecutable&Scripts)
Commands(userexecutable&Scripts)
rootprivilegedcommand
commandswhichwemakeforouruse.
SystemCongurabonles
LinuxKernel&Bootableles
root(Admin)Data
formounbnganyexternaldevices
devices(hdd,CDRom,PenDrive)
Serverdata
SystemInformabon
Librarylesstored

INSTALLATION

HereIwilltellyouinstallabonrelatedrequirementsandles.(notwholeinstallabon).

Linuxusesext2&ext3lesystem.
BootloaderoflinuxGRUB(GrantUniedBootLoader)new&LILO(LinuxLoader)old.

BootfromCDorDVD

Therearemanytypesofmethodofinstallinglinux

1. SimpleGraphicalmethoditwillaskforaEnter
2. Textbased inthisyouhavetowritelinuxtextorlinuxaskmethod(fromthisyoucanalso
installfromNFS)

MinimumrequirementforGraphicalinstallabonx86processor,256MBRAM.

ParbbonCreatedatthebmeofinstallabon

Partition Name
File System
Used for
Minimu m Siz e
/
ext3
linuxlesystem
6000MBor6GB
/boot
ext3
Linuxboobngles&kernel
75or100MB
/home
ext3
Linuxusersentry
Itsuponyou
/swap
Swap
Usesasvirtualram
DoubleofRAM

Linuxcansupportmaximum63harddiskIDE&15SATAHarddisk.

InLinux7userscanloginatthesamebme.

IstUser

Atl+Ctrl+F1
nd
th

II toVI user
Alt+Ctrl+F2toF6

Graphicaluser
Alt+Ctrl+F7

LINUXBOOTPROCESS

Linu xBasi cCo mm and s

Directorycommands:

1.
2.
3.
4.

#mkdir
#cd
#cd..
#rmdir

Forcreabngdirectory.
changedirectory.
tocomeoutfromworkingdirectory.
toremovedirectory

FileCommands:

1.
2.
3.
4.
5.

#touch<lename>
#cat>lename
#cat

#catle1>>le2
#catnlename

createsablankle.
createsaleandforsavingthisle(ctrl+D)
toseethecontentofthele.
tomovele1maderinle2
toseehowmanylinesarewrideninthatle.

Commandsfordeleb ng:

1.
2.
3.
4.

#rmlename
#rmi
#rmr
#rmf

deletesale.
deletesle/folderininteracbvemode(askingmode)
deletesdirectory.
deletesles/foldersforcefully.

HelpCommands:

1.
2.
3.
4.
5.
6.

#whabs<command>
#man<command>

#info<command>
#<command>help
#which<command>
#cd/usr/share/doc

Theseallarethehelpcommands.Printsallrelatedtags
aboutthatcommand.

Rename&Move:

1. #mv<oldle><newle>

2. #mv<lename><wherewehavetomovethele>

(Rename)
(Move)

Lisb ngCommands:

1.
2.
3.
4.
5.

#ls

#lsl(ll)
#lsa
#ls???
#lsm*

lisbngles/folders
longlisbngofles/folderswithwholeinformabon
listsallles/folders(hiddenalso)
allles/foldersnamedwith3characters
les&directoriesstartedwithlederm.

Copy:

1.
2.
3.
4.

#cp<source><desbnabon>
copieslesfromsourcetodesbnabon
#cpi<source><desbnabon>
copieslesfromsourcetodesbnaboninaskingmode
#cpi*<desbnabon>

copiescurrentworkingdirectoryalldatatodesbnabon.
#cpr<directoryname><desbnabon>copiesdirectoryfromsourcetodesbnabon

Editorsinlinux:

1.
2.
3.
4.
5.
6.

nano
vi

vim
gvim
gedit
Emacs

Theseeditorsareusedinconsolemode.

Theseeditorsareusedingraphicalmode.

VIeditor/VIMeditor:

Therearethreemodesinvieditors
1. exmode
(defaultmode,bypressingescapekey,thismodeisusedforsavingandexit)
2. Insertmode (bypressinginsertorIkey,thismodeisusedforedibng)
3. Replacemode (thismodeisusedforreplacingtextwriden,byagainpressinginsertorrkey)

Forsavingdocumentcomeonescmodeandwrite: w q
Forsetnglinenumbersindocumentcomeonescmodeandwrite: se nu
Forcomingonanyspeciclinepresslineno.andthenG (ex102thenG)
ForgoingattheendofpagepressG
Forgoingatthetopofpagepressgg

Vimeditorisnotinstalleddefaultwhenyouinstalllinux,youhavetoinstallvimeditor.Itisthe
enhancedversionofvieditor.

#vim/vilename

Pressvtocometovisualmode,herewecanselectthemaderwhichwewanttocopy,pressyy
tocopy(ystandsforyank).Pressptopastethatmader.

Pressddtodeleteaparbcularlinewherecursoris.

NanoEditor:

Nanoisacommandbasededitor,earlierusedwhenadvancededitorswerenotcameintobeing.
Whenyouopenaalewiththiseditor,youwillndallrelatedhelpofthiscommand.

SOM EBAS ICCOMMA NDS

1. #powerof
2. #haltnp

Thesecommandsareusedtoturnocomputer.

ThesecommandsareusedtoRestartcomputer.

6. #startx

Switchfromcommandtographic.

7. #init5

Restartssystemfromcommandmodetographicmode.

8. #history

Toseehistoryofrecentcommands.

9. #historyc

Toclearthehistoryofrecentcommands

10. #cat>/etc/issue

Tocreatelogoscripts.

11. #cat>/etc/motd

Tocreatelogonscripts.

12. #calyyyyormmyyyy

Toseethecalendarofthatmonth&year.

13. #bc

3. #init0
4. #init6
5. #reboot

Startsbasiccalculator.

14. #whoiamor#w

Toknowbywhichuserweloggedon

15. #adduser<username>

Tocreateuser

16. #passwd<username>

Togivepasswordtouser.

17. #usermodL<username>

Tolockauseraccount.

18. #usermodL<username>

Tounlockauseraccount.

19. #passwdd<username>

Toremovepasswordforauser.

20. #cd~

Switchdirectlytousershomedirectorywith.

Toseethetoptenlinesofale.

22. #headn16<lename>

Toseetop16linesofale.

23. #tail<lename>

Toseethebodomtenlinesofale.

24. #tailn16<lename>

Toseebodom16linesofale.

25. #evince<lename.pdf>

Toopenapdfle(onlyongraphicalterminal)

26. #sort<lename>

Shortleinazformat.

27. #sortd<lename>

Shortleindicbonaryformat.

28. #sortr<lename>

Shortleinzaformat.

21. #head<lename>

29. #cat<lename>|trazAZ

Translateleinallcapitalleders.

30. #wc(l/w/c)<lename>

Wordcount(lforline,wforword,cforcharacter)

10


31. #dile1le2

Toseedierencebetweensamelookingles.

32. #blkid

Toseedeviceid(exhda1,sdb).

33. #mkfs.vfatI/dev/deviceid

Toformatdeviceinfatformat.

34. #aspellc<lename>

Tocheckspellinginale.

35. #neat

Toopennetworkcongurabonongraphicterminal

36. #ifcong

TochecktheIP&MACaddressofNIC.

37. #ifcongeth0<ipaddress>

ToassigntemporaryIP

38. #ifupeth0

Toenablenetworkcard.

39. #ifdowneth0

Todisablenetworkcard.

40. #vi/etc/syscong/networkscripts/ifcfgeth0

41. #vi/etc/syscong/networking/devices/ifcfgeth0

ToassignpermanentIP,herewe

havetoeditale.

42. #ethtooleth0

Tocheckgraphicallywhethercableisconnectedornot.

43. ##dfh<parbbon>

Tocheckthefreespaceofaparbbon.

44. #ping(c2,a)<ipaddress>

Tocheckconnecbvity(c2forseeingtwolines,alisbng)

45. #look<word>

Forlookingtheexactwordspelling.

46. #datemmddhhmmyy

Tosetdate.

47. #ps

Tochecktheprocessingstatus.

48. #kill9PID

Tokilltheserviceno.9.

49. #top

Fulldetailsofallprocessing&theirID.(kkill,hhelp)

50. #wget<website>

Todownloadthewebsitehomepage.

51. #elinks<website>

Toopenwebsiteincommandline.

52. #xterm

Startsanewsubterminal.

53. #mud

TosendmailinaNISorsinglePCbetweenuser&root

Tocheckhowmuchparbbonisused.

55. #ln/home/rahul/rahul

Itwilllinktheleinhomenamerahulwithrahul(inroot)

56. #seq11000>/home/rag

Itwillcreatealenamedraghavingno.1to1000.

57. #uname

Toseekernelname.

58. #unamer

Kernelrelease.

59. #unamea

Wholeinformabonaboutkernel.

60. #nd/name<lename>

Searcheslein/.

61. #ndperm775

Searchesforleshavingpermission775.

62. #ndsize512k

Searchesforlesof512k

54. #duh<parbbon>

11


63. #ndname*.htm

Searchesleshavingextension.htm.

64. #zcat<lename.gz>

Toseethecontentofcompressle.

65. #chkcongon/o<service>

Toon/oanyservicepermanently.

66. #lsmod

Listofdriversrunning.

67. #modinfo

Detailsaboutrunningdriver

68. #sysctlnkernel

Toupdatekernel.

69. #tmpwatch

Showstemporaryles.

Itwilldisplayfullinformabonaboutthatleordirectory.

70. #ge|acl<lename>

71. #se|aclmu:<user>:rwx/ww

Itwillsetthefulluserpermissiononwwdirectory.

72. #mount/dev/cdrom/mnt

TomountCDROM.

73. #mount/dev/devicename/mnt

Tomountanyexternaldevice.

74. #mounttvfat/dev/parbbon/mnt

Tomountfatparbbon.

75. #userdel<username>

Todeleteuser.

76. #groupadd<name>

Toaddagroup.

77. #groupdel<name>

Todeletegroup.

78. #cat.bash_history

Toseehistoryofcommands(a]erexecubnghistoryc)

79. #cat>.bash_history

Toremovehistoryofcommands

80. #chageEYYYYMMDD<user>

Setuserexpirabon.

81. #chagel<username>

Toseeuserdetailedinformabon.

82. #chageW1<username>

Tosetwarningperiodforuser.

83. #le<le/directoryname>

Tocheckwhetheritisleorfolder.

84. #cutf1d:/etc/passwd

Itwillshowtherstcolumnofpasswdle.

85. #usermodG<group><user>

Itwilladdusertogroup.

86. #idusername

Toseetheidofuser.

87. #adduserg<group><user>

Toaddnetworkuseringroup.

88. #command|teestages.out

Itwillgivetheoutputofcommandinlenamestages.out.

89. #less<lename>

Toseealepagewise.

Tondaparbcularwordorstringinale.

90. #grep<word><lename>

91. #grepn<word><lename>

Toseethelinenumberinwhichthatwordis.

92. #tarcvf<name><lesname>

Itwilltakethebackupoflesasasinglele.

93. #tartvf<name>

Showhowmanyles&theirnameinthebackuple.

94. #tarxvf<name>

Restorethebackup.

12


95. #gzip<lename>

Itwillcompressale.

96. #bzip2<lename>

Itwillcompressale.

97. #gunzip<lename>.gz

Itwilldecompressale.

98. #bunzip2<lename>.b2z

Itwilldecompressale.

99. #ssh<ipofremotePC>

Itwilltakecontrolofremotepc(askforpassword)

100.#scp/root/proxy.exe10.0.0.1:/root

Tosendanyleinnetwork.

101.#scprv<source><desbnabon>

Tosendanydirectoryinnetwork.

102.#tunetofsj/dev/parbbon

forconverbngext2toext3

RPM(RedH atPacka geMana ger )

PackageNameVersionTypeofExtension

xmms1.2.109.i386.rpm

architecture

#rpm<opbons><packagename>
#rpmivh<packagename>

aid

(installpackagealongwithdependencies)

force

(forcefully)

nodebs

(toremovepackagealongwithdependencies)

#rpme<packagename>

(Touninstallpackage)

(upgradethepackage)

#rpmq<packagename>

(Showwhetherpackageisinstallornot)

qa

(queriesallinstalledrpmpackages)

qc

(listsonlythecongurabonlesstoredinthequeriedpackage)

qd

(listsonlythedocumentabonlesstoredinthequeriedrpm)

qi

(displayswholeinformabonaboutthequeriedrpm)

qs

(displaysthestatesoflesinthequeriedrpm)

ql

(displaysalllesrelatedtothequeriedrpm)

13

BREAKINGPA SS WORD& PASS WORDSECU RITY

Bre aki ng root passw ord:


WhensystemasktoselectOS,herepresse.
ChoosethesecondopbonKernel/vmlinuz2.6.i8,againpresse.
Write1atthelastoftheline,
Thenpressesckeyandthenb.
Nowsystemwillrebootandstopsonsingleusermode
sh#
heretypepasswd,thenenter
typenewpassword
nowreboot&giverootandnewpassword.

Passw ord Sec urit y (adding passw ord ong rub a] e r i nstall ab on):
{ongraphicalterminal}
#grubmd5crypt
Password:
Conrmpassword:
(Hereyouseesomedigits,copythosedigits)
Noweditlegrub.conf
#vi/boot/grub/grub.conf
Hereyouseealinewherewridenhiddenmenu,comeunderthatlineandtype
Passwordmd5{pastethosedigits}
Savele.
Nowyourpasswordcannotbebrokenonstartup.

14

PERM ISS IONS

__________ owner group lename


f/dUsergroupothers

r=4(22)

w=2(21)

x=1(20)

read

write

execute

For di rect ory m ax im um pe rm i ssi on=777


For l e sm axi mum permi ssi on=666
To gi ve userfull pe rmi ssi on
#chmod777lename

Defaul t pe rmi ssi on for l e=644


Defaul t pe rmi ssi on for di re ct ory=755
To see t he i nte rnal pe rm issi on
#umask(maxper.umask=defaultpermission)
#umask000(fullpermissionforall)
#umask777(denyforall)

To change the ow ne r of le s or direct ory


#chown<username>le/directoryname
To change g roup of l es & di rect ory
#chgrp<groupname>le/directoryname

EveryuserhasitsownUID(UserIdenbcabon)
EverygrouphasitsownGID(GroupIdenbcabon)
IfUIDmatches(i.e.loginuser&owner)userpermissionisapplicable.
IfGIDmatches(i.e.loginuser&group)grouppermissionisapplicable.
Ifnothingmatchesotherpermissionisapplicable.

15


TocheckUID/GID
#cat/etc/passwd

(UIDforroot=0,UIDforuserstartsfrom500)

Fi le s w he reUI D & GI D i nformab on sav e d


/etc/passwd

(UID)

/etc/shadow

(UIDinencryptedform)

/etc/group

(GID)

/etc/gshadow (GIDinencryptedform)

BASH SHE LLP ROGRA MM ING

Bythiswecanmakeascriptofanyserverandrunatbmewewantit.
#mkdir~/bin
#cd/root/bin
#vitest.sh(typethefollowinginthele)
#!/bin/bash
mkdir/repo
cd/repo(writecommandinasequenceofitsuse)
:wq

#chmodu+xtest.sh(togiveexecutablepermissiontole)
#test.sh(torunthatle)

Todisplaythecontentonthescreen
#echowhatisyouripaddress$(ifcong)
#aliasR=ifcong
#echowhatisyouripaddress$(R)

16

RU NLEV EL(INIT)
Toeditorseeinitlevel
#vi/etc/inidab
0=shutdown
1=singleusermode
2=mulbusermodewithoutNFSsupport
3=fullmulbusermode
4=notused
5=Graphical(x11)
6=reboot
Ifoursystembootsongraphicalandwewantthatoursystembootoninit3default,wechangethe
followingline
Id:5:initdefault(herewechange5with3)

Looping commandf ormaki nguser s

#forUSERinname1name2name3name4name5
>do
>useradd$USER
>echoredhat|passwdstdin$USER
>done
Nowitwillcreateveusersnamedname1,name2,name3,name4,name5withpasswordredhat.

CRONTA B
#crontabeuusername
*/1****

echoHello>/dev/dy2(min,hour,date,month,day)

Savele.
#servicecrondrestart (nowwhenuserloginon2ndterminalitwillgetmessagehelloa]erevery1min.)
#crontabluusername(toseehowmanycrontabarerunningforuser)
#crontabruusername(deletesthecrontab)

17

PARTIT IONS

Creabngnew/homeparbbon

#fdiskl

(forcheckingtheposibonofharddiskparbbons)
#fdisk/dev/hda
(toassignwholeharddisk)

IDE0 PrimaryMaster
hda

PrimarySlave
hdb
IDE1 SecondaryMaster
hdc

SecondrySlave
hdd

:n
(nforcreabngnewparbbon,enter)
Againenter
Nowgivethesize(ex10000M)
:w
(wforsave,dfordelete)

#partprobe(orrestart)

Nowtoformatthisparbbon

#mkfs.ext3/dev/hda7
(whateverparbbonyouhavemade)

Nowtomountthisparbbon,makeafolder(ex/home)

#mount/dev/hda7/home
(butthisistemporarymounbng)

Forpermanentmounbng

#vi/etc/fstab

(nowdothefollowingentryinthele)

/dev/hda7
/home
ext3 default
12

Savethele.

(nowifyouhavepermanentlymountedtheparbbonandnowyouwanttodeleteparbbonrstlyremove
theentryfromfstab,otherwiseyoursystemwillbedump)

18

CreabngSwapParbbon

Firstlyifthereisswapparbboninyoursystem,stopswap

#freem
(tocheckswapisworking)
#swapons

(tocheckswapisonwhichparbbon)

Firstremovetheentryofswapfromfstab
#fdisk/dev/hda
(deleteswapandreboot)
Nowcreate
:n
:l

(forseeingtheswapcode)

:t

(togivecode)

Parbbonno:5
Hexcode:82(forswap)
:w(save)

#partprobe
#mkswap/dev/hda5 (tomakeparbbonswap)
#swapona/dev/hda5
#e2label/dev/hda5hda5swap

(togivelabeltoparbbon)

Nowinfstab
LABEL=hda5swap

swap swap defaults

00

:wq(save)

Nowrebootyoursystemandyouwillndanewswapparbbon.

19

RAID
Raidareoftwotypes
1. So]wareRaid
2. HardwareRaid

Herewewilllearntoimplementso]wareRaid(Raid1,Raid5)
MD(Metadisk)(whenmanyharddiskmakesadisk)
Firstcreate4(exhad7,8,9,10)parbbonofequalsize.
Now, for R aidlevel5 (m inim umt hre e harddi sk)
#mdadmC/dev/md0n3/dev/had{8,9,10}l5
raidlevel5)

To form at t he m d0
#mkfs.ext3/dev/md0

Now m ountm d0 i n a fol de r


#mkdir/raid
#mount/dev/md0/raid

To chec kt he st at us of rai d de vic e s


#mdadmD/dev/md0
#cat/proc/mdstat

To m ak e any parb b on fault y


#mdadmf/dev/md0/dev/hda10

To rem ove t he parb b on from rai d


#mdadmr/dev/md0/dev/hda10

To add new parb b oni n rai d array


#mdadma/dev/md0/dev/hda7

20

(bythiscommandwehavesuccessfullycreated

To st op the rai d
#mdadmS/dev/md0

Beforestopping,wehavetounmountraid

To acb v at e rai d
#mdadmA/dev/md0/dev/had{7,8,9}
(mountbeforeacbvabng)

NowforRAIDlev el1(Mirroring) (minimumtwoharddiskrequired)


#mdadmC/dev/md0chunk=64level=1raiddevices=2/dev/had{6,7}

Nowformat&mountsameasabove.

LV M{LOGICA LVOLUME MA NA GER}

InLVM,parbbonsspacearemergedlogicallynotphysically.
Makeparbbonsofsamesize(100mb2parbbons)

Fi rstc re ate P hysic al Vol ume (PV)


#pvcreate/dev/hda5/dev/hda6or
#pvcreate/dev/hda{5,6}
#pvdisplay

(toseewhetherpviscreatedsuccessfully)

Nowc re ate Vol um e Group


#vgcreatevg0/dev/had{5,6}
#vgdisplay

(200mb)

(toseewhethervgiscreatedsuccessfully)

Now we wi ll cre at el ogic al v ol ume


#lvcreateL+50M/dev/vg0nlv0

(itwillcreatealogicalvolumeof50Mb{52Mb})

21


To e xte nd t he l ogi calv ol um e
#lvextendL+25M/dev/vg0/lv0

(itwillextendthelogicalvolumetoapprox.80Mb)

To re duce t he l og ic al v ol um e
#lvreduceL25M/dev/vg0/lv0

(itwillreducethelogicalvolumeto25Mb)

USERQUOTA

Firstlyeditle/etc/fstabforaddingquotaforusers
#vi/etc/fstab
LABEL=home

/home

ext3

defaults,usrquota

00

Savethele

#mountOremount/home

(remounthomeparbbons)

#quotacheckcu/home

(tocheckwhetherquotaisappliedornot)

#quotaon/home

(tostartthequota)

Now,addtwousersandeditleforuser
#edquotauser(editthisle) or
#setquotauser5125124050/home
Itwillsetquotafortheuserthathecanonlyuse512kbofhomeparbbonspace.

#quotao/home

(tostopquota)

22

PRINTE RC OMMA NDS

ThesecommandsarecalledCUPS(CommonUnixPrinbngSystem)
1. #systemcongprinter

ToinibalizePrintergraphically

2. #lpstat

Tocheckthestatusofprinter

3. #lprm<jobid>

Tocanceltheprinbng

4. #lpq

Tochecktheprinbngqueuestatus

5. #a2ps

ChangenormaltexttoPostScript

6. #ps2pdf

Changespostscripttopdf

Sendsprinbng

7. #lpr<lename><Printer>

SOM EIMP ORTANT F ILES & C OMMA NDS

1. #vi.bashrc

(Thisishiddenle&usedtocreateshortcutsforcommands)

aliasc=clear
aliasm=mkdir
savethele
bytypingtheabovewordsitwillcreateshortcutforclearandmkdir(c&m)
buta]eredibnglerstlogout&againlogin.

2. #vi/var/log/messages (showsauditmessages)
3. #vi.exrc
:senu

(wehavetocreatethisle)

(writethisinthele)

Savethele
A]ersavingleyouwillndlinenumbersalreadywridenineveryleyouopenforedibng.

4. Forreplacingmanywordsinale(forexifwehavemadeale,inthatlemanybmesdogword
iswridenandwewanttoreplaceworddogwithcat)
Openlewithvieditorandonesc.Modetype

23


:%s/dog/cat/g
5. #seds/dog/cat/glename

(showlewithreplacedword)

6. $su

(onuser,askforrootpasswordandactasroot)

7. #suusername

(movesdirectlytouseranditsdirectory)

8. #lsR

(Showallles&directoryintreeorder)

(historyofcommandswhichyouhaveexecuted)

(herewecanchangetheOSselecbonbme)

9. #vi.bash_history
10. #vi/boot/grub.conf
bmeout:50

savethele.

SUDO

Bythiswecangiveuserpermissiontorunaparbcularcommandorcanrunallrootprivilegedcommand.
#vi/etc/sudoers

(inthislewehavetoeditthele&writetheusernameunderthefollowingline)

## Al l ow root t o runanyc omm andsanyw he re

root ALL= (ALL )

ALL

use r ALL= (ALL )

ALL

(herewritetheusernametowhomyouwanttogivepermissiontorunrootprivilegedcommand)
(NoteeditthislecarefullyotherwiseyourOScouldbecorrupt)
Nowloginwiththatuser
$sudo<rootprivilegedcommand>
Password

(giveuserpassword)

24

25

YUM(YELLOWDOGM ODIFIE R)SERV ER


WhenweinstallRPMitwillaskfordependenciesbutwhenweinstallanypackagewiththehelpofyumit
willinstallalldependenciesbydefault.
FormakingYUMwehaveto
1. Createafoldernamedre po
2. MountCDROM(#m ount / dev /c drom /m nt)
3. CopyServer,Cluster,ClusterStorage,VTfromDVD/CDofRHEL5
(# c pR v f Se rve r Cl ust erCl ust e rSt orage VT /v ar/ re po)
4. Pasteitinfoldernamedre po
5. Deleterepodatanamedfolderfromallthefourfolders.
6. Createalenamedbase.repo
#v i /et c/ y um. re pos. d/ base . re po

[base]
name=base
baseurl=le:///var/repo/Server
enabled=1
gpgcheck=0

[Cluster]
name=Cluster
baseurl=le:///var/repo/Cluster
enabled=1
gpgcheck=0

[ClusterStorage]
name=ClusterStorage
baseurl=le:///var/repo/ClusterStorage
enabled=1
gpgcheck=0

[VT]
name=VT
baseurl=le:///var/repo/VT
enabled=1
gpgcheck=0

26

(savethele)

7. Editalenamedrheldebuginfo.repo

#v i /et c/ y um. re pos. d/ rhel de bugi nfo. re po


(Inthisleenabled&gpgcheckmustbe0)
8. Now,editthisle
#v i /et c/ y um. c onf
(Herealsoenabled&gpgcheckmustbe0)
9. Now,editlastle
#v i /et c/ y um /pl ugi nc onf. d/ rhnpl ug in.c onf
(Herealsoenabled&gpgcheckmustbe0)
10. Nowwehavetogrouplestocreaterepodata
11. Installstandaloneservice
# rpm iv h /m nt / Se rve r/c re at e re po0 .4.42. fc6. noarc h.rpm
12. #c re at e re pog /m nt / Se rve r/ re podat a/c om psrhel5 serv erc ore. xm l
/v ar/ repo/ Serve r
13. #c re at e re pog /m nt /C lust e r/ re podata/c om psrhel5c l ust e r. xm l
/v ar/ repo/C l ust e r
14. #c re at e re pog /m nt /C lust e rSt orage / re podata/ c om psrhel5c l uste r st. xm l
/v ar/ repo/C l ust e rSt orag e
15. #c re at e re pog /m nt / VT/ re podata/c omps rhel5v t. xml / v ar/ re po/ VT
16. #y umcl e an all
17. #y uml ist all
18. Nowinstallpackagefromcommand
#y umi nst al l< pac k ag e nam e>
19. Touninstallpackage
#y um re m ov e < pack ag e nam e >
20. Nowongraphicsyouwillndadd/removeprogramandallpackagesaretheretoinstall.

27

SQUIDSE RVE R(Pr oxyinLINUX)

Squidservercontrolsclientscomputersaccesstotheinternet.

Itblockstheusersfromaccessingundesirablewebsitesandhidestheinternalidenbtyof
thenetwork.

ItimprovesperformancebystoringWebPageslocally.

Itisgenerallyusedtoshareinternetfromonemachinetoseveralclients.

SquidserveriswidelyusedasProxyserverbecauseitprovidesmanyfeatures&isanopen
source.

Pac k ag e s re qui re d:

Squid2.6.STABLE64.el5.i386.rpm
Port N um be r:
3128(default)
Con g urab on Fil e:
/etc/squid/squid.conf
Servic e / Daem on:
squid
Forsquidyoursystemmusthavetwolancardoneforinternetline&otherforyourprivate
network.

1. #yuminstallsquid*

or

#rpmivhSquid2.6.STABLE64.el5.i386.rpm
2. Editle
#vi/etc/squid/squid.conf (inthislesetlineno.&remove#anddofollowingchanges)

Line no. 73
hdp_port3128
Line no. 993
Cache_dirufs/var/spool/squid10016256

28


Line no. 1079
access_log/var/log/squid/access.logsquid
Line no. 1087
Cache_log/var/log/Squid/cache.log
Line no. 1097
Cache_store_log/var/log/squid/squid.log
Line no. 2522
aclour_networksscr192.168.1.0192.168.2.0/24 (herechangewithyournetworkrange)
Line no. 2523
hdp_accessallowour_networks
Line no. 2778
cache_mgrrahulguptamd1988@gmail.com(changewithyouremailaddressorname)
bydoingthesecongurabonyourinternet
Now forA cce ssl ist
Line no. 2409
(thereyouwillndtypedaclC ONN ECT met hod C ONNEC T,typeunderthatline)
acl<anyname>url_regex<Websitesyouwanttoblockorinibals,downloadings>
(aclxyzurl_regexorkutmp3downloadingwww.gmail.com)
hdp_accessdeny<abovename>(xyz)

or

aclxyzurl_regexwww.google.com

(Onlythiswebsiteyouwantyourclienttoaccess)

hdp_accessallowxyz
hdp_accessdenyall

(savethele)

4. #netstattulpn|grep3128

(tocheckwhethersquidisworkingornot)

5. #vi/var/log/squid/access.log

(toseetherecordofwebsiteopenedbyclient)

3. #servicesquidrestart/reload

6. NowonclientPC

Re dhatFireFoxeditmenupreferencesconnecbonsetngManualProxysetngProxy
ServerIP__________Portno.3128check(usethisproxyforallprotocols)
On Wi ndows: InternetexplorerToolsInternetOpbonsconnecbonsLanSetngcheck
(useaproxyforthislan)GiveIP&Portno.OK.

29

DHCP( DYNAMICH OST C ONF IGURAT IONPROT OC OL)


SERVER

ItprovidesIPaddressautomabcallytotheclientswhichrequestforanIPaddress.

CentralizedIPmanagement

DHCPpreventsIPaddressconictsandhelpsconservetheuseofclientIPaddresson
thenetwork.

DHCPreducesthecomplexityandamountofadministrabveworkbyassigningTCP/IP
congurabonisupdatedautomabcally.

Pac k ag e s:
dhcp*
Port num be rs:
67Bootp,68DHCP
Con g urab on l e:
/etc/dhcpd.conf
Servic e / Daem on:
dhcpd
1. Installdhcppackage
#y umi nst al l dhc p*
# rpm iv h dhc p*

2. Copydhcpcongurabonle
#c p / usr/ share/ doc / dhc p3.0. 1/ dhc pd.c onf.sam pl e / etc /dhcpd.c onf

30

3. Editthisle
#v i /et c/ dhc pd. c onf
Subnet192.168.1.0

netmask255.255.255.0

example.com

Opbondomainname

Opbondomainnameservers
rangedynamicbootp

192.168.1.1;

192.168.1.10192.168.1.20;

hardwareethernet __:__:__:__:__:__
xedaddress

192.168.1.16

(savele)

In this le we have to give our network range, domain name & its IP (opbonal), range of IP
providedbyDHCPandifwewanttoxanyaddressforspecicuserwecanreserveIPforthat
withthehelpofMACaddress.

4. # se rvic e dhc pd re st art


5. Now on client set the TCP/IP setng on obtain an IP address automabcally & obtain DNS
serveraddressautomabcally.

31

DNS (DOMAINNA MESYSTEM)

HostleprovidesresolubonofhostnamestoIPaddress.Itcanonlyresolvethenamesprovide
inthelocalhostle.Itcannotbeusedascentraldatabase.Youcanaddthename&Ipaddress
in/etc/hostsle.
#vi/etc/hosts
#Donotremovethefollowinglineorvariousprograms
127.0.0.0

localhost.localdomain

localhost

192.168.1.1

rahul.com

server

(savethele)

DNS
ProvidesresolubonofnamestoIPaddressandresolubonofIPaddresstonames,denesa
hierarchicalnamespacewhereeachlevelofanamespaceisseparatedbya..
ZoneZoneisastoragedatabasewhichcontainsallzonesrecords.
Forward l ook upz one:UsedtoresolvehostnametoIPaddress.ItmaintainshosttoIP
mappinginformabon.
Ty pe s of R ec ords:
SOARecord:
NSRecord:
Arecord:
CNAMERecord:
PTRRecord:
MXRecord:

Therstrecordinanyzonele.
IdenbestheDNSServerforeachzone.
ResolvesahostnametoIPaddress.
Resolvesanaliasnametoahostname.
ResolvesIPaddressforhostname.
Usedbymailserver.

Re qui re d Pac k ag e s:

bindchroot9.2.42.i386.rpm
binddevel9.2.42.i386.rpm
bindlibs9.2.42.i386.rpm
bind*
bindubls9.2.42.i386.rpm
bind9.2.42.i386.rpm
cachingnameserver7.33.noarch.rpm
systemcongbind

P ort num be r:53DNS


Se rv ic e/ Dae m on:named

32

1. Installbind
#y umi nst al l bi nd*
# rpm iv h bind*
#y umi nst al lc ac hing *
# rpm iv h cachi ng *
# yum i nst all sy st emc on g bi nd*
# rpm iv h syste mc on g bi nd*
2. Copythele

#c p / usr/share / doc / bi nd9.3. 3/ sam pl e/ v ar/ nam e d/ nam e d. root


/v ar/ nam e d/ chroot /v ar/name d
3. Nowongraphicalterminal
(checkthatinnetworktabtheremustbeyoursIPaddressinDNStab)
# sy st emc on gbi nd
Nowawindowcomesthererig ht clic k on DN S se rve r addz onei nte rne t ok
forw ardl ook upz one ok rahul. c om (g iv et he dom ai n nam e )(ok )
Nowrig ht cl ick on dom ai n nam e (ra hul.c om) addIP v4 addre ss (A )
ww w. rahul.c om (full dom ai n nam e) t he n IP v 4addre ss (192.168 .1 .. )
4. # se rvic e nam e d re st art
5. Forreverselookupzone255 R. CI nt e rnet R ev e rse IP v4z one R .C. add NS
(N am e Serv er) Se rv e r Dom ai n N am e: ww w. rahul. c om (sav e)
6. # se rvic e nam e d re st art
7. TocheckwhetheryourDNSserverisworking
#hostwww.rahul.com

(forwardlookupzone)

#host192.168.1.1

(Reverselookupzone)

#digwww.rahul.com/192.168.1.1
#nslookupwww.rahul.com/192.168.1.1
8. On client PC add your IP in DNS tab in TCP/IP setngs and ping the domain name, if it
completes successfully, means your forward lookup zone is working and ping a <ip
address>,ifitgivesdomainnameitmeansreverselookupzoneisworking.(onwindows)

33

NFS SE RVE R
Sharingofles&foldersbetweenLinux.
Pac k ag e s:
portmap4.063.i386.rpm
nfsubls1.0.64.6.i386.rpm
Port N um be r:
2049nfsd
111portmap
Con g urab on Fil e:
/etc/exports
Servic e:
portmap
nfs
Dae m ons:
nfsd
1. Createafolderandmakelesorpastelesyouwanttosharefrominnetwork.(ex./var/dump)
2. Editleforsharing
#vi/etc/exports
/var/dump
*(rw)
/var/rahul
192.168.1.15(ro)

(savethele)

(inrstline,wehaveshare/var/dumpforallusersinanetworkwithread&writepermission&in
second line, wehaveshared /var/rahulonlyforthe PChavingIPaddress192.168.1.15withread
onlypermission)
3. #servicenfsrestart
4. #serviceportmaprestart
5. #showmounte

(TocheckNFSServeranditsshareddirectoryfromServeritself)

6. #showmounte<IPaddressofServer>(TocheckNFSServeranditsshareddocfromclient)
7. CLIENT EN D: FortakingNFSserverservicewehavetomountdirectoryfromservertoclient
#mounttnfs<serverIP>:/var/dump/mnt
#cd/mnt

(hereyouwillndallthesharedmaterial)
#cd/net
#cd/IPofNFSServer

34


8. ForinstallabonfromNFS,copywholeDVD/CDinafolderandshareit.
9. Boot from CD on another client computer, write linux askmethod, here it will ask to select the
installabonmedia,selectNFS,nowitwillaskto giveIPforyourclientcomputer,giveIP,Nowit
will ask for Name of NFS Server: <Give IP of NFS Server>, and directory : <Give the path>. Now
yoursystemwillinstallveryquicklywiththehelpofNFSserver.

SAM BASE RVE R

SambaisawayaLinuxComputercommunicatewithSMB(ServerMessageBox)andCIFS.

With Samba, you can make your Linux computer a part of Microso] based network.
ComputerswithvariousMicroso]Operabngsystemscancommunicatewitheachotherusing
theserver.

MessageBlock(SMB)protocol.WhenaMicroso]basedOSshareslesorprintersonaTCP/IP
network,itusestheCIFS(CommonInternetFileSystem).

Con g urab on Fil e s:

Servic e:

/etc/samba/smb.conf

smb

1. #yuminstallsamba*

(Installsambapackage)

#rpmivhsamba*
2. Now,editle
#vi/etc/samba/smb.conf

(atlastofle,pressingGcopythefollowinglineandpastethelinesandthenremove;infontof
theline.)
[MyShare]

comment=

path=

validusers=

public=no

writable=no

printable=no
savethele.

3. #servicesmbrestart

(Sharename)
(anycomment)
(heregivethepathwhichyouwanttoshare)
(Heregivesambausers)

(Heregivethepermissionyouwanttogive)

4. TocreateSambausers
#useradd<username>
#smbpasswda<username>
5. Tochecksambaisconguredofnot

35


#testparm
6. Sambausersentrycanbendin/etc/samba/smbpasswd
7. Onc li e ntc om pute rs:onrun:\\<IPaddressofsambaserver>
Nowitwillaskforsambausergiveusernameandpassword.

NIS SE RVE R
NISserverisjustlikeAcbveDirectoryServicesinWindows.NISserverneedNFSserver,soitisnecessary
toinstallNFSserverbeforeNIS.

1. Setthehostname
#hostnamerahul.com
2. Setthedomainname
#domainnamerahul.com
3. Installthepackage
#yuminstallypserv*
#rpmivhypserv*

4. Nowcreateasmanyasuseryouwanttocreate.Share/homeinNFSserver.
#vi/etc/exports
/home

*(rw,sync)

(savethele)

5. #servicenfsrestart
#serviceportmaprestart
#serviceypservrestart

6. #cd/usr/lib/yp
7. #./ypinitm

(inthisleitwillaskforhostname,addhostname,thenctrl+D)

8. On Cli e nt:
#setup(hereawindowwillbeopen,heremark*inNISopbon,itwillaskfordomain&IPOK)
9. #vi/etc/auto.master
/home

/etc/auto.misc

(savethele)

10. #vi/etc/auto.misc
*

rw,so],intr

serverIP:/home/&

11.#serviceautofsrestart

36

(savethele)


(Nowyouclientisready,loginwiththeuserthatyouhavecreatedonServerandmakeleyou
willndthatleonServer.)

APACHE( WE B)S ERVE R


ApacheServerisusedforhosbngwebsiteforInternet/Intranet.Bythisserverwecanalso
authenbcateonlylimiteduserstoaccesswebsite.ForthisserveryoumusthaveDNSserver
conguredoraddyourIPandservernameinhostsle.
Pac k ag e s:
hdpd*
1. Installpackageforhdp.
#yuminstallhdp*
#rpmivhhdp*

2. Nowmakeawebpage.
#vi/var/www/html/rahul.html

(forsinglewebpage,forvirtualhosbngmakeanotherpageinanotherlocabon,)
3. NowwhenweentertheDNSaddress,apacheserverwelcomescreencomes,ifwewantto
addourownhomepagewehavetoeditale.
#vi/etc/hdpd/conf/hdpd.conf

(atlastofthele)

</virtualHost*:80>

Documentroot/var/www/html
Servernamewww.rahul.com
</virtualHost>

(change*withIPaddress)

(savethele)

4. #servicehdpdrestart
5. NowwhenyouentertheDomainname(www.rahul.com)itwillopenyourwebpage)
6. AUTHE NTI CATI ON:
openthesameleandattheendofle,typethefollowing
<Directory
AuthUserle
AuthName
AuthType
Require

</Directory>

/var/www/html>
/etc/hdpd/conf/htpasswd
WebAuthenbcabon
Basic
ValidUser

(savethele)

7. Adduserforhdp
#useraddrahul
#htpasswdc/etc/hdpd/conf/htpasswdrahul

37


(itcreatesanewlehtpasswdandadduserrahulinit)
Foraddingmoreuser
#htpasswd/etc/hdpd/conf/htpasswd<username>

(againstartservice)

8. Vi rt ual H osb ng
Firstcopytheabovefourlines
<Virtualhost*:80>

Documentroot/var/www
Servernamewww.yahoo.com
</Virtualhost>

(change*withIPaddressatbothplace)

Cometothelinesabovetheselines

#NameVirtualHost*:80
(remove*and#change*withIPaddressofthesystem)

SENDMA IL

Pac k ag e s:

send*

1. # rpm iv h ai d se nd*

Con g urab on Fil e:


/etc/sendmail.mc

#y umi nst al l se nd*


2. # vi / etc/ se ndm ai l.m c
Lineno.116
deamon_opbons(Port=smtp,addr=127.0.0.0,name=mta)dnl(adddnl#atthebeginning)
savethele.
3. #m4/etc/mail/sendmail.mc>/etc/mail/sendmail.cf
4. #servicesendmailrestart
5. MA IL:
#mailroot@localhost.localdomain

38

XENSE RVE R( VIRTUA LIZAT ION)

PA RA VI RTU ALIZ ATIO N


Forvirtualizabon,firstwehavetocongureNFSserver.
1. Installpackages
#yuminstallsystemcongkickstart*
#yuminstallvirtmanager*
2. NowcopywholeDVDinafolder&shareitinNFS&alsosharethatfolderinwhichkickstartleis
saved.
3. #systemcongkickstart
(heremakeakickstartle,selectinstallabonbyNFSgiveNFSIP&Directoryandsaveit)
4. Alsomakeaparbbonhaving10GBspaceandformatthatparbbon(donotmount).
5. Now,rebootandselecttheXenLinux
6. Nowongraphicalconsole
#virtmanager
NewforwardparavirtualizabonforwardInstallmediaURL:nfs:<IPaddressofNFS>:/<path>
&kickstartURL:nfs:<IPaddressofNFS>:<pathwherekickstartlesaved>nextNormalDisk
/dev/<newparbboncreatedbyyou>nextnish.
7. YourvirtualLinuxmachineisreadytoinstallwiththehelpofNFS.

39

FTP
Re qui re d Pac k ag e
Vsftpd*
1. # rpm iv h v s] pd*
#y umi nst al lv s] pd*

2. #v i/ etc /v s] pd/v s] pd.c onf


Wehavetoremove#infrontofthefollowinglines.
Line no. 12:
anonymous=defaultuser

(FTPusestwousersanonymous&FTPanonymoushasnopassword)
Line no. 15:
local_enable=yes
(LocalusercanloginthroughFTP)
Line no. 18:
write_enable=yes
(writepermissionisenabledtoFTP)
Line no. 27:
anon_upload_enable=yes
(anonymoususercanuploadles)
Line no. 31:
anon_mkdir_write_enable=yes
(anonymoususercancreatedirectory)
Line no. 35:
dirmessageenable=yes
Line no. 85:
Ftpd_banner=welcometoFTP
3. # se rvic ev s] pd restart
4. Cli ente nd:
]p<ServerIP>
>cdpub
>get<lename>
>put<lename>

(download)
(upload)

40


>bye

(exit)

41

You might also like