Ramniranjan Jhunjhunwala College (Autonomous) : Certificate

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 62

SEMESTER 5 Subject: Linux Administration Roll No: 50

Hindi Vidya Prachar Samiti’s

RAMNIRANJAN JHUNJHUNWALA COLLEGE


(AUTONOMOUS)
Ghatkopar (W), Mumbai-400 086

Certificate

This is to certify that Mr. Vimal Tiwari ,Roll No:50 of TY B.Sc. (I.T.) class has completed the
required number of experiments in the subject of Linux System Administration in the
Department of Information Technology during the academic year 2020-2021.

Professor In-Charge Co-ordinator of IT Department

Prof. Bharati Bhole


Prof. Archana Bhide
Examiner

No Practical Remark
1 Installation of RHEL 6.X

2. Graphical User Interface and Command Line Interface and


Processes

a The Command Line Interface


1. Use man and man -k to find out how to change the current date
on your computer.
2. Create a directory with the name /tempdir. Copy all files from
the /etc directory that start with an a, b, or c to this directory.
3. Find out which command and which specific options you will
need to show a time sorted list of the contents of the
directory /etc.
4. Find all files on your server that have a size greater than 100 MB
b Managing Processes
Managing Processes with ps and kill
1. Move a job that was started as a foreground job into the
background.
2. Start a few processes to make the parent-child relationship
between these processes visible. Then kill the parent process .
3. Using nice to Change Process Priority
4. create a user account to run a cron job that sends an email
message to user root on your system

3 Storage Devices and Links, Backup and Repository

a Working with Storage Devices and Links


1. create a new partition and unmount it
2. Create a logical volume using logical volume management
3. create a hard link as well as a symbolic link to a file to
demonstrate the differences
b Creating a Repository
Create a repository for Yum and install httpd package using yum

4 Working with RPMsm Storage and Networking

1
a Using Query Options
(i) Various query options on RPM command
b Connecting to the Network

5 Working with Users, Groups, and Permissions

6 Firewall and Cryptographic services

a Securing Server with iptables


b Setting Up Cryptographic Services
(i)Creating and exchanging gpg key for encrypting and decrypting file

7 Configuring Server for File Sharing


a Configuring NFS Server and Client
b Configuring Samba
c Configuring FTP

8 DNS, DHCP and Mail Server


a Configuring DNS
b Configuring DHCP
c Setting Up a Mail Server
(i) configuring mail with mutt
(ii) Install and configure postfix mail server

9 Web Server
a Configuring Apache on Red Hat Enterprise Linux
b Writing a Script to Monitor Activity on the Apache Web Server
c Using the select Command
Write a simple script that asks the user to enter the name of an RPM or
fi le that
the user wants to query. Write the script to present a menu that
provides different options that allow the user to do queries on the
RPM database
The following options must be presented:
a. Find the RPM from which this file originates.
b. Check that the RPM where the user has provided the name is
installed.
c. Install this RPM.

2
d. Remove this RPM.

10 Shell script
a Writing Shell Scripts
(All Shell programs )
b Configuring Booting with GRUB

3
Practical 1:Installation of RHEL 6.X

Steps to install RHEL 6.X:

1. Open vmware workstation.

2. Creating a new virtual machine click on “Create a new virtual machine”.

3. After clicking on the new virtual machine “Select Typical(recommended)” > Click on Next.

4. After that check the radio button “Select Installer disk image file” and browse the disk file and
After click on I will install the operating system later option > Click on Next.

5. After that select Guest operating system for that click on “Linux” option. > select the version of
Linux that is “Red Hat Enterprise Linux 6 64-bit” > Click on Next.

6. After that Give name to your virtual machine in “Virtual machine name” as TYIT_Liux and set the
Location or you can use Default Location which is theirs > Click on Next.

7. After that Specify Disk Capacity 20.0 GB in which choose the option as “Split virtual disk into
multiple files” > Click on Next.

8. After that click on the “Customize Hardware” button.

9. A window gets opened in which following settings has to be done:


a. Click on New CD/DVD option Select the option of “Use ISO image file” and Browse the
ISO image file.
b. Click on Network Adapter option select the option “Host-only option” after that click on
close.
10. Click On Finish.

11. After that click on Power on the virtual machine

12. After that click on the Skip button > Click On Next.

13. After that choose the language as English > click on Next.

14. Select the appropriate Keyboard option as U.S. English > click on Next.

15. Select what type of devices will your installation involve? In that you choose Basic Storage
Device option and click next.

16. After that click on Reinitialize all.

4
17. Now here we assign our Hostname change the hostname as you desire or let it be as
localhost.localdomain > click on Next.

18. After that select the city > click on Next.

19. Enter the root Password > Click on Next > And click on Use Any way.
20. After that select “Create Custom Layout” option > Click on Next

21. (After create a disk partition) After Clicking On Create Custom Layout Option “Please select a
device” window open > Click On Create Button > Create storage window open > Click on radio button
Standard Partition > Click on create button > Add a partition.
1. /(root)Ext4 10000 MB
2. /swap 4000 MB
3. /boot Ext4 2000 MB
4. After that click on Next.And Format Button.
5. After that Click on “Write Changes to disk”.

22. Click On Next.

23. After click on Next > Choose two option from one part choose “Desktop” and for another part
click on Customize Now option > click on Next.

24. We have to do some changes for software selection.


1.Select Base System (Networking Tools, Performance Tools, Security Tools)
2.Select Servers (E-mail server, FTP server, NFS File server, Print server)
3.Select Web Services(Web server, Web servlet Engine)
4.Select Databases (MYSQL Database Client, MYSQL Database Server)
5.Select System Management (Messaging Client Support, Messaging Server Support)
6.Select Desktops(KDE Desktops, X-Windows System)

25. After that installation gets started.

26. Click on reboot

27. After that Click on Forward button.

28. Select the option “Yes,I agree to the Licence Agreement” > Click on Forward button.

29. Click on the Forward button.

30. Click on the Forward button > And fill the username and password

31. Set date and time > click on the Forward button.

5
32. Click on the Finish button.

33. The login screen appears.This means installation is successful.

6
Practical 2 Graphical User Interface and Command Line Interface and Processes

Practical 2(a): The Command Line Interface

1. Use man and man -k to find out how to change the current date on your computer.
.
[root@server Desktop]# cd //Change the directory.

[root@server ~]# man -k time | grep 8 //This gives a command list. Use date command to change
the current date of the computer.

[root@server ~]# date 12022020 //This command set a date. In a Mm/dd/yy


Wed Dec 2 12:14:00 IST 2018

2. Create a directory with the name /tempdir. Copy all files from the /etc directory that start
with an a, b, or c to this directory.

[root@loacalhost ~]# mkdir /tempdir //This command creates a directory.

[root@loacalhost ~]# ls //This command gives a list of directories.

[root@loacalhost ~]# cp /etc/[ijk]* /tempdir/ //This Command Copy all files from the /etc directory that
start with an i, j, or k to this directory.
cp
[root@loacalhost ~]# ls /tempdir //give the list of files of temdir directory.

3. Find out which command and which specific options you will need to show a time sorted
list of the contents of the directory /etc.

[root@loacalhost ~]# man ls //gives the list of options with ls command.

[root@loacalhost ~]# ls -t/ etc //sorts the file by modification time, showing the last edited file
first.

4. Find all files on your server that have a size greater than 100 MB

[root@loacalhost ~]# find / size +100M //Find all files on your server that have a size greater than
100 MB

7
Practical 2(b): Managing Processes.

● Managing Processes with ps and kill:

1. Move a job that was started as a foreground job into the background.

Step 1: open a terminal, and from that terminal, start the system-config-users program.

[root@loacalhost ~]# system-config-users

Step 2: You will see that the terminal is now occupied by the graphical program you’ve just started and
that you cannot start any other programs.

Step 3: Click in the terminal where you started system-config-users, and use the Ctrl+Z key sequence.
This temporarily stops the graphical program and returns the prompt on your terminal.

^Z
[1]+ Stopped system-config-users
[root@loacalhost ~]#

Step 4: Use the bg command to move the job you started by entering the system-config-users
command to the background. You can now continue using the graphical user interface and, at the same
time, have access to the terminal where you can start other jobs by entering new commands.

[root@loacalhost ~]# bg
[1]+ system-config-users &
[root@loacalhost ~]#

Step 5: From the terminal window, type the jobs command. This shows a list of all jobs that are started
from this terminal. You should see just the system-config-users command. Every job has a unique
job number in the list displayed by the jobs command. If you have just one job, it will always be job
1.

[root@loacalhost ~]# jobs


[1]+ system-config-users &
[root@loacalhost ~]#

Step 6: To put a background job back into the foreground, use the fg command. By default, this
command will put the last command you started in the background into the foreground. If you want to
put another background job into the foreground, use fg followed by the job number of the job you
want to manage; for instance,use fg 1.

[root@loacalhost ~]# fg
8
system-config-users

2. Start a few processes to make the parent-child relationship between these processes visible.
Then kill the parent process .

Step 1: Use the bash command to start Bash as a subshell in the current terminal window.

[root@loacalhost ~]# bash

Step 2: Use ssh -X localhost to start ssh as a subshell in the Bash shell you just opened.When asked if
you want to permanently add localhost to the list of known hosts,enter yes. Next enter the password of
the user root.

[root@loacalhost ~]# ssh -X localhost

Step 3: Type gedit & to start gedit as a background job.

[root@loacalhost ~]# gedit &


[1] 2720

Step 4: Type ps afx to show a listing of all current processes, including the parent-child relationship
between the commands you just entered.
One of the output lines shows the ssh -X localhost command you just entered. Note the PID that
you see in that output line.

[root@loacalhost ~]# ps afx

Step 5: Use kill followed by the PID number you just found to close the ssh shell. Because the ssh
environment is the parent of the gedit command, killing ssh will also kill the gedit window.

[root@loacalhost ~]# kill 2686 Killed by signal 15.


3. Using nice to Change Process Priority

Step 1: Type the command dd if=/dev/zero of=/dev/null &, and repeat this four times.

[root@loacalhost ~]# dd if=/dev/zero of=/dev/null &


[1] 2826
[root@loacalhost ~]# dd if=/dev/zero of=/dev/null &
[1] 2827
[root@loacalhost ~]# dd if=/dev/zero of=/dev/null &
[1] 2828
[root@loacalhost ~]# dd if=/dev/zero of=/dev/null &
[1] 2829

9
Step 2: Now start top. You’ll see the four dd commands listed at the top. In the PR column, you can see
that the priority of all of these processes is set to 20. The NI column, which shows the actual
process niceness, indicates a value of 0 for all of the dd processes, and, in the TIME column, you can
see that all of the processes use about the same amount of processor time.

[root@loacalhost ~]# top

Step 3: Now, from within the top interface, press r. On the PID to renice prompt, type the PID of one of
the four dd processes, and press Enter. When asked Renice PID 2826 to value, type 5, and press Enter.

PID to renice: 3641


Renice PID 2826 to value:5

Step 4: With the previous action, you lowered the priority of one of the dd commands. You should
immediately start seeing the result in top, because one of the dd processes will receive a
significantly lower amount of CPU time.

Step 5: Repeat the procedure to adjust the niceness of one of the other dd processes. Now use a
niceness value of -15. You will notice that this process now tends to consume all of the available
resources on your computer. Thus, you should avoid the extremes when working with nice.
PID to renice: 3642
Renice PID 2827 to value:-15

PID to renice: 3643


Renice PID 2828 to value:0

PID to renice: 3644


Renice PID 2829 to value:-5

Step 6: Use the k command from the top interface to stop all processes where you adjusted the
niceness.
//press k enter the pid number
PID to kill: 3641 //press Enter than below msg will show again press enter to exit
msg - Kill PID 3641 with signal [15]:k
//Repeat the process to kill rest PID
PID to kill: 3642
PID to kill: 3643
PID to kill: 3644

10
4. Create a user account to run a cron job that sends an email message to user root on your
system

Step 1: The command su is used to execute commands with the privileges of another user account.
When executed it invokes a shell without changing the current working directory or the user
environment.

[root@loacalhost ~]# su - rjcit


[rjcit@loacalhost ~]$

Step 2: Edit the crontab file and to exit type :wq

[rjcit@loacalhost ~]$ crontab -e

//this will help to edit the crontab than type i to enter edit mode insert bellow command after done
typing press esc and type :wq to exit crontab.

Type this - */5 * * * * mail -s “hello root” root <

Step 3: After that login as root permission. Use mail command to send email.

[rjcit@server Desktop ~]$ crontab -e


[rjcit@server Desktop ~]$ su
Password:
[root@server Desktop ~]$ mail

11
Practical 3: Storage Devices and Links, Backup and Repository

Practical 3(a): Working with Storage Devices and Links

1. Create a new partition and unmount it

Step 1: Before creating the partition we need to check the current partitions and file systems.
To view all existing disk partitions we use the ‘fdisk –l’ command.
fdisk command helps to create,view,resize,delete,change,copy and move partitions on a hard drive.
It allows creating four new primary partitions, and number of logical partitions(extended partitions)
based on the size of the hard disk by dividing from one of the primary partitions.

[root@loacalhost ~]# fdisk -l

Step 2: View all fdisk commands using fdisk Command m.

[root@loacalhost ~]# fdisk /dev/sda

command (m for help): m

Step 3: Create a new partition of defined space


To add new partition : n
It will ask whether to create a primary or extended partition.
Here,since we have already 3 primary partitions created,we can add one 4th primary partition.
Type ‘p’ for primary partition
Select partition number : 4
Press Enter (first cylinder)
And specify the size of partition(last cylinder): +20M
To write(save) partition and exit fdisk utility :w

command (m for help): n


command action
e extended
p primary partition (1-4)
p
Select partition 4

command (m for help): w

Step 4: Command to inform kernel about a new partition


Use partx –a command.
partx : extended partition
-a : all

12
[root@loacalhost ~]# partx –a /dev/sda

Step 5: Type the command twice.


Second time it refreshes and adds 4th partition

[root@loacalhost ~]# partx –a /dev/sda

Step 6: To check whether the 4th partition is successfully added use fdisk –l command

[root@loacalhost ~]# fdisk -l

Step 7: Inform the Hard Disk about the file system of partition
Command to make the file system is #mkfs.ext4 /dev/sda4

[root@loacalhost ~]# mkfs.ext4 /dev/sda4

Step 8: Mount the partition


A] First create a directory named as file1 under root for mount point
B] To configure file to do mounting is fstab

[root@loacalhost ~]# mkdir/ file1


[root@loacalhost ~]# cd /
[root@loacalhost ~]# ls

Mount the partitions in /etc/fstab

[root@loacalhost ~]# vim /etc/fstab

At last type the following line by going to insert mode


Save and quit by using :wq!
Use mount command:#mount –a

[root@loacalhost ~]# mount -a

To check whether it is mounted we use df –hT command

[root@loacalhost ~]# df -hT

Unmounting the created partition.

Step 1: To unmount the created 4th partition i.e /dev/sda4 use “umount” command

13
[root@loacalhost ~]# umount /dev/sda4

Step 2: Unmount the extended partition


A]First remove a directory for mount point using rmdir command

[root@loacalhost ~]# rmdir /file1

B]Unmount the partitions i.e file system in /etc/fstab


First open the file /etc/fstab and then remove the last line which was added.

[root@loacalhost ~]# vim /etc /fstab

Save and quit by using :wq!

C]Now delete the created partition 4 by fdisk Command d


Delete partition number: 4
Save the changes : w

Step 3: Command to inform kernel about a deleted partition

[root@loacalhost ~]# partx -a /dev/sda

Step 4: Check whether partition is successfully deleted

[root@loacalhost ~]# fdisk -l

2. Create a logical volume using logical volume management.

Step 1: Checking disk space of /(root),/home and lv(LVM) partitioned.


By Using df –h command

[root@loacalhost ~]# df -h

Step 2: Create one physical volume /dev/sda5 and one volume group as tybscit-A then create one
logical
volume user1 and finally mount this volume to directory /user1.

[root@loacalhost ~]# fdisk dev/sda

Extend partition
A] Press ‘n’ for new partition
B] Press ‘e’ to extended partition
C] Press ‘Enter’ on first and last sector
14
D] Press ‘p’ to print the partition

command (m for help): p

command (m for help): n


command action
e extended
p primary partition (1-4)
e
selected partition 4

command (m for help): p

Now create new partition from extended partition(/dev/sda4)


A] Press ‘n’ new partition
B] Press ‘Enter’ on first and last sector
C] Press ‘t’ to change partition types
D] Give value ‘5’ partition number
E] Enter partition type ‘8e’ for linux LVM

command (m for help): n

command (m for help): t


Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed the system type of partition 5 to 8e (Linux LVM)

command (m for help): p

command (m for help): w

Step 3: Once you have completed all the steps reboot the system by using init 6 command
And print the partition table by using fdisk /dev/sda Command p
After this press ctrl+c
Create Physical Volume(pv),Volume Group(vg),Logical Volume(lv):

Create physical volume by using pvcreate command

[root@loacalhost ~]# pvcreate /dev/sda5

To check your physical volume use pvs command

[root@loacalhost ~]# pvs

15
Create Volume group name of tybscit-A by using vgcreate command

[root@loacalhost ~]# vgcreate tybscit-A /dev/sda5

To check your volume groups name,size and free space use vgs command

[root@loacalhost ~]# vgs

Create logical volume name of user1 with 2GB space from tybscit-A group by using lvcreate
command

[root@loacalhost ~]# lvcreate -n user1 -L +2GB tybscit-A

To check your logical volume use lvs command

[root@loacalhost ~]# lvs

Setting LVM path:

[root@loacalhost ~]# cd /dev /mapper


[root@loacalhost mapper]# ls

Make file system to ext4

[root@loacalhost mapper]# mkfs.ext4 /dev/sda/mapper/tybscit--A-user1

Mount the Logical volume:

Now,mount the logical volume tybscit--A-user1 to /user1 directory


Create one new directory /user1 under mapper directory

[root@loacalhost mapper]# mkdir /user1

Mount the volumes to these directory

[root@loacalhost mapper]# mount /dev /mapper //tybscit--A-user1 /user1

Finally check the partition using df –h command

[root@loacalhost mapper]# df -h

Deleting all the volumes created


Unmount the logical volume

16
[root@loacalhost mapper]# umount /dev /mapper //tybscit--A-user1

Remove logical volume(lv) by using lvremove command

[root@loacalhost mapper]# lvremove /dev/tybscit/user1

Remove Volume group(vg) by using vgremove command

[root@loacalhost mapper]# vgremove tybscit-A

Remove Physical volume(pv) by using pvremove command

[root@loacalhost mapper]# pvremove dev/sda5

3. Create a hard link as well as a symbolic link to a file to demonstrate the differences

Step 1: Create a hard link as well as a symbolic link to the file /etc/hosts, and you will see how both
behave differently.
Open a terminal and make sure you have root permissions.
Using the command ln –s /etc/hosts ~/symhosts. This creates a symbolic link with the name
symhosts in your home directory.

[root@loacalhost ~]# ln -s /etc/hosts ~/symhosts

Step 2: Using the command ln /etc/hosts ~/hardhosts. This creates a hard link with the name hardhosts
in your home directory.

[root@loacalhost ~]# ln /etc/hosts ~ /hardhosts

Step 3: Using the command ls –il /etc/hosts ~/symhosts ~/hardhosts .The option –I shows the inode
number.You can see the inode number is same for /etc/hosts and ~/hardhosts like all other properties
of a file.

[root@loacalhost ~]# ls -il /etc/hosts ~/symhosts ~/hardhosts

Step 4: Use rm /etc/hosts.Try to read the contents of ~/symhosts and ~/hardhosts.You will see the
difference.

[root@loacalhost ~]# rm /etc/hosts

17
Step 5: Restore the original situation by recreating the /etc/hosts file.You can do that easily by making a
new hardlink using ln ~/hardhosts /etc/hosts
[root@loacalhost ~]# ln ~/hardhosts /etc/hosts

Practical 3(b): Creating a Repository

Create a repository for Yum and install httpd package using yum

Step 1: Check the DVD for Packages


cd:change directory and ls:list the files under the directory

[root@loacalhost ~]# cd/media/


[root@loacalhost media]# cd RHEL_6.0\ x86_64 \Disc \1 /
[root@loacalhost RHEL_6.0 x86_64 Disc 1]# ls

Step 2: Make directory named as RHEL6 under root

[root@loacalhost RHEL_6.0 x86_64 Disc 1]# cd/


[root@loacalhost /]# mkdir /RHEL6
[root@loacalhost /]# ls

Step 3: Copying whole DVD in RHEL6 folder


[root@localhost /]#cd RHEL6/
[root@localhost RHEL6]# cp –vr /media/RHEL_6.0\ x86_64\ Disc\ 1/* /RHEL6/
While packages are getting copied from cd/packages to /RHEL6 directory

Check the folder RHEL6 to see whether the packages have been copied properly by using ls
command

[root@localhost RHEL6]# ls

Go to /etc/yum/pluginconf.d directory

[root@localhost RHEL6]# cd/ etc/ yum


[root@localhost yum]# ls
[root@localhost yum]# cd pluginconf.d/
[root@localhost pluginconf.d]# ls

Step 4: Create a repository for yum


18
[root@localhost pluginconf.d]# createrepo --database/RHEL6/Packages/

If error comes install createrepo using rpm and install all the dependency packages until no
dependency is found

[root@localhost pluginconf.d]# cd/media/RHEL_6.0\ x86_64\ Disc\ 1/Packages/


[root@localhost Packages]# rpm -ivh-createrepo-0.9.8-4.el6.noarch.rpm

[root@localhost Packages]# rpm -ivh python-deltarpm-3.5-0.5.20090913.git.el6.noarch.rpm

[root@localhost Packages]# rpm -ivh-createrepo-0.9.8-4.el6.noarch.rpm

Now the command for creating repository will work by changing the directory to pluginconf.d

[root@localhost Packages]# cd/etc/yum/pluginconf.d/


[root@localhost pluginconf.d]# createrepo --database /RHEL6/Packages/

Step 5: Make changes in rhel.repo file located at /etc/yum.repos.d folder

[root@localhost pluginconf.d]# cd /etc/yum.repos.d/


[root@localhost yum.repos.d]# ls
packagekit-media.repo
[root@localhost yum.repos.d]# vi rhel.repo

The directory /etc/yum.repos.d/ contains two .repo files which should be removed or moved to
other directory,so that YUM server will check default.repo file it self.If you don’t move or remove
the default .repo files from /etc/yum.repos.d/ folder then every time when you try to install
packages through YUM,your yum will check all these files for repositories for getting packages
which will or will not work and most probably delay is increased in getting those packages from
online servers.

[rhel]
name=rhel6
baseurl=file:///RHEL6/Packages

Save the file:Press Esc key and :wq!


Come out of the yum.repos.d directory by cd command and check whether your yum server is
configured or not
In order to use yum repository we have to clean the yum metadata,so before installing any
package first time use yum clean all command.

[root@localhost yum.repos.d]# cd
[root@localhost ~]# yum clean all
19
[root@localhost ~]# cd/etc/yum.repos.d/
[root@localhost yum.repos.d] yum search firefox

If this error occurs


Create repo.disabled inside /etc/yum.repos.d/

[root@localhost ~]# mkdir /etc/yum.repos.d/repo.disabled


[root@localhost ~]# ls /etc/yum.repos.d/

Then move all the .repo files into “repo.disabled” folder

[root@localhost ~]# mv /etc/yum.repos.d/packagekit-media.repo /etc/yum.repos.d/repo.disabled


[root@localhost ~]# mv /etc/yum.repos.d/rhel.repo /etc/yum.repos.d/repo.disabled

List out the updated files and folders inside /etc/yum.repos.d/

[root@localhost ~]# ls-l /etc/yum.repos.d/

Only folder repo.disabled should be exist.


Run yum clean all to clear up your yum cache directory:

[root@localhost ~]# yum clean all


[root@localhost /]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls

Now Repeat Step5:Make changes in rhel.repo file located at /etc/yum.repos.d folder


[rhel]
name=rhel6
baseurl=file:///RHEL6/Packages
Save and quit by using wq!
Now run the yum command as usual

[root@localhost ~]# yum repolist

[root@localhost /]# cd /etc/yum.repos.d/


[root@localhost yum.repos.d]# yum search firefox

Step 6: Installing httpd package using yum install

[root@localhost yum.repos.d]# cd/media/RHEL_6.0\ x86_64\ Disc\ 1/Packages/


[root@localhost Packages]# yum install httpd

As the httpd package is already install therefore the package is not been installed.You can try with
20
nmap package

[root@localhost Packages]# yum install nmap

21
Practical 4:Working with RPMsm Storage and Networking

Practical 4(a):Using Query Options

(i) Various Query Option on RPM command

Before that go into Packages.using command :

[root@localhost ~]# cd/media/RHEL_6.0\ x86_64\ Disc\ 1/Packages/


[root@localhost Packages]#

Step 1: How to Install an RPM Package.

[root@localhost Packages]# rpm -ivh vlock-1.3-31.el6.x86_64.rpm

Step 2: how to check the dependencies of installed RPM Package.


Using -qR option.

[root@localhost Packages]# rpm -qR vlock

Step 3: How to Check dependencies of RPM Package before Installing.


Using -qpR option.

[root@localhost Packages]# rpm -qpR createrepo-0.9.8-4.el6.noarch.rpm

Step 4: How to Install a RPM Package Without Dependencies.


Using - -nodeps option.

[root@localhost Packages]# rpm -ivh --nodeps createrepo-0.9.8-4.el6.noarch.rpm

Step 5: How to check an Installed RPM Package.


Using -q option.

[root@localhost Packages]# rpm -q vlock

Step 6: How to List all files of an installed RPM package.


Using -ql option.

[root@localhost Packages]# rpm -ql vlock

Step 7: How to List all file before installing RPM package.


Using -qpl option.

[root@localhost Packages]# rpm -qpl createrepo-0.9.8-4.el6.noarch.rpm


22
Step 8: How to List Recently Installed RPM Packages.

[root@localhost Packages]# rpm -qa vlock

Step 9: How to List All Installed RPM Packages.


Using -qa option.

[root@localhost Packages]# rpm -qa

Step 10: How to Upgrade a RPM Packages.


Using -Uvh option.

[root@localhost Packages]# rpm -Uvh vlock-1.3-31.el6.x86_64.rpm

Step 11: How to Remove a RPM Package.


Using -e option.

[root@localhost Packages]# rpm -e createrepo

Step 12: How to Remove an RPM Package Without Dependencies.


Using --nodeps option.

[root@localhost Packages]# rpm -e --nodeps vlock

Step 13: How to Query a file that belongs to the RPM Package.
Using -qf option with file name.

[root@localhost Packages]# rpm -qf /usr/share/doc/vlock-1.3

Step 14: How to Query Information of Installed RPM Package.


Using -qi option.

[root@localhost Packages]# rpm -qi vsftpd

Step 15: Get the Information of RPM Package Before Installing.


Using -qpi command.

[root@localhost Packages]# rpm -qpi createrepo-0.9.8-4.el6.noarch.rpm

Step 16: How to Query documentation of Installed RPM Package.


Using -qd option.

[root@localhost Packages]# rpm -qd vlock


23
Step 17: How to Query documentation of before Installing RPM Package.
Using -qpd option.
[root@localhost Packages]# rpm -qpd createrepo-0.9.8-4.el6.noarch.rpm

Step 18: How to Verify a RPM Package.


Using -Vp option.

[root@localhost Packages]# rpm -Vp vlock-1.3-31.el6.x86_64.rpm

Step 19: How to Verify all RPM Packages.


Using -Va option.
[root@localhost Packages]# rpm -Va

Step 20: How to install a already installed packages in your system.


• This shows that packages are already installed. if we try to install the package again. to overcome
this problem use option replacepkgs.

[root@localhost Packages]# rpm -ivh vlock-1.3-31.el6.x86_64.rpm

[root@localhost Packages]# rpm -ivh --replacepkgs vlock-1.3-31.el6.x86_64.rpm

24
Practical 4(b):Connecting to Network

[root@server Desktop]# cd
[root@server ~]# vim /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=linux

Restart the system:


To set IP address permanently

[root@linux Desktop]# cd
[root@linux ~]# ifconfig

[root@linux ~]# ifconfig eth0 192.168.0.47


[root@linux ~]# vim/etc/sysconfig/network-scripts/ifcfg-eth0
[root@linux ~]# service network restart

DEVICE=eth0
HWADDR=00:0c:29:fc:9c:27
NM_CONTROLLED=yes
ONBOOT=yes
DNS1=192.168.205.128
IPADDR=192.168.1.3

BOOTPROTO=none
NETMASK=255.255.255.0
TYPE=Ethernet
IPV6INIT=no
USERCTL=no

[root@linux ~]# ifconfig eth0 192.168.0.47


[root@linux ~]#vim/etc/sysconfig/network-scripts/ifcfg-eth0
[root@linux ~]# service network restart

[root@linux ~]# ifconfig eth0

25
Practical 5:Working with Users, Groups, and Permissions

A. Becoming super user

1.We create a user account “linda” to grant her the privilege of super user.

[root@localhost~]# useradd jay

[root@localhost~]# passwd jay

Changing password for user jay


New Password: ********
Retype New Password : *******

2. Open /etc/shadows file and the following lines for sachin.

[root@localhost~]# vi /etc/sudoers

We add the following line no. 90 to grant “jay” the privileges.

3. Run the ‘visudo’ command

[root@localhost~]# visudo

4.Test the configuration by making “jay to login and perform any administrative activity as shown below:

Add user “shreya” using sudo:


[root@localhost ~]# su - jay
[sachin@localhost ~]# sudo useradd shreya

Changing password of ‘shreya’ using sudo:


[sachin@localhost ~]# sudo passwd shreya

New Password: ********


26
Retype New Password : *******

C. Change normal user to root user:

[root@localhost ~]# su - shreya


[shreya@localhost ~]# su - root
Password:
[root@localhost ~]# su -shreya
[shreya@localhost ~]#

D. Administrative Commands

1. Useradd
[root@localhost ~]# useradd -c “This is Jisha’s account” -u 601 -o -s /sbin/bash jisha

To check the file /etc/passwd shows the entry at last”

#cat /etc/passwd

2.chage

[root@localhost~]# chage -m 15 -M 25 -E 12/10/2016 -W 7 shreya


[root@localhost~]# chage -l shreya

The above command also affects the file /etc/shadow as follows:


#cat /etc/shadow

3.passwd

passwd command is used to lock or unlock user’s password:

[root@localhost~]# passwd -u shreya

4.chsh
chsh command is used to change the shell of user:

[root@localhost ~]# chsh -s /bin/nologin Jisha


Changing shell for Jisha.
Shell changed.
[root@localhost ~]#

5.groupadd
27
groupadd command is used to create a new group and gpasswd command to add members and
administrators in the group.

[root@localhost ~]# groupadd friends


[root@localhost ~]# gpasswd -M smith,Jackson,Jisha -A smith friends
[root@localhost ~]#

-A specifies the name of the group administrator.

-M specifies members to be added in the group


The above command also affects the file /etc/group.
#cat /etc/group

It displays the following details:


Name of the group: group password: group id: group members

6.userdel
userdel command is used to delete the user.
[root@localhost~]# userdel shreya

You can check in /etc/passwd file, the user named ‘shreya’, no longer exists

7.groupdel

groupdel command is used to delete the group which is no longer used.

[root@localhost~]# groupdel friends

8.newusers

1.Multiple users will be created in text file using vi editor

[root@localhost~]# vim users.txt

2. You can verify entry by cat command.

[root@localhost~]# cat users.txt

3.Now, let’s execute the above file using newusers command.

[root@localhost~]# newusers users.txt

4. Verifying entry in the password file that users are created or not.
28
#cat /etc/passwd

5.Verifying the entry in group file

[root@localhost~]# cat /etc/group

6.Verifying the entry in shadow file

[root@localhost~]# cat /etc/shadow

9. Chattr

1.Go to home directory

[root@localhost ~]# cd ..
[root@localhost /]# pwd
/
[root@localhost /]# cd /home/
[root@localhost home]#pwd
/home
[root@localhost home]#

2.Using vi editor we create a new text file named as “linux.txt”

[root@localhost home]# vi linux.txt

3. to check whether a file is created.

4.Setting immutable attribute to file linux.txt

[root@localhost home]# chattr +i linux.txt

5. Check the attributes for a particular file

[root@localhost home]# lsattr linux.txt

Now try removing the immutable file forcefully.

[root@localhost home]# rm -rf linux.txt

Try moving one file to another file


29
[root@localhost home]# mv linux.txt linux_new.txt

Changing permissions-giving read, write and execute permissions to immutable file.

[root@localhost home]# chmod -R 777 linux.txt

6.To unset the immutable flag.

[root@localhost home]# chattr -i linux.txt

7.Now try removing the file forcefully and check.

[root@localhost home]# rm -rf linux.txt

Practical 6: Firewall and Cryptographic services

Practical 6(a): Securing Server with iptables.

[root@server ~]# service iptables start


[root@server ~]# service iptables stop

Iptables command to accept connections by default.

[root@server ~]# iptables -P INPUT ACCEPT


[root@server ~]# iptables -P FORWARD ACCEPT
[root@server ~]# iptables -P OUTPUT ACCEPT

Iptables command to deny all the connections(drop).


Iptables command to reject all network connections(reject).

[root@server ~]# iptables -P INPUT DROP


[root@server ~]# iptables -P FORWARD DROP
[root@server ~]# iptables -P OUTPUT DROP
[root@server ~]# iptables -A INPUT -j REJECT
[root@server ~]# iptables -A FORWARD -j REJECT
[root@server ~]# iptables -A OUTPUT -j REJECT

Accept host with IP address 192.168.1.5


Block all incoming connection to port 22.

[root@server ~]# iptables -A INPUT -p tcp -s 192.168.1.5 --dport ssh -j ACCEPT


[root@server ~]# iptables -A INPUT -p tcp --dport ssh -j REJECT

30
Allow all incoming ssh connection.

[root@server ~]# iptables -A INPUT -i eth0 -p tcp --dport 22 -m --state NEW,ESTABLISH -j ACCEPT

Allowing outgoing ssh connection for specific address.

[root@server ~]# iptables -A INPUT -A OUTPUT -p tcp -d 192.168.1.3 --sport ssh -j ACCEPT

Allowing outgoing ssh connection which is established for incoming ssh connection request, once
the incoming connection is allow we also need to allow response back for that incoming ssh
connection

[root@server ~]# iptables -A OUTPUT -o eth0 -p tcp --sports 22 -m state --state NEW,ESTABLISH -j
ACCEPT

Iptable to drop incoming ping request.

[root@server ~]# iptables -A INPUT -p icmp --icmp-type echo-request -j DROP

To drop all outgoing telnet connection.

[root@server ~]# iptables -A OUTPUT -p tcp --dport telnet -i REJECT

To reject all incoming telnet connection.

[root@server ~]# iptables -A INPUT -p tcp --dport telnet -j REJECT

To save changes in iptables

[root@server ~]# iptables -F

Practical 6(b): Setting Up Cryptographic Services

(i)Creating and exchanging gpg key for encrypting and decrypting file

Step 1: Login as root permission and add two user first “linda” nd second “lisa”

[root@localhost Desktop]# cd
[root@localhost ~]# useradd linda
[root@localhost ~]# passwd linda

[root@localhost ~]# useradd lisa


c passwd lisa

31
Step 2: Login into linda account and generate gpg key

[linda@server Desktop]$ cd
[linda@server ~]$ gpg --gen - key

After opening a window pinentry-gtk-2 enter passphrase and click on ok.

Step 3: Login into lisa’s account and generate gpg key

[lisa@server Desktop]$ cd
[lisa@server ~]$ gpg --gen - key

After opening a window pinentry-gtk-2 enter passphrase and click on ok.

[lisa@localhost ~]$ gpg --export -a > /tmp/lisa.key


[lisa@localhost ~]$ gpg --import < /tmp/linda.key

[lisa@localhost ~]$ gpg --list-keys

[lisa@localhost ~]$ cat > secret.txt


hii linda

[lisa@localhost ~]$ gpg -e secret .text

Step 4: Press Enter [tab]

Enter the user ID. End with an empty line:


[lisa@localhost ~]$ cp secret.txt.gpg /tmp

Login into linda account:

[linda@localhost Desktop]$ cd
[linda@localhost ~]$ gpg --list- key

[linda@localhost ~]$ gpg --import < /tmp/lisa/key

[linda@localhost ~]$ gpg --list- key

[linda@localhost ~]$ gpg -d/tmp/secret.txt.gpg

32
Practical 7: Configuring Server for File Sharing

Practical 7(a): Configuring NFS Server and Client

Step 1: Installation of nfs package.

[root@server ~]# cd /media/RHEL_6.0/ x86_64 \Disc\1/Packages


[root@server Packages]# rpm -ivh nfs*

Step 2: Verify IP address of the linux machine to be setup as NFS server.

[root@server Packages]# ifconfig eth0

[root@server Packages]# cd/home/


[root@server home]#

Step 3: Make a directory to be exported,create few files into it and give full permission.

[root@server home]# mkdir servernfs


[root@server home]# cd servernfs
[root@server servernfs]#

[root@server servernfs]# cat>newfile


Hello Linux
[root@server servernfs]#

33
Step 4: Open the configuration file of NFS,i.e, /etc/exports .

[root@server servernfs]# vi /etc/exports

Step 5: It will be a blank file. write the following.

/home/servernfs * (ew, sync)

Step 6: Restart the services of nfs and enable it form boot .

[root@server servernfs]# service nfs start


[root@server servernfs]# service nfs restart

Step 7: stop the Firewall and check the status wheather it is stopped.

[root@server servernfs]# service iptables stop

[root@server servernfs]# service iptables status

Step 8: Showmount command shows you all shared directions in given IP address.

[root@server servernfs]# showmount-e 192.168.43.252


Export list for 192.168.43.252:
/home/servernfs *
Step 9: Stop the ftp services.

[root@server servernfs]# service vsftpd stop


Shutting down vsftpd:
[root@server servernfs]# service vsftpd status
vsftpd is stopped
[root@server servernfs]#

Step 10: Give full permission to the shared folder.

[root@server servernfs]# chmod -R 777 /home/servernfs/


[root@server servernfs]#

Step 11: List the directory .

[root@server servernfs]# ls

Step 12: Create a clone machine.


1. Click on the VM menu > select clone…
34
2. Click on the Next button.
3. Select clone source > Click on the radio button “The current state in the virtual machine” > Click
on Next.
4. Select CLone type > click on the radio button ” Create a full clone” >click on Next.
5. Give name to the virtual machine and give location
6. Click on the finish button.

Step 13: As NFS Client make a directory /clientnfs and mount the server exported directory on it.

[root@server Desktop]# cd /home/


[root@server home]# ls

[root@server home]# mkdir clientnfs

Step 14: To unmount the file from the client machine, use the unmount command.

[root@server home]# mount -t nfs 192.168.43.252:home/servernfs/ /home/clientnfs/


[root@server home]# ls

[root@server home]# cd clientnfs


[root@server clientnfs]# cat newfile
Hello Linux
[root@server client]

Practical 7(b): Configuring Samba

● Samba is basically used for establishing connection among linux to windows, with help of samba
file sharing can be done using Windows file-sharing protocol and connect your Red Hat
Enterprise network to a windows network to share files and printers.
● Windows use a protocol called Server Message Block (SMB) to communicate with each other and
to share services such as file and print sharing.
● With Samba, the Linux PC icon appears in the Windows Network Places window and the files on
the Linux PC can be browsed using Windows Explorer.
● The Windows File system can be mounted on your Linux System , and you can browse
theWindows files from your Linux PC. Before using Samba to connect to the Windows computers,
it must first be installed on the Linux PC.
● All current distributions of Linux include three Samba packages:
- Samba
- Samba-client
- Samba-common

Step 1: Create linux users

[root@server ~]# cd /media/RHEL_6.0/ x86_64 \Disc\1/Packages


35
[root@server Packages]# useradd osr
[root@server Packages]# passwd osr

Step 2: Create a directory /data on the Linux file system on the Samba server.

[root@server Packages]# mkdir /data


[root@server Packages]#

Step 3: Give full permissions to this directory

[root@server Packages]# chmod 777 /data


[root@server Packages]#

Step 4: Set directory with the samba_share_t type, if you want to treat the files as samba share data

[root@server Packages]# chcon -t samba_share_t /data


[root@server Packages]#

Step 5: Create a Samba user account that has access to the share.

[root@server Packages]# smbpasswd -a osr


New SMB password:
Retype new SMB password:
[root@server Packages]#

Step 6: Define the share in /etc/samba/smb.conf

[root@server Packages]#vi /etc/samba/smb.conf

And make the following changes by going to end of the file->Press Esc->:$

A]At the end of the file copy 7 lines and paste it


B]To copy 7 lines –type 7yy and save

Step 7: Install the samba packages


Click on install.

[root@server Packages]# rpm qa | grep samba

Step 8: Start the smb service

[root@server Packages]# service smb restart

Step 9: Bring it on thr run level


36
[root@server Packages]# chkconfig smb on

Step 10: Turning off firewall

1. System->Administration->firewall
2. Press close and disable
3. Click on apply and yes

Step 11: Go to windows and Run command Type ping 192.168.214.128 >click on ok.

Practical 7(c):Configuring FTP


FTP server is used to transfer files between server and clients.
● All major operating system supports FTP.
● FTP is the most used protocol over internet to transfer files. Like most Internet operations, FTP
works on a client/ server model.
● FTP client programs can enable users to transfer files to and from a remote system running an
FTP server program.
● Any Linux system can operate as an FTP server.
● It has to run only the server software—an FTP daemon with the appropriate configuration.
Transfers are made between user accounts on client and server systems.
● A user on the remote system has to log in to an account on a server and can then transfer files to
and from that account's directories only.
● A special kind of user account, named FTP, allows any user to log in to it with the username
“anonymous.”
● This account has its own set of directories and files that are considered public, available to
anyone on the network who wants to download them.
● The numerous FTP sites on the Internet are FTP servers supporting FTP user accounts with
anonymous login.
● Any Linux system can be configured to support anonymous FTP access, turning them into network
● FTP sites. Such sites can work on an intranet or on the Internet.
37
Configuring the FTP Server
● The vsftpd RPM package is required to configure a Red Hat Enterprise Linux system as an ftp
Server.
● If it is not already installed, install it with rpm commands.
● After it is installed, start the service as root with the command service vsftpd start .
● The system is now an ftp server and can accept connections.
● To configure the server to automatically start the service at boot time, execute the command
chkconfig vsftpd on as root.
● To stop the server, execute the command service vsftpd stop.
● To verify that the server is running, use the command service vs ftpd status.

Step 1: Verify the package vsftpd for FTP. If installed, create few files in the pub. it is shown below.

[root@server ~]# rpm –qa | grep vsftpd

This command returns the version of vsftpd.If package vsftpd is not installed then install using
following command.
#rpm – ivh vsftpd*
#rpm –ivh ftp*

[root@server ~]# cd /media/RHEL_6.0/ x86_64 \Disc\1/Packages


[root@server Packages]# rpm – ivh vsftpd*

[root@server Packages]# rpm – ivh ftp*

Step 2: Check whether the package is install or not with #rpm –qa | grep ftp command

[root@server Packages]# rpm - qa | grep ftp

Step 3: Now use the following command to start vsftpd services at boot time using chkconfig command.

[root@server Packages]# chkconfig vsftpd on

Step 4: Create a file in pub directory

[root@server Packages]# cd /var/ftp/pub/


[root@server pub]# cat > ftpfile
Hello
This is my FTP file for testing!
[root@server pub]#

38
Use ctrl+d to save and exit

Step 5: Verify IP address of linux machine to be configured as FTP

[root@server pub]# ifconfig

Step 6: Open the configuration file


#vi /etc/vsftpd/vsftpd.conf
1.Uncomment anonymous_upload_enable = YES

[root@server pub]# vi /etc/vsftpd/vsftpd.conf

Save and exit

Step 7: Restart the vsftpd service

[root@server pub]# service vsftpd restart

Step 8: Login with an anonymous user.


Now you can login with ftp 192.168.1.1
We can use Username: anonymous and password for same is blank.
Here you can use ls –a command to view the content of ftp home directory.
ftp> ls –a

[root@server pub]# cd
[root@server ~]# ftp 192.168.21.129

To log off from ftp we use bye command

Step 9: Allow ftp anonymous write enable as follows:

[root@server ~]# getsebool –a | grep ftp


[root@server ~]# setsebool –P allow_ftp_annon_write= 1

Step 10: Allow System user to get access to ftp server

[root@server ~]# setsebool –P ftp_home_dir on


[root@server ~]# getsebool –a | grep ftp

Step 11: By default /var/ftp is ftp user Home directory. Check the context of file
/var/ftp/pub and change to ftp

[root@server ~]# ls –ldZ /var/ftp/pub


39
[root@server ~]# chown ftp /var/ftp/pub
[root@server ~]# chgrp ftp /var/ftp/pub
[root@server ~]# ls –ldZ /var/ftp/pub

Step 12: Create a file in the pub directory and create one file.
#cd /var/ftp/pub
#touch T1 T2 T3
#cat > ftptest
Welcome to ftp server
To save the document use ctrl+d

[root@server ~]# cd /var/ftp/pub


[root@server pub]# touch F1 F2 F3
[root@server pub]# cat>ftpfile.txt
Welcome to ftp server.
[root@server pub]# ls

Step 13: Restart the service of vsftpd and enable it from root
Also give full permission to the directory /var/ftp/pub. service vsftpd start
#service vsftpd restart
#chkconfig vsftpd on
#chkconfig –list | grep vsftpd

[root@server pub]# service vsftpd restart

[root@server pub]# service vsftpd status

[root@server pub]# chkconfig --list |grep vsftpd

[root@server pub]# chmod -R 777 /var/ftp/pub

Step 14: Now FTP is configure.Test as FTP client from another machine. Use the following command.
#ftp:192.168.21.129/pub/

After opening the file ftpfile.txt

Welcome to ftp server

40
Practical 8: DNS, DHCP and Mail Server

Practical 8(a): Configuring DNS

Name address resolution is simply the conversion of people friendly names into computer friendly
numbers.
● It means that every interface on the network has a unique group of numbers
called as IP address.
● These groups of numbers are present to the computers in the network but it is difficult for the
users to by heart, learn or remember them.
● DNS makes it possible for the users to enter the names and then these names get converted into
numbers.
● The main function of name address resolution is to create an efficient user and computer
interaction.
● For this name address resolution there is a need for how to install and configure the Domain
Name System.
● To understand, take a look at the domain and understand its working. For eg. example.com.
41
● In the above eg: The first part of the domain name is the name of the company or institution or
an organization. The next part after the period/dot is called a top-level domain (TLD).

There are many TLD listed below:


● .com - A TLD used to register a business
● .edu – A TLD for educational institution
● .name – A TLD used to register sites for individuals
● .gov – A TLD given to government
● .mil – A TLD used for military
● .org – A TLD used by a non-commercial organization

Following files are used while Configuring DNS Server.


● named.conf – It is the main Configuration file that contains global properties and other sources. It
is found in / etc/ directory.
● named.ca – The file contains the name and address of root servers. Used for the purpose of
caching the forward zone. It is found in /var/named.
● named.local – The file provides information for resolving the loopback address for the local host.

Also called as named.empty, used for the purpose of caching of reverse zone.
It is found in /var/named/
The 2 additional files required for the master domain server are:
(i) zone – This file contains the names and addresses of hosts in the local domain and maps names
to the IP address.
(ii) reverse.zone – This file provides information to map ip-address to names Hence reverse.

DNS Configuration:

Step 1: Check your machine’s IP Address


#ifconfig

[root@localhost ~]# ifconfig

Step 2 : #vim /etc/sysconfig/network-scripts/ifcfg – eth0

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg – eth0

DEVICE=”eth0”
HWADDR=”00:0C:29:A6:A0:E9”
NM_CONTROLLED=”yes”
ONBOOT=”yes”
TYPE=Ethernet
DNS1=192.168.21.129
IPADDR=192.168.21.129

42
Step 3: #vim /etc/hosts

[root@localhost ~]# vim/etc/hosts

192.168.21.129 server.tyit.com server

Step 4: Enter the hostname


#vim /etc/sysconfig/network

[root@localhost ~]# vim /etc/sysconfig/network

NETWORK=yes
HOSTNAME=server.tyit.com

Step 5: #vim /etc/resolv.conf

[root@localhost ~]# vim /etc/resolv.conf

# Generated by NetworkManager
search tyit.com
nameserver 192.168.21.129

Step 6: Restart the network


#service network restart

[root@localhost ~]# service network restart

Step 7: To install the bind package


Desktop->CD->Packages->bind->install OR use command rpm –ivh bind*
Query to check whether bind package is installed

[root@localhost ~]# cd /media/RHEL_6.0/ x86_64 \Disc\1/Packages


[root@localhost Packages]# rpm -ivh bind*

#cd

[root@localhost ~]# rpm -qa |grep bind*

Step 8: vim /etc/named.conf.

[root@localhost ~]# vim /etc/named.conf

Line no.11 :- Listen – on port 53 {192.168.21.129}


Change this from 127.0.0.1 to current Machine IP address.
43
Line no.12 :- Comment it using “#”
# listen –on – v6 port 53{ : : 1:};
Line no.17 :- allow – query{any;}

Check and Note Down the last line of the file :-


Copy the last line “/etc/named.rfc1912.zones”

Include “/etc/named.rfc1912.zones”;

Save and quit

Step 9: #vim /etc/named.rfc1912.zones

[root@localhost ~]# vim /etc/named.rfc1912.zones

Following changes has to be done:


Line no 13:change zone “localhost.localdomain” IN to zone “tyit.com” IN
Line no 15:change file “named.localhost” to file “forward.zone”
Line no 31:change zone “1.0.0.127.in-addr.arpa” IN to zone “21.168.192.in-addr.arpa” IN
Line no 33:change file “named.loopback” to file “reverse.zone”

Zone “tyit.com” IN{


type master;
file “forword.zone”;
allow-update { none; };
}

Zone “localhost” IN{


type master;
file “named.localhost”;
allow-update { none; };
}

Zone “21.168.192.in.addr.arpa” IN{


type master;
file “reverse.zone”;
allow-update { none; };
}

Save and quit

44
Step 10: Go to named directory present in var
#cd /var/named

Step 11: #cp named.localhost forward.zone

Step 12: #cp named.localhost reverse.zone

After this type ls to list the files.


You can see two files are copied i.e forward.zone and reverse.zone

[root@localhost ~]# cd / var/named/


[root@localhost named]# ls

Step 13: Open forward.zone

[root@localhost named]# vi forwoard.zone

Step 14: Open reverse.zone

[root@localhost named]# vi reverse.zone

Step15: # chgrp named forward.zone

[root@localhost named]# chgroo named forward.zone

Step16: # chgrp named reverse.zone

[root@localhost named]# chgrp named reverse.zone

Step17: #service named start

[root@localhost named]# service named start


Starting name:

DNS configuration s successful


To check whether DNS is working

Step18: Use dig command

[root@localhost named]# dig server.tyit.com

OR

[root@localhost named]# dig –x 192.168.21.129


45
Practical 8(b): Configuring DHCP

DHCP, or Dynamic Host Configuration Protocol, allows an administrator to configure network


settings for all clients on a central server. The DHCP clients request an IP address and other network
settings from the DHCP server on the network. The DHCP server in turn leases the client an IP
address within a given range or leases the client an IP address based on the MAC address of the
client's network interface card (NIC). The information includes its IP address, along with the
network's name server, gateway, and proxy addresses including the netmask. Nothing has to be
configured manually on the local system, except to specify the DHCP server it should get its
network configuration from. If an IP address is assigned according to the MAC address of the
client's NIC, the same IP address can be leased to the client every time the client requests one.
DHCP makes network administration easier and less prone to error.

Configure dhcp server:

We will configure a dhcp server and will lease ip addresses to clients. We are using two systems:
one linux server and one linux client. dhcp rpm is required to configure the dhcp server.

Step 1: First we have to check whether DHCP is available on our machine or not that we can check with
rpm command.

[root@server ~]# cd /media/RHEL_6.0/ x86_64 \Disc\1/Packages


[root@server Packages]# rpm -ivh dhcp*

Step 2: Query the installed dhcp package.

[root@server Packages]# rpm -qa | grep dhcp

Step 3: Check the hostname of your linux system.

[root@server Packages]# hostname


server.tyit.com
[root@server Packages]#

Step 4: Run the setup command from root user

[root@server Packages]#setup

To assign IP to dhcp server

Step 5: DHCP server have a static a IP address.First configure the IP address 192.168.43.243 with
46
netmask255.255.255.0 on server.

Step 6: This will launch a new window select Network Configuration.

Step 7: Select Device Configuration.

Step 8: Select your LAN card(If you don’t see any LAN card here means you haven’t installed the driver)

Step 9: Select Use DHCP option and remove the[*] dhcpd option.
To remove [*]press Spacebar
Now Enter static IP Address
Static IP 192.168.43.252
Netmask 255.255.255.0

Step 10: Click on ok,Quit and again Quit to come back on root prompt.

Step 11: To disable the network we use the following command.

[root@server Packages]# ifdown eth0

Step 12: To enable the network we use the following command.

[root@server Packages]# ifup eth0

Step 13: Open the configuration file dhcpd.conf which represents in /etc/dhcpd directory.

[root@server Packages]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

Step 14: Restart the dhcp service, stop the firewall.

[root@server Packages]# service dhcpd start


[root@server Packages]# service dhcpd restart

[root@server Packages]# chkconfig --list dhcpd

[root@server Packages]# chkconfig dhcpd on


[root@server Packages]# chkconfig --list dhcpd

[root@server Packages]# service iptables stop

[root@server Packages]# setenforce 0

Step 15: After that create a clone machine.

47
Step 16: The final output is that IP address which is given as a range.

[root@server Packages]# ifconfig

Practical 8(c): Setting Up a Mail Server

A. configuring mail with mutt

Step 1: Installation of sendmail packages.

Step 2: Create a new user and set a password.

[root@server ~]# useradd linda


[root@server ~]# passwd linda

Step 3: Writing a mail.

[root@server ~]# mail -s hello linda


Hii linda
How are you???
EOT
[root@server ~]# su -linda
[linda@server ~]$ mutt

[1]+ Stopped mutt


You have mail in /var/spool/mail/linda

Step 4: Reading mail from root.

B. Install and configure postfix mail server

Step 1: Installation of postfix packages.

Step 2: Restart the basic services.


[root@server Desktop]# cd
[root@server ~]# cd /media/RHEL_6.0/ x86_64 \Disc\1/Packages
[root@server Packages]# /etc/init.d/postfix start
[root@server Packages]# /etc/init.d/postfix restart
48
[root@server Packages]# chkconfig postfix on
[root@server Packages]# chkconfig --list postfix

Step 3: Open the configuration file.

[root@server Packages]# vi /etc/postfix/main.cf

Step 4: Change the myhostname to your fully qualified domain name.

#inet_intefaces = all
#inet_intefaces = $myhostname
#inet_intefaces = $myhostname, localhost
#inet_intefaces = localhost

Step 5: Uncomment the line and changes my networkfrom 169.100.189.0./28 to 192.168.1.0/28

#mynetworks = 192.168.1.0/28, 127.0.0.0/8


#mynetworks = $config directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table

Step 6: Uncomment the mail_spool_directory=/var/spool/mail

Step 7: Restart the postfix service.

[root@server Packages]# service postfix restart

[root@server Packages]# cd
[root@server ~]# mail [email protected]
Subject: to check mail through postfix
Hii lisa
EOT

[root@server ~]# mail [email protected]


Subject: linux
Complete linux Practical..
EOT
[root@server ~]# su -lisa
[lisa@server ~]# mail

49
Practical 9:Web Server

Practical 9(a): Configuring Apache on Red Hat Enterprise Linux

● When you view a web page over the Internet, the code to create that page must be retrieved from
a server somewhere on the Internet.

50
● The server that sends your web browser the code to display a web page is called a web server.
There are countless web servers all over the Internet serving countless websites to people all over
the world.
● Whether you need a web server to host a website on the Internet a Red Hat Enterprise Linux
server can function as a web server using the Apache HTTP server.
● The Apache HTTP server is a popular, open source server application that runs on many UNIX-
based systems as well as Microsoft Windows.
● Since we had created DNS named as server.tyit.com but on Linux browser it is showing unable to
connect because we need to configure apache web server , so that we can display out html page
on web browser with the help of our own DNS server.tyit.com

Configure web server


We will configure a web server. The necessary rpm for web server is httpd, httpd- level and check
them for install.
#rpm –ivh httpd*
#rpm –qa | grep httpd

[root@localhost Desktop]# cd
[root@localhost ~]# rpm –qa | grep httpd

[root@localhost ~]# ifconfig

[root@localhost ~]# chkconfig httpd on


[root@localhost ~]# service httpd start

[root@localhost ~]# service httpd status

Configure virtual hosting


In this example we will host a website www.tyit.com to apache web server. Create a documents root
directory for this website and a index page

[root@localhost ~]# mkdir -p /var/www/virtual/www.tyit.com/html/

[root@localhost ~]# vi /var/www/virtual/www.tyit.com/html/index.html

<html>
<head>Linux Apache Website</head>
<body>
Apache web server practical
</body>
</html>

Check for DNS by following command:


# dig –x 192.168.21.129
51
[root@localhost ~]# cd /var/named
[root@localhost named]# service named start
[root@localhost named]# dig -x 192.168.21.129

Now open /etc/httpd/conf/httpd.conf main configuration file of apache server.


#vim /etc/httpd/conf/httpd.conf

[root@localhost named]# cd
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

Locate virtual host tag


Now go to the end of the file and copy the last seven lines [ virtual host tag ] and paste them in the end
of file.
Remove the comments from all 7 lines

You have done necessary configuration now restart the httpd service and test this configuration run
links command.
#service httpd restart
#chmod –R 777 /var/www/virtual/www.tyit.com/html/

[root@server ~]# service httpd restart

[root@server ~]# chkconfig httpd on


[root@server ~]# chmod -R 777 /var/www/virtual/www.tyit.com/html/

Go to the Clone and open browser and type server.tyit.com OR 192.168.21.129


You can view your web page.
[root@server ~]# elinks http://192.168.21.129

Practical 9(b): Writing a Script to Monitor Activity on the Apache Web Server

Step 1: Creating a new script

[root@localhost Desktop]# cd
52
[root@localhost ~]# gedit test.sh

Step 2: Write the code

#!bin/bash
#Monitoring process httpd
COUNTER=0
While ps aux | grep httpd | grep -v grep > /dev/null
do
COUNTER=$((COUNTER+1))
sleep 1
echo COUNTER is $CONUTER
done
logger HTTPMONITOR: http stopped at ‘date’
service httpd start
mail -s Apache server just stopped root

Save this file as test.sh

Step 3: Assign execute permission and execute the script

[root@server ~]# chmod –R 777 test.sh


[root@server ~]# sh test.sh

Step 4: Open another terminal and stop httpd.

[root@server ~]# cd /media/RHEL_6.0/ x86_64 \Disc\1/


[root@server RHEL_6.0/ x86_64 \Disc\1]# service httpd stop

Step 5 : After stopping httpd service the script will start the httpd service automatically

Practical 9(c): Using the select Command, Write a simple script that asks the user to enter
the name of an RPMor file that the user wants to query. Write the script to present a menu
that provides different
options that allow the user to do queries on the RPM database
The following options must be presented:
53
a. Find the RPM from which this file originates.
b. Check that the RPM where the user has provided the name is installed.
c. General info of this RPM.
d. Remove this RPM.

Step 1: Login as root permission on file in vi editor.

[root@server Desktop]# cd
[root@server ~]# vi smapel1.sh

Step 2: write a code and save it.

#!bin/bash
echo Enter the name of RPM or file
read RPM
echo Select a task from menu
Select Task in ‘check from which RPM this file comes’ ‘check if this RPM installed’ ‘General info of this
RPM’ ‘Remove this RPM’
do
case $REPLY in
1) TASK =” rpm -q $RPM”;;
2) TASK= ” rpm -qa | grep $RPM”;;
3) TASK =” rpm -qi $RPM”;;
*) echo error&& exit 1;;

esac
if [-n TASK ]
then
clear
echo you have selected TASK
$TASK
else
echo invalid choice
fi
done

Step 3: Give permission to file for execution.

[root@server ~]# chmod +x smapl1.sh


[root@server ~]# ./sample1.sh
Enter the name of RPM or file
ftp
Select a task from menu
1)check from which RPM this file comes
54
2)check if this RPM installed
3)General info of this RPM
4)Remove this RPM
#? 1

you have selected TASK


package ftp is not installed

#? 3

you have selected TASK


package ftp is not installed
#? 4

error
[root@server ~]#

Practical 10: Shell script


55
Practical 10(a): Writing Shell Scripts

1) Write a shell script to accept two numbers and to print its


a. addition
b. product
c. a / b.
d. (a + b) – c

Step 1: Login as root permission on file in vi editor.

[root@server~]# vi operation.sh

Step 2: write a code and save it.

#!bin/bash
echo “Enter the first number :”
read n1
echo “Enter the second number:”
read n2
echo “Enter the third number:”
read n3
sum =$(($n1 + $n2))
echo Addition is =$sum
product =$(($n1 * $n2))
echo Product is =$product
div =$(($n1 / $n2))
echo Division is =$div
ans=$(($n1 + $n2 -$n3))
echo Answer is =$ans

Step 3: Give permission to file for execution.

[root@server ~]# chmod +x operation.sh


[root@server ~]# ./operation.sh
Enter the first number :
10
Enter the second number:
5
Enter the third number:
2
Addition is 15
Product is 50
Division is 2
56
Answer is 13
2)Program to print the day of the week using case.. In

Step 1: Login as root permission on file in vi editor.

[root@server~]# vi days.sh

Step 2: write a code and save it.

echo Enter the day number


read num
case $num in
1) echo Sunday;;
2) echo Monday;;
3) echo Tuesday;;
4) echo Wednesday;;
5) echo Thursday;;
6) echo Friday;;
7) echo Saturday;;
*) echo Enter the number bet 1 to 7;;
esac

Step 3: Give permission to file for execution.

[root@server ~]# chmod +x days.sh


[root@server ~]# ./days.sh
Enter the day number
5
Thursday

3) Program that demonstrates the use of if..else with test

Step 1: Login as root permission on file in vi editor.

[root@server~]# vi no.sh

Step 2: write a code and save it.

echo Enter any number


read n
if test $n -gt 0
then
57
echo $n is positive
else
echo $n is negative
fi

Step 3: Give permission to file for execution.

[root@server ~]# chmod +x no.sh


[root@server ~]# ./no.sh

Enter any number


4
4 is positive

4) Program to check existing file

Step 1: Login as root permission on file in vi editor.

[root@server~]# vi file.sh

Step 2: write a code and save it.


echo Enter the File Name
read fname
if [ -f $fname ]
then
echo The File exists
else
echo File with the name $fname does not exists
fi

Step 3: Give permission to file for execution.

[root@server ~]# chmod +x file.sh


[root@server ~]# ./file.sh
Enter the File Name
prog5.sh
The File exists

5) Program for string comparison

Step 1: Login as root permission on file in vi editor.

[root@server~]# vi str.sh
58
Step 2: write a code and save it.

echo Enter the two Strings


read str1 str2
if [ $str1 = $str2 ]
then
echo The strings are identical
else
echo The strings are not identical
fi

Step 3: Give permission to file for execution.

[root@server ~]# chmod +x str.sh


[root@server ~]# ./str.sh

Enter the two Strings


RAM RAM
The strings are identical

6) Program to print first n number and their sum: while loop

Step 1: Login as root permission on file in vi editor.

[root@server~]# vi sum.sh

Step 2: write a code and save it.

i=1
sum=0
while [ $i -le 10 ]
do
echo $i
sum=`expr $sum + $i`
i=`expr $i + 1`
done
echo The sum is: $sum

Step 3: Give permission to file for execution.

[root@server ~]# chmod +x sum.sh


[root@server ~]# ./sum.sh

59
1
2
3
4
5
6
7
8
9
10
The sum is: 55

7) Program to print table

[Step 1: Login as root permission on file in vi editor.

[root@server~]# vi table.sh

Step 2: write a code and save it.

echo "Print table"


j=1
echo Input number
read x
for i in 1 2 3 4
do
j=`expr $x \* $i`
echo $j
i=`expr $i + 1`
done

Step 3: Give permission to file for execution.

[root@server ~]# chmod +x table.sh


[root@server ~]# ./table.sh

Print table
Input number
5
5
10
15
20
60
Practical 10(b): Configuring Booting with GRUB.

Step 1:

[root@server ~]# vi /boot/grub/grub.conf


[root@server ~]#

Step 2: Change From Red Hat Enterprise Linux to Red Hat Recovery in grub.conf file

Step 3:Right click on below given tab Power ->Restart.

Step 4:Before complete counting press any key from Keyboard.

61

You might also like