Day3 - Linux Complex Workflows
Day3 - Linux Complex Workflows
Linux uses single rooted, inverted tree like file system hierarchy
The directories and their description
a. / this is top level directory
it is parent directory for all other directories
it is called as ROOT directory
it is represented by forward slash(/)
cat command is used to create file and diplay the contents of file also
Note: If we use the same file name which already exits it will overwrite the old file with new file.
ex # cat file1
type the contents of file here
This is a
Sample data stored
In the file with out opening using cat using cat command
# cat -n file
Touch command is used to create multiple files with zero bytes size.
syntax # touch <filename>
ex # touch file1
ex # touch file2 file3 file4
To create a directory
mkdir..... make directory
syntax # mkdir <dirname>
ex 1: # mkdir dir1
ex 2: # mkdir dir1/dir2
ex 3: # mkdir dir1/dir2/dir3
ex 4: # mkdir -p india/ap/hyd/galaxy
ex : 1 [root@sys10~]# cd /var/log
[root@sys10 log]# pwd
/var/log
[root@sys10 log]# cd /root
[root@sys10~]# pwd
/root
Of the two move (mv) commands, the first moves the file abc to the file def in the same
directory (essentially renaming it), whereas the second moves the file abc to your home
directory (~). The first copy command (cp) copies abc to the file def, whereas the second
copies abc to your home directory (~). The first remove command (rm) deletes the abc file;
the second removes all the files in the current directory (except those that start with a dot).
NOTE: For the root user, the mv, cp, and rm commands are aliased to each be run with the -i
option.
This causes a prompt to appear asking you to confirm each copy and removal, one file at a time.
For file moves, the -i option will prompt you if the move would overwrite a file, but you may still
unintentionally move a file, so be careful. This is done to prevent the root user from messing up a
large group of files by mistake.
To temporarily get around an alias, type the full path to the command (for example,
/bin/rm -rf /tmp/junk/*).
This command will copy file1 file to /usr directory with same name.
Ex 1: # cp /root/file1 /root/one/two/three/file123
this command will copy file1 file to three directory with file123 name.
ex 2: # cp a* /var
This command will copy all files starting with the alphabet a to /var directory.
By default cp command will not copy directory we have to use -r (recursively) switch to copy directory
Ex 3: # cp -r /root/dir2 /usr
This command will copy all the contents of dir1 directory to var directory
To delete a file:
ex 1: # rm /root/file1
it will ask for confirmation, press y to delete file
ex 2: # rm -f /root/file2
it will not ask for confirmation
ex 4: # rm -rf /root/dir2
this command will delete dir2 directory with all its contents,
without confimation. f for (forcefully)
Ex 1: # rmdir one/two/three
Ex 2: # rmdir one/two
Ex 3: # rmdir one
ex 2: # mv /root/file2 /root/newfile
this command will rename file2 file to newfile
Nautilus is a tool with which we can check the files/dirs in GUI mode. run the command in terminal in gui mode.
BASIC COMMANDS
This command is used to list the contents of a directory generally following options are used with 'ls' (list
directories)
a. [root@sys10~]# pwd
/root
b. [root@sys10boot]# pwd
/boot
# bc to open calculator
Help commands :-
ex: 1 a. # whatis ls
b. # whatis mkdir
b. # man ls
(or)
# info ls
this is command mode editor for files other editors are emacs, gedit vi editor is most popular it is having 3 modes:
1. command mode
2. insert mode (edit mode)
3. execution mode
vi filename edit filename starting at line 1
vi -r filename recover filename that was being edited when system cra
Command mode:
dd to delete a line (cut)
4dd to delete 4 lines (cut)
dw to delete a word
dl (or) x to delete a character
yy to copy a line (yank)
10yy to copy 10 lines (yank)
yw to copy a word
yl to copy a character
p to paste lines below cursor position
10p to paste line 10 times
P to past lines above cursor position
r to replace a character
u to undo
ctrl+r to redo
/<find> to find a text inside a file
shift zz to save and quit from command mode
3w to move cursor after 3 words
Execution mode:
:w to save the file
:wq to save and quit
:x to save and quit
:q to quit without saving
:q! to quit without saving (forcefully)
:wq! to save and quit file (forcefully) {used for read only files}
:se nu to set line Number
:se nonu to remove line Number
:14 to move cursor to line no. 14
:/find word to find for a word
:r /root/file1 to read the contents of file1 file in the present file
:w >> /root/file2 to append the data of present file to /root/file2
:1,$d to delete entire contents of a file
ex: :1,$s/this/that
% complete file
10,$ from 10th line to last line
15,20 from 15th line to 20th line
To find cat, CAT, Cat, cAT and replace with dog in complete file
ex. :1,$s/cat/dog/gi
Create USER:
syntax. # useradd <option> <username>
options are
-u user id
-G Secondary group id
-g primary group id
-d home directory
-c comment
-s shell
-o overwriting the id
Note:- when a account is locked it will show !(exclamation mark) in /etc/shadow file.
To set password:
syntax. # passwd <username>
ex. 1 # passwd user1
enter the password
GROUPS
To create a group:
syntax. # groupadd <option> <groupname>
options:
-g to set GID
ex. 1: # groupadd -g 1010 sales
ex. 3: # gpasswd -d user1 sales to delete secondary user from member list
note: All information of group is stored in /etc/group file it contain list of secondary members also.
PASSWORD POLICY:
More and less commands are used to see the contents of a file page wise.
syntax. # more <filename>
ex 1. # more file1
Now to see contents page wise press space to see contents line wise press enter
Less command is same as more but to quit less command we have to press q
#less <filename>
#less file1
REDIRECTION
This command will APPEND the contents of file1 to file2.
# cat file1 >> file2
# sort file1
# sort -b file1
Cut:
cut is used to give the output of selected fields of each line of a file.
# cut -f1 -d /etc/passwd
ADMINISTRATIVE TOOLS
This task is to create "auto" dir in /root at 03:05pm on 24/04/08 The task will be completed in background
At or batch this command is used to schedule task for one time only:
# at 13:30 or batch 13:30
at> touch /root/breaktime
at> (press ctrl+d to save)
To check it
# atq it will diplay task no. and time
ex.
# at 13:29
at> eject
at> ctrl+d
# at 13:30
at> eject -t
at> ctrl+d
# at 13:31
at> eject
at> ctrl+d
-x to extract archive
-z to zip archive using gzip
-j to zip archive using bzip2
After creating tar how to zip there are two zip commands used, gzip/gunzip and bzip2/bunzip2 bzip2 is more
powerfully than gzip
0 -[zero]full backup.
u - updates in dumpdates file.
f - file.
Note: While using dump command v need to create a new filesystem here /dev/hda8 is a new unformated
filesystem.
Restoring:
# cd /home
PERMISSIONS:-
Permission bits appear as rwxrwxrwx. The first three bits apply to the owner’s
permission, the next three apply to the group assigned to the file, and the last three apply to all
others. The r stands for read, the w stands for write, and the x stands for execute permissions.
If a dash appears instead of the letter, it means that permission is turned off for that associated
read, write, or execute.
You can see the permission for any file or directory by typing the ls -ld command. The
named file or directory appears as those shown in the following example:
$ ls -ld ch3 test
-rw-rw-r-- 1 chris sales 4983 Jan 18 22:13 ch3
drwxr-xr-x 2 chris sales 1024 Jan 24 13:47 test
The first line shows a file (ch3) that has read and write permission for the owner and the
group. All other users have read permission, which means they can view the file but cannot
change its contents (although a user may be allowed to remove the file, since the ability to
remove a file is based on directory permissions). The second line shows a directory (indicated
by the letter d before the permission bits). The owner has read, write, and execute permission,
while the group and other users have only read and execute permissions. As a result, only the
owner can add, change, or delete files in that directory. Any other user, however, can only
read the contents, change to that directory, and list the contents of the directory. (Note that by
using the -d option, the test directory entry is listed without listing its contents.)
If you own a file, you can change the permission on it as you please. You can do this with the
chmod command. For each of the three sets of permission on a file (read, write, and execute),
r is assigned to the number 4, w to 2, and x to 1. So to make permissions wide open for
yourself as owner, you would set the first number to 7 (4 plus 2 plus 1). The same would be
true for group and other permission. Any combination of permissions can result from 0 (no
permission) through 7 (full permission).
Here are some examples of how to change permission on a file and what the resulting
permission would be:
chmod 777 files rwxrwxrwx
chmod 755 files rwxr-xr-x
chmod 644 files rw-r—r
chmod 000 files ---------
You can also turn file permissions on and off using plus (+) and minus (-) signs, respectively.
This can be done for the owner user (u), owner group (g), others (o), and all users (a). For
example, each time starting with a file that has all permissions open (rwxrwxrwx), here are
some chmod examples with resulting permissions after using a minus sign:
chmod a-w files r-xr-xr-x
chmod o-x files rwsrwsrw
chmod go-rwx files rwx------
To set the permission on file/dir 'chmod' command is used bydefault permissions on file and dir:-
file dir
root 644 755
normal user 664 775
here,
read=4
write=2
execute=1
Note:- UMASK- is the number which is removed from full permission of file / dir.
Formula:-
full permissions - umask = default file/dir permissions.
The umask value represents the permissions that are not given on a new file. It masks the
permissions value of 666 for a file and 777 for a directory. The umask value of 022 results in
permission for a directory of 755 (rwxr-xr-x). That same umask results in a file permission
of 644 (rw-r--r--). (Execute permissions are off by default for regular files
TIP: Here’s a great tip for changing the permission for lots of files at once. Using the -R options of
chmod, you can change the permission for all of the files and directories within a directory structure
at
once. For example, if you want to open permissions completely to all files and directories in the
/tmp/test directory, you can type the following:
$ chmod -R 777 /tmp/test
This command line runs chmod recursively (-R) for the /tmp/test directory, as well as any files or
directories that exist below that point in the file system (for example, /tmp/test/hat,
/tmp/test/hat/caps, and so on). All would be set to 777 (full read/write/execute permissions).
SUID userlevel
SGID Grouplevel
Stickybit others level
# whereis ping
/bin/ping
# ls -ld /bin/ping
-rwsr-xr-x ..........
````` this means SUID is set bydefault
To remove SUID:
# chmod 0755 /bin/ping
# ls -ld /bin/ping
-rwxr-xr-x ................
```` this means SUID is removed
To check:
log in as normal user and try to ping
it will display error..... Operation not permitted
SGID:- SGID is used for group inheritance, files and directories will Get groupname from their parent directory.
ex.
# mkdir /mywork
# chmod 777 /mywork
# groupadd sales
# chgrp sales /mywork
# chmod 2777 /mywork
# ls -ld /mywork
Now login with any user and create some files/dirs in /mywork directory and check the properties of files and
dirs, groupowner will be same as of parent directory. If sgid is disabled there will be a change in the group owner
for the files which r newly created.
Sticky Bit:- If sticky bit is set for a directory then only owner can delete the files/dirs in that dir.
ex.
# mkdir /mywork
# chmod 1777 /mywork
# ls -ld /mywork
To remove stickybit.
# chmod 0777 /mywork
Note:- 1Block=1KB Id is used by system to identify the type of partition. * means it is a boot partition.
To check partition:-
# fdisk -l
To delete partition:-
first note the partition no. by using 'fdisk -l' command.
for example----/dev/hda9
then,
# fdisk /dev/hda
command(m for help) : d
partition no.(1-9) : 9
command(m for help) : w
# partprobe /dev/hda
Note:- Do not delete the partitions which are already existing. Delete only those partitions which we have
created
To format partition:-
mkfs command is used to make file system.
mount command is also used to check whether the partition is mounted or not.
# mount (press enter) it will show all currently mounted partitions
To Remove label:
# e2label /dev/hda9 ""
Note: unmount the partitions before converting/tunning.
This command will list the free & used space of all the partitions which r mounted.
# df -h
This command will list the free & used space of a single partition which is mounted.
# df -h /dev/hda2
This command will list the free & used space and filesystem type of all the partitions which r mounted.
# df -hT
This command will list the used space of each & every file/dir in the /usr directory.
# du -h /usr
To Mount Cd Rom.
# mount /dev/cdrom /mnt
# cd /mnt
# ls
To Mount Dvd.
# mount /dev/dvd /mnt
To Mount floppy.
# mount /dev/fd0 /mnt
LINKS
Links are shortcuts, pointers for easy accessing of a file/dir.
There are two types of Links:-
2.size of both files are same. size of link file is equal to no.
of characters in the name of source file.
3. inode no's of both the files are same. inode no's of source and link files are different.
4. if original file is deleted then also link file can be if original file is deleted then link file
accessed. cannot be accessed
5. link file is a copy of source file. link file is dependent on source file.
To check use:-
# ls -ali <source file> <target file>
Compressing/zipping Tools.
# gzip <file name>
# gzip /var/file1
# ls -ld /var/file1.gz
ACL's
Acl's refers to assigning different privileges for users who come under others category. They are of 2 types.
1. user level [appling on individual users]
2. group level [appling on multiple users/groups]
Note: Remount the partition in which u have the files with acl permissions.
To create users.
# useradd sam
# useradd john
To set acls for a user.
# setfacl -m u:sam:rw /file1 [-m modify,u user,]
# setfacl -m u:john:- /file1
Create group.
# groupadd sales
To remove acls.
# setfacl -x u:sam /file1 [users]
# setfacl -x g:sales /file1 [groups]
DISK QUOTAS
quota's are used to restrict the amount of disk usage by any user, group on a particular partition.
QUOTA
user level . group level
blocks inodes .blocks inodes
(size in kb) (no. of files) .(size in kb) (no. of files)
inode:- Index node no. it is used by system to identify the properties of file like, file type, permission, owner,
group, size in blocks, no. of links, time stamps.
options:-
-c to create quota database files
-u user quota
-g group quota
-v verbose
Note: group level quota should b applied on primary groups only.
Add a group.
# groupadd mrkt
here,
soft means --- limit after which warning message is displayed
hard means --- limit after which error message is displayed
RAID
Redundant Array of Inexpensive/Independent Disk
2 or more hard disk are combined to create RAID, it is used in servers with SCSI Harddisk.
To check it:-
ex. # mdadm -D /dev/md0
it will show faulty device----- /dev/hda10
To check:-
ex. # mdadm -D /dev/md0
it will show spare building for some time. Then it will show active synchronous.
In linux, lvm is used to create logical partitions, called as logical volumes. we can easily resize logical volumes,
without data loss. LVM can be created using one or more harddisk. We will implement LVM on 3 different
partitions of single harddisk.
# cd /mnt
# touch 1 2 3 4 5
To resize LV:-
syntax # lvresize -L +/-sizeM <lvname>
# lvresize -L +10M /dev/cms/linux
# lvresize -L -20M /dev/cms/linux
To remove LV:-
# lvremove /dev/cms/mcsa
RPM options:-
i install package
U(capital U) Upgrade Package
v verbose mode installation
h hash
--force to forcefully install package, overwrite previous
Installation.
--nodeps to remove package but dependency will not be removed.
then mount the shared directory from server to any local directory:-
# mount 192.168.10.10:/var/ftp/pub/Server /mnt
```````````` ``````````````````` ````
IP add of server:/location of shared dir local dir.
go to mount point
# cd /mnt
YUM
YellowDog Updater Modified
yum feature was available with fedora, now it is available in RHEL5 RPM feature is used to install pakages but
its main drawback is Failed Dependency Resolution. yum automatically identifies dependency in pakages,&
install those dependencies also.by using YUM we can install, remove, list pakages and group of pakages.
Repository:- it is the place where we create RPM Dump on server we copy all rpm from RHEL cd/dvd here a list
of all those pakages is created this list of packages is called Repository.
generally we copy all rpm of 'Server' directory of rhel cd/dvd to /var/ftp/pub/Server directory on Server.
yum command :-
# yum install <pakagename> rpm -ivh <pkgname>
# yum remove <pakagename> rpm -e <pkgname>
# yum list installed rpm -qa
# yum list installed <pakagename> rpm -q <pkgname>
# yum grouplist -----
# yum upgrade <pakagename> rpm -Uvh < pkg name>
# yum groupinstall <grpname> -----
Remote copy:-
scp---- secure copy this command is used to copy contents of remote system, we can take remote backup using
this command
ssh is Secure Shell ssh is secure version on telnet it uses port no. 23 like telnet but the data, password sent using
ssh is secure because it encrypts data before sending using ssh we can SHARE REMOTE DESKTOP in text
mode. HOW?
# ssh <ip add of remote pc>
password of root:
To run a command on remote pc:-
# ssh <ip add of remote pc> <command>
# ssh 192.168.1.1 init 0
this command will shutdown 192.168.1.1 pc
Find command :-
# find / -name file1 -> will search for files having a name called file1 from / directory.
# find /home -name file1 -> will search for files having a name called file1 from /home
Directory.
# find / -name '*log*' -> will search all files having a word called log from / directory.
# find / -name *.log -> will search for all files having an extension called .log
# find / -user root -group root -> will search for all files having owner as 'root' and group as 'root'.
# find / -perm 622 -> will search for all files whose permissions are 622.
# find / -size 10k -> will search for all files having the size of 10 kb.
Locate command:-
Locate command will generally search for the database file called /var/lib/mlocate/mlocate.db
this is the database file which should b updated always.
# locate file1 will search for all files having a word called file1. may b [file1.txt or linuxfile1]
# slocate -i file1
# grep linux file1 file2 -> searches for linux word in 2 files [file1,file2]
# grep -i linux file1 -> searches for linux words [cap's & small letters] ignore case-sensitive.
# grep -n linux file1 -> searches for linux words with line numbers in a file1 file.
# grep -r linux /dir1 -> searches for linux words in all files existing in dir1 directory.
r stands for recursively.
# egrep linux file2 file3 -> searches for linux words from 2 files [file2,file3].
# egrep 'linux | solaris| aix' file1 -> searches for 3 words in a file called file1.
# egrep -n linux file1 -> searches for a word called linux from file file1 with line numbers.
# egrep -i linux file1 -> searches for words called linux ignore case-sensitive.
# egrep -r linux /dir1 -> searches for linux words in all files existing under /dir1
Network Configuration:
ifconfig:-
Interface configuration(Network Interface Card)
it is used to set ip addr temporarily
it is also used to check ip addr
To check ip add:-
# ifconfig eth0
it will display ip addr, hardware addr, subnet mask .....
To set ip addr:
# netconfig ( press enter )
ok
192.168.1.X
255.255.255.0
enter
enter
ok
# service network restart
restart network service to update new ip addr
Note:- if netconfig is not working then pakage is not installed you can install this pakage by using rpm/yum.
# system-config-network
or
# neat( Network Administration Tool ) used to set ip addr in Graphical mode
or
# setup
When you assign ipaddress then it is stored in a file called ifcfg-eth0 which is in this directory.
# cd /etc/sysconfig/network-scripts
# ls
# cat ifcfg-eth0
ifup:- interface up
this command will enable lan card
# ifup eth0
To Assign Hostname:
hostname:- This command is used to set hostname temporarily and view hostname
To see hostname:-
# hostname (press enter)
To check log off and log in again and use 'hostname' command
To configure hostname:-
Hostname is pc name
it is used to identify the system on network
bydefault hostname is localhost.localdomain
To see hostname:-
# hostname (press enter)
pakages:- nfs-utils*
portmap*
Services nfs
portmap
Daemon statd,mountd,lockd,nfsd
Steps:-
Server side:-
create share folder:-
# mkdir /share
NOTE:-/share *(ro,async)
Restart service:-
# service portmap restart
# service nfs restart
Client side:-
mount server's dir on /mnt
# mount 192.168.1.10:/share /mnt
Note:- # showmount -e <ip add> this command is used to see what is shared on 'ip add'
FTP SERVER
FILE TRANSFER PROTOCOL- used to upload and download files from ftpserver following are different ftp
server:-
wuftp washington university ftp
proftp
vsftp very secure ftp
Pakages:- vsftpd*.rpm
Port no. 20 for data transfer
21 for connection control
configuration file /etc/vsftpd/vsftpd.conf
/etc/vsftpd/user_list
/etc/vsftpd/ftpusers
services vsftpd
Daemon vsftpd
Steps:-
1. Check for installed pakages
# rpm -q vsftpd
if not installed then install it using nfs method
# mount 192.168.1.10:/var/ftp/pub /mnt
# cd /mnt
# cd /Server
# rpm -ivh vsftpd*
line no.
12 anonymous_enable=YES
to allow anonymous user to log into ftp server user name for anonymous users are,
ftp anonymous
15 local_enable=YES
to allow local users that are created on server machine to log into ftp server from
client side example of local users is user1,user2,raj,ravi
27 anon_upload_enable=YES
to allow users to upload file to ftp server by default any user is not permitted to upload files to server, he
can only download
115 userlist_enable=YES
Note:- if local_enable=YES is given in vsftpd.conf file it means local users of server can also login from client
side
ex. of local users are user1,user2, and even root but bydefault root user is NOT allowed to login from
network so to deny any local user to login into ftp server, enter its name in ftpusers file or user_list file,
and reload the service
To access FTP Server in graphical mode:- open web browser( mozila filefox ) type addr
ftp://<ip addr of ftp server>
like
ftp://192.168.1.10(press enter)
SAMBA SERVER
Windows OS share file/folders using SMB(server message block) protocol
Windows OS share file/folder over tcp/ip by using CIFS(common internet file sharing) method
Linux uses SMBD/NMBD to share file and folders with windows machine for this we have to configure samba
server on linux machine
pakages samba,samba-common,samba-client,swat
portno. 137 NetBIOS name service
138 NetBIOS datagram service
139 NetBIOS session service
configuration file /etc/samba/smb.conf and /etc/samba/smbpasswd
service smb
Daemon smbd, nmbd
go to last line
copy last 8 lines(press yy)
paste at the bottom of file (press p)
now edit last 8 lines by removing ;(comment)
[myshare] .......... this is share name
comment = This is CMS shared directory .... you can type any comment
path = /var/share ................ this is path of shared directory
valid users = user1 ............... space separated list of users
public = no .................... to make folder visible to all
writable = yes .................. to give write permission on folder
browseable = yes .... to see icon of shared folder in my'network places'
FTP method:-
# smbclient //<ip add of server>/<share name> -U username
# smbclient //192.168.1.10/myshare -U user1
smb>ls
smb>get file1
smb>put anyfile
smb>quit
Note :- on samba server you must create user and provide smb password
# useradd user1
# smbpasswd -a user1
*****
*****
PROCESS MANAGEMENT
To manage different process:- system identifies any process by its process id(PID)
To see pid of a running process:-
# service vsftpd status
vsftpd is runnig (3954).......
(this is pid)
or
# ps -ef | grep vsftpd
Note:- PID for init is always 1
To stop a process
# service vsftpd stop
When we restart the service is shutdown and again started, it takes time when we reload service only changes are
reloaded, it is fast
If any service is not responding then we can use kill command to abnormally terminate that process:-
# kill <pid of that process>
# kill 3954
note :- first check the pid of process, then kill it.
pakage dhcp-3.0.5-3.el5
configuration file /etc/dhcpd.conf
/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample
/var/lib/dhcpd/dhcpd.leases
# system-config-network
or
# neat
To give DHCP reservation:- We can bind any MAC addr to a IP addr by using dhcp ip address reservation first
we have to find out the mac addr of client:-
# ifconfig it will show hardware addr
Note:- if you want to see mac addr of client from server machine then
# ping 192.168.1.X
# arp -a (press enter)
DNS server is used to resolve Hostname to IP addr and IP addr to Hostname. DNS server maintains Zone files.
Zonefiles are database which contains information about different server and thier corresponding ip addr
there are two type of zone database files:-
A Address record
Used to show it Ip Addr of any hostname
PTR Pointer record
Used to show hostname of any IP Addr
Note:- DNS works on BIND(Berkely Internet Name Domain) version 9 In RHEL we call bind as
named(nameserver daemon)
Steps:-
check ip addr:-
# ifconfig
if it is not correct set ip addr
# neat
or
# netconfig
restart network service:-
# service network restart
Check hostname
# hostname
if it is not correct then set hostname
# hostname sysX.cms.com
make it permanent:-
# vi /etc/hosts
192.168.1.X sysX.cms.com sysX
# vi /etc/sysconfig/network
hostname=sysX.cms.com
now logout and login again to check hostname
# vi /etc/named.rfc1912.zones
copy line no. 21 to 31 ( 11 lines) paste it below line no. 31 edit these lines:
zone "cms.com" IN {
type master;
file "cms.for";
};
zone "1.168.192.in-addr.arpa" IN {
type master;
file "cms.rev";
};
change directory:-
# cd /var/named/chroot/var/named
$TTL 86400
@ IN SOA sys10.cms.com. root.cms.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS sys10.cms.com.
IN A 127.0.0.1
sys10.cms.com. IN A 192.168.1.10
sys9.cms.com. IN A 192.168.1.9
sys2.cms.com. IN A 192.168.1.2
# vi cms.rev
$TTL 86400
@ IN SOA sys10.cms.com. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS sys10.cms.com.
10 IN PTR sys10.cms.com.
9 IN PTR sys9.cms.com.
2 IN PTR sys2.cms.com.
open resolv.conf file and enter the ip addr of dns server this file is similar to prefered dns of windows os
# vi /etc/resolv.conf
nameserver 192.168.1.10
query dns server and check the output:- we can check dns server by two commands:-
nslookup and dig
# nslookup
KICKSTART INSTALLATION
It is similar to RIS/Unattended installation of Windows os By using kickstart installation we can install linux on
remote machine all the installation files are present on kickstart server client is booted from linux bootable cd(cd
no.1) and then it will take installation files from server along with answer file. Answer file is a file generated on
kickstart server which provides all answers of questions which are asked during installation process.
Method 2:-
if we are using 1dvd then simply copy complete dvd to /var/ftp/pub now configure nfs server to share this
location
# vi /etc/exports
/var/ftp/pub *(rw,sync)
# service nfs restart
check it
# showmount -e
or
now configure ftp server to share this location just install the vsftpd package and configuration is completed
because bydefault ftp server shares /var/ftp/pub location itself
# service vsftpd restart
it will open a wizard configure the options, after configuring options you have to add pakage list manually to the
kickstart file give following command:-
# yum grouplist >> /var/ftp/pub/ks.cfg
it will transfer all group names to end of kickstart file now modify that file
# vi /var/ftp/pub/ks.cfg
MAIL SERVER
MAIL server uses MTA( mail transfer agent) like sendmail, qmail, postfix squirrelmail, smail etc
MTA uses SMTP protocol to send and receive mail at port no. 25
on the client side mail client software like mutt(Mutt Mail User agenT), thunderbird, evolution, and webmail are
used to send and receive mail.
note: this command will not show any output on screen m4 is a macro compiler which is used to compile
sendmail.mc file
start service
# service sendmail restart
On Client Side:-
set hostname............. sysX.cms.com
set ip addr
set ip addr of dns server in resolv.conf file
# vi /etc/resolv.conf
nameserver 192.168.1.X
Then you can access mail in graphical mode using webmail( mail client )
open mozila firefox web browser
type following addr
http://<name of mail server>/webmail
like
http://mail.rhce.com/webmail
it will ask for username and password
then you can access your mail
There are many web servers like IIS(windows), apache, sunone, AOL, etc most popular web server is Apache, it
works on both windows and linux more than 68% of total web servers of world are configured on Apache
Note:- go to www.netcraft.com
Type url of any web server, and search, it will show you on what kind of server that web site is working, like
www.way2sms.com is working on Apache 2.0 installed on Fedora8 goto ip2location.com
type url of any web server, and search, it will show you the geographical location of that web server, like
www.google.com is in US, california, street...., contact person... www.whois.net...... you can find who is
maintaining that server, complete contact information is displayed with ph. no. too use nslookup command
to see ip addr of any dns server.
Steps to configure web server:- install the packages if not already installed:-
# yum install httpd*
line 250 is for providing contact user information if your web server is not working then client will
contact to this person
line 264 is for provding url for your web site, it may be different from your system name
like here system name is web.cms.com but website url is www.cms.com. and it works on port no.
80
line 280 is for defining DocumentRoot this is the location where your html files are kept
you can change this location
134 Listen 80 this is to define portno. that this web server listens
390 DirectoryIndex discribes the name of first page of your website
if first page name is different then change this option, by
default it is index.html file which is created inside
/var/www/html(DocumentRoot)
Check it
# dig -x 192.168.1.X
It is a centralized directory service through which we can share resources like users, groups, mails over the
network It is similar to LDAP( Light Weight Directory Access Protocol )
Linux machine uses NIS, Solaris machine also uses NIS+
Configuring NIS-Client:
1. set nisdomain name
# nisdomainname cms.com
# vi /etc/sysconfig/network
NISDOMAIN=cms.com
SHELL SCRIPTING
# grep 'root' /etc/passwd
# date --help | grep year
# cut -d: -f1 /etc/passwd
# grep bash /etc/passwd | sort
# cut -d: -f7 /etc/passwd | sort | uniq
save this file and give execute permission now to run this shell script :
# ./first.sh
or
# bash first.sh
# vi second.sh
#/bin/bash
echo "enter yes or no"
read ans
ans="$(echo $ans | tr 'A-Z' 'a-z')"
echo "$ans"
save the file and give execute permission now run shell script:
# ./second.sh
# vi pets
hi this is my pet animals file
i have a lot of pet animals
like
cat dog parrot and rabbit
but my fav. is cat
my cat is very soft
cat is white in color
dog is black in color
save the file and exit
capital=dehli
echo "what is capital of india"
read cap
if [ $cap != $capital ]
then
echo "wrong"
exit 1
else
echo " correct "
fi
read a
read b
c=`expr $a + $b`
echo $c
for x in 10 20 30
do
echo $x
done
cat > animal
cat
dog
fly
goat
lion
*****************
/etc/fstab and /etc/mtab files
FSTAB---- File System Table file stores information about partition, file type, mount point, and mounting
options system reads this file at the time of booting, and mounts the partitions which are listed in this file
Note:- When we mount any partition by using 'mount' command, then /etc/mtab file is updated and new entry is
added but this type of mounting is temporary after rebooting the system it is automatically unmounted so to
mount a partition permanently we use /etc/fstab file we have to manually edit this file to mount a partition
permanently
ex.
a new partition is created /dev/hda9, it is formatted to mount it temporarily,
# mount /dev/hda9 /mnt
to mount it permanently,
# vi /etc/fstab
VIRTUALIZATION
Red Hat Virtualization can host multiple guest operating systems. Each guest operating system runs in its own
domain. Each guest operating systems handles its own applications.
Full virtualization provides total abstraction of the underlying physical system and creates a new virtual system
in which the guest operating systems can run. No modifications are needed in the guest OS or application (the
guest OS or application is not aware of the virtualized environment and runs normally).
Paravirualization requires user modification of the guest operating systems that run on the virtual machines(these
guest operating systems are aware that they are running on a virtual machine)
The first domain, known as domain0 (dom0), is automatically created when you boot the system. Domain0 will
host Guest OS(Domain1).
The hypervisor (Red Hat's Virtual Machine Monitor) is a virtualization platform that allows multiple operating
systems to run on a single host simultaneously within a full virtualization environment. A guest is an operating
system (OS) that runs on a virtual machine in addition to
the host or main OS.
Celeron “Pentium II " Pentium III " Pentium IV " Xeon " AMD Athlon " AMD Duron for para virtualization.
Installing virtualization:-
yum install <pakage name>
pakages are:
kernel-xen
xen
xen-libs
virt-managerz
gnome-applet-vm
libvirt
Connect to a domian:
# xm console domain-id
Create a domain:
# xm create -c newdomainname
Saving a domain:
# xm save domain-id
Destroy a domain:
# xm destroy domain-id
Shutdown a domain:
# xm shutdown domain-id
Restore a domain:
# xm restore domain-id
Suspend a domain:
# xm suspend domain-id
Resume a domain:
# xm resume domain-id
reboot a domain:
# xm reboot domain-id
pause a domain:
# xm pause domain-id
unpause a domain:
# xm unpause domain-id
Display uptime:
# xm uptime domain-id
The Virtual Machine Manager (VMM) gives you a graphical view of the virtual machines on your system. You
can use VMM to define both para-virtual and full virtual machines.
Requirements:
First create a new partition on Domain0 host (ex. /dev/hda9) then configure your nfs install server
192.168.1.10(share dir is /var/ftp/pub) Then create a kickstart server 192.168.1.10(save file in /var/ftp/pub)
After virtual machine is created you can view graphical mode in virtual machine console window
To start your guest machine:-
# xm create -c guestname
Then right click on guest in virtual machine manager and chose open to open virtual console
Note:- you can also use "virt-install" command to create a virtual machine in text mode
PROXY SERVER
line no.
73 http_port 3128
remove the hash from line no. 993
cache_dir ufs /var/spool/squid 100 16 256
After defining all acl define allow/deny policy for each of them below line no. 2500 like
http_access deny denydomain
http_access deny denykeyword
or
http_access deny denydomain denykeyword
http_access allow neighbours
TROUBLESHOOTING
To Break root password:-
1. restart system
# init 6
2. go to single user mode
at the grub boot screen select Redhat and press 'a'
then give space and type '1'
then press enter
3. at the shell prompt change the root password
sh# passwd root
******
******
4. restart the system
# init 6
What is GRUB?
GRand Unified Bootloader is the default boot loader program for RHEL5
configuration file for GRUB is /boot/grub/grub.conf
Configure autofs:
1.Create /etc/auto.master
1. Create /etc/auto.* files
2. Restart autofs
3. Access a configured directory