[go: up one dir, main page]

100% found this document useful (1 vote)
303 views134 pages

Rhcsa Full Doc CSL

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 134

RHCSA:

Contents
GETTING STARTED WITH LINUX...................................................................................................................1
LINUX TEXT PROCESSING TOOLS...............................................................................................................12
LINUX TEXT EDITOR...................................................................................................................................16
USER AND GROUP ADMINISTRATION........................................................................................................21
LINUX FILE PERMISSION............................................................................................................................31
LINUX ACL PERMISSION.............................................................................................................................39
LINUX COMPRESSION UTILITIES................................................................................................................42
LINUX PROCESS MANAGEMENT................................................................................................................46
LINUX CRONTAB AND AT...........................................................................................................................52
LINUX FILE SYSTEM MANAGEMENT..........................................................................................................54
LINUX SWAP SPACE...................................................................................................................................63
LINUX LVM MANAGEMENT.......................................................................................................................67
LINUX NETWORK MANAGEMENT..............................................................................................................72
LINUX YUM CONFIGURATION....................................................................................................................77
LINUX VIRTUALIZED SYSTEM.....................................................................................................................80
HTTP SERVER WITH VIRTUAL HOSTING.....................................................................................................85
ISCSI...........................................................................................................................................................91
NFS SERVER...............................................................................................................................................95
DNS............................................................................................................................................................99
MAIL SERVER...........................................................................................................................................106
BASH SCRIPTING......................................................................................................................................110
FTP...........................................................................................................................................................113
CACTI.......................................................................................................................................................118
SQUID......................................................................................................................................................124
DHCP........................................................................................................................................................128
GETTING STARTED WITH LINUX

Working with Linux CLI:

=======================

[student@hostX Desktop] $

[root@hostX Desktop] #

1 2 3 4

1: user name

2: hostname

3: user's current location

4: user types (root: #, regular user: $)

Linux User's Types:

-------------------

=> root user: Administrator (#)

=> system user: service (mail/ftp/games/daemon)-cannot login

=> regular user: student, guest, sakib ($)

Working with Linux Shells & Terminal:

------------------------------------

[student@hostX Desktop] $ echo $SHELL

[student@hostX Desktop] $ chsh -l

/bin/sh

/bin/bash

/usr/bin/sh

/usr/bin/bash
Working with linux CLI:

-----------------------

=> Physical Consoles (Alt + Ctrl+ F1 - Alt + Ctrl + F6)

=> Alt + Ctrl + F1: GUI

=> Alt + Ctrl + F2-F6: CMD

=> Pseudo Consoles (/dev/pts/x) or connection from GUI

=> Telnet (unencrypted, TCP port 23)

=> SSH (encrypted, TCP Port 22)

Alt + Ctrl + F1 => GUI - :0

Alt + Ctrl + F2 => new CMD terminal (F2-F6) - tty2-tty6

=> Press Ctl + Alt + F2

Login: student

pass: ******

[student@hostXDesktop]$ su

Password: ******

[root@hostX ~]# exit

[student@hostX ~]$ exit

screen:

------

$ ctrl + l = srceen clear

$ ctrl + shift + "t" => new terminal (tab) (GUI)


Linux Command Syntax/Pattern:

-----------------------------

# command [optoin (-)] argument

ex # ping -c 4 172.25.11.254

[student@hostX Desktop]$ cd

[student@hostX ~]$ ls ;list of files and dir.

[student@hostX ~]$ ll ;file and dir properties

[student@hostX ~]$ ls -l

[student@hostX ~]$ ls -la ; details list with hidden files and dir

blue - dir

b&w - file

red - compress (rpm/zip/rar)

green - execute file

yellow - device (terminal/cd/dvd/usb/hdd)

cyan - link file

magenta - Picture/image/media

[student@hostX ~]$ pwd ; present working directory

"~" => home dir

"/" => root partition (My Computer)

"/root" => root's home dir

"/home" => user's home

i.e.: /home/student

[student@hostX~]$ => user's home dir


Working with Linux More Commands:

================================

[student@hostX ~]$ w

[student@hostX ~]$ who

[student@hostX ~]$ whoami

[student@hostX ~]$ hostname

[student@hostX ~]$ tty

[student@hostX ~]$ date

[student@hostX ~]$ cal

[student@hostX ~]$ cal 2017

[student@hostX ~]$ runlevel ;(5-GUI, 3-CMD, n-none)

[student@hostX ~]$ uname -r ; kernel version

[student@hostX ~]$ uname ; OS name

[student@hostX ~]$ cat /etc/redhat-release ; redhat/centos version

[student@hostX ~]$ top ; task manager

[student@hostX ~]$ lastlog ; login details

[student@hostX ~]$ free -m ; RAM Info

[student@hostX ~]$ uptime : system UPtiem info

[student@hostX ~]$ ip addr

[student@hostX ~]$ history ; list of privious command

[student@hostX ~]$ !25 ; 45 no command

[student@hostX ~]$ history -c ; clear all previous history

[student@hostX ~]$ history

Shutdown

===========

[root@hostX ~]# init 0


[root@hostX ~]# poweroff

[root@hostX ~]# shutdown -h now

[root@hostX ~]# shutdown -h 5 now ; shutdown after 5 min

restart:

=======

[root@hostX ~]# reboot

[root@hostX ~]# init 6

[root@hostX ~]# shutdown -r now

[root@hostX ~]# shutdown -r 5 now ; restart after 5 min

Linux Directory Structure:

-------------------------

[student@hostX ~]$ cd /

[student@hostX /]$ ls

backup boot etc lib media opt root sbin sys usr

bin dev home lib64 mnt proc run srv tmp var

bin - user binary files ( executed by regular user)

boot - system boot related file

dev - system device files (dvd/cd/hdd/fd)

etc - all server & system configuration file

home - regular user home dir

lib - system libary files locations. libraries needed to execute the binaries in /bin/ and /sbin/.

media - system defaut mount point (DVD/ISO/SOFTware)

mnt - mount point (DVD/HDD/USB)

opt - optional (empty)

proc - Also called 'proFS' system process related info (CPU,RAM, Process, Driver, Modules and Kernel)
root - root user (superuser) home dir.

run - service running data. Runtime data for processes started since the last boot.

sbin - system binary ( used by root user)

srv - Sort for Service. User's (/home/*) service related data. Like WWW, FTP etc.

sys - Sort for system. '/sys' directory as a virtual filesystem (sysfs) mounted under /sys. similar as proc.

tmp - temporary files (deleted after 10 days)

usr - thirdparty software install location

var - varibale file (mail/log/hosting/ftpdata)

[student@hostX ~]$ cd [enter] ; back to home dir

[student@hostX ~]$ cd /

[student@hostX /]$ ls

[student@hostX /]$ cd

=> cd /dir1/dir2/dir3 [path] ; Linux

=> C:\dir1\dir2\dir3> ; Windows

[student@hostX ~]$ cd /var/log

[student@hostX log]$ ls

[student@hostX log]$ cd .. ; one step/dir back

[student@hostX var]$ cd - ; back to previous dir

[student@hostX ~]$ cd

[student@hostX ~]$ ls

[student@hostX ~]$ cd Music

[student@hostX Music]$ cd ../Videos

[student@hostX Videos]$ ls

[student@hostX Videos]$ pwd

[student@hostX Videos]$ cd
[student@hostX ~]$ mkdir linux

[student@hostX ~]$ ls

[student@hostX ~]$ cd linux

[student@hostX linux]$ ls

[student@hostX linux]$ pwd

[student@hostX linux]$ mkdir lesson02

[student@hostX linux]$ cd lesson02

[student@hostX lesson02]$ ls

[student@hostX lesson02]$ pwd

Test: Graphically (home/...........)

class work:

-----------

[student@hostX lesson02]$ touch file1 ; file create

[student@hostX lesson02]$ ll

[student@hostX lesson02]$ touch test1 test2 test3 ; multiple files create with single command

[student@hostX lesson02]$ ll

[student@hostX lesson02]$ mkdir dir1 dir2 dir3 ; multiple dirs create with single command

[student@hostX lesson02]$ ll

[student@hostX lesson02]$ touch file{1..10}

[student@hostX lesson02]$ touch user{1,2,3}

[student@hostX lesson02]$ touch user-{tarek,lima,liza}

[student@hostX lesson02]$ ll

[student@hostX lesson02]$ mkdir -p dir1/dir2/dir3

[student@hostX lesson02]$ ll dir1

[student@hostX lesson02]$ touch dir1/dir2/test

[student@hostX lesson02]$ cd dir1/dir2/

[student@hostX dir2]$ pwd


[student@hostX dir2]$ ll

[student@hostX dir2]$ cd /home/student/linux/lesson02

or

[student@hostX dir2]$ cd ../../

[student@hostX lesson02]$ rm -rf *

[student@hostX lesson02]$ ls

Working with Hidden file/dir:

----------------------------

[student@hostX lesson02]$ mkdir .training

[student@hostX lesson02]$ touch .csl

[student@hostX lesson02]$ ll

[student@hostX lesson02]$ ls -la ; a for hidden file/dir

[student@hostX lesson02]$ mv .training training ; file rename

[student@hostX lesson02]$ ll

[student@hostX lesson02]$ touch test1

[student@hostX lesson02]$ mkdir linux1

[student@hostX lesson02]$ ll

d rwx rwx r-x . 2 student student 6 Feb 4 18:06 linux1

- rw- rw- r-- . 1 student student 0 Feb 4 18:06 testY

1 2a 2b 2c 2d 3 4 5 6 7 8

1: file/dir types
2: file/dir permission: 2a: user permission, 2b: group permission, 2c: others permission 2d: ACL
Permission

3: file/dir link (Hard Link)

4: file/dir owner

5: file/dir group owner

6: file/dir size (byte)

7: file/dir modify date

8: file/dir name

Linux FIle & Dir types:

------------------------------

d = directory : regular directory

l = link file : /dev/stdin

s = socket : /dev/log

- = regular file : text/any file

p = Pipe file : /dev/initctl

b = device CD/DVD/HDD : /dev/sdb, /dev/sr0

c = character device (serial/prallel/printer): /dev/tty

s - A socket file is used to pass information between applications/process for communication purpose

[student@hostX lesson02]$ cd /dev

[student@hostX dev]$ ll

[student@hostX dev]$ cd -

[student@hostX lesson02]$ cd /run

[student@hostX run]$ ll

[student@hostX run]$ cd -

[student@hostX lesson02]$ rm -rf *

[student@hostX lesson02]$ ls
FIle/dir Permission:

---------------------------

r = read

w = write

x = execute

- = no permission

. = ACL File Permission (+)

Copy/Paste/Remove/Rename/Delete

===============================

[student@hostX lesson02]$ touch file1

[student@hostX lesson02]$ mkdir dir1

[student@hostX lesson02]$ ls

[student@hostX lesson02]$ cp file1 file2 ; file copy

[student@hostX lesson02]$ ll

[student@hostX lesson02]$ cp file1 /home/student ; same name

[student@hostX lesson02]$ cp file1 /home/student/file3 ; diffrent name

[student@hostX lesson02]$ cd

[student@hostX ~]$ ls

file1

file3

[student@hostX ~]$ cd -

[student@hostX lesson02]$ cp /etc/passwd . ; copy to current dir

[student@hostX lesson02]$ ls

[student@hostX lesson02]$ cp /etc/hostname /home/student

[student@hostX lesson02]$ cd

[student@hostX ~]$ ls

[student@hostX ~]$ cd -
[student@hostX lesson02]$ cp dir1 linux99 ; wrong command

[student@hostX lesson02]$ cp -r dir1 linux99 ; copy directory

[student@hostX lesson02]$ cp -r /etc . ; full '/etc' directory copy to 'current location'

[student@hostX lesson02]$ ls

[student@hostX lesson02]$ mv file2 file4 ; move or rename

[student@hostX lesson02]$ ls

[student@hostX lesson02]$ mv file4 /home/student

[student@hostX lesson02]$ ls

[student@hostX lesson02]$ rm file1 ; file remove

[student@hostX lesson02]$ ls

[student@hostX lesson02]$ rm linux99 ; wrong command

[student@hostX lesson02]$ rm -r linux99 ; delete empty dir

[student@hostX lesson02]$ rm -r etc ; delete dir with content and confirmation

C^

[student@hostX lesson02]$ rm -rf etc ; delete dir with contains and without confirmation

[student@hostX lesson02]$ ls

[student@hostX lesson02]$ rm -rf * ; delete everything from curent dir

[student@hostX lesson02]$ ls

===================== The End =======================


LINUX TEXT PROCESSING TOOLS
Text Processing tools: (echo/tail/Grep/cat/head/less/wc/locate/find)

--------------------------------------------------------------------

[student@desktopX ~]$ cd

[student@desktopX ~]$ mkdir -p linux/lesson03

[student@desktopX ~]$ cd linux/lesson03/

[student@desktopX lesson03]$ ls

[student@desktopX lesson03]$ cp /etc/passwd .

[student@desktopX lesson03]$ ls

[student@desktopX lesson03]$ touch test

[student@desktopX lesson03]$ ls

passwd test

[student@desktopX lesson03]$ cat test

[student@desktopX lesson03]$ cat passwd

[student@desktopX lesson03]$ cat -n passwd ; concatinate

[student@desktopX lesson03]$ cat /etc/hostname

[student@desktopX lesson03]$ clear

[student@desktopX lesson03]$ echo "Hello World"

[student@desktopX lesson03]$ echo $SHELL

[student@desktopX lesson03]$ echo $HOSTNAME

[student@desktopX lesson03]$ echo "Welcome to RHEL 8" > test

[student@desktopX lesson03]$ cat test

[student@desktopX lesson03]$ echo "Welcome to CentOS 8" > test ; replace

[student@desktopX lesson03]$ cat test

[student@desktopX lesson03]$ echo "Welcome to RHEL 8" >> test ; append

[student@desktopX lesson03]$ cat test

[student@desktopX lesson03]$ history

[student@desktopX lesson03]$ history > command-list


[student@desktopX lesson03]$ ping -c4 127.0.0.1 > ping

[student@desktopX lesson03]$ ls

[student@desktopX lesson03]$ cat command-list

[student@desktopX lesson03]$ less passwd ; Scrolling

[student@desktopX lesson03]$ head passwd ; 1st 10 l ines

[student@desktopX lesson03]$ tail passwd ; last 10 lines read

[student@desktopX lesson03]$ tail -5 passwd ; last 5 lines

[student@desktopX lesson03]$ head -5 passwd ; 1st 5 lines

[student@desktopX lesson03]$ cat -n passwd | tail -5

[student@desktopX lesson03]$ grep -n root passwd ; search root keyword in passwd file

1 root:x:0:0:root:/root:/bin/bash

10 operator:x:11:0:operator:/root:/sbin/nologin

[student@desktopX lesson03]$ tail passwd | grep root ;search root keyword in last 10 lines

[student@desktopX lesson03]$ head passwd | grep root

[student@desktopX lesson03]$ ll

[student@desktopX lesson03]$ ll | wc -l

[root@desktopX lesson03]# updatedb

[root@desktopX lesson03]# locate sshd_config

[root@desktopX lesson03]# locate -i .exe ;including case sensitve

[root@desktopX lesson03]# find / -name mail ; mail name file

[root@desktopX lesson03]# find /var -name mail

[root@desktopX lesson03]# find /var -type d -name mail


[root@desktopX lesson03]# find / -type f -name passwd

[root@desktopX lesson03]# find / -size +100M ; size more than 100MB

[root@desktopX lesson03]# find / -size -10M ; size less than 10M

Working with "Help and Manual":

------------------------------

[root@desktopX lesson03]# man passwd

[root@desktopX lesson03]# useradd --help

[root@desktopX lesson03]# passwd -?

[root@desktopX lesson03]# mandb

[root@desktopX lesson03]# whatis yum.conf

[root@desktopX lesson03]# whatis passwd

The Info Command:

-----------------

[root@desktopX lesson03]# info passwd

Online Documentation:

---------------------

docs.redhat.com

Class work:

===========

[student@desktopX lesson03]$ su

:******

[root@desktopX lesson03]# cat -n /var/log/messages


[root@desktopX lesson03]# grep "MM DD" /var/log/messages | wc -l > log

---------------------- Thank you -----------------


LINUX TEXT EDITOR
Linux Text Editor:

-------------------

Windows Text Editor: notepad, notepadd++

Linux Text Editor: vi/vim, nano, gedit (GUI), emacs, pico

Most propular/Advanced Text Editor: Vi/Vim

=> vi - old, b&w, default

=> vim - advanced, colorfull (Package must be installed)

[student@hostX ~]$ cd

[student@hostX ~]$ mkdir linux/lesson04 -p

[student@hostX ~]$ cd linux/lesson04

[student@hostX lesson04]$ ls

[student@hostX lesson04]$ touch test ; create new file

[student@hostX lesson04]$ cp /etc/passwd . ; copy passwd file to cureent dir

[student@hostX lesson04]$ ls

passwd test

[student@hostX lesson04]$ vim file1 ; edit newfile

welcome to vim editor

:x

[student@hostX lesson04]$ cat file1

[student@hostX lesson04]$ nano file2

welcome to nano editor


=> Ctrl+X then 'Y'

[student@hostX lesson04]$ cat file2

[student@hostX lesson04]$ gedit file3

welcome to graphical geditor

[student@hostX lesson04]$ cat file3

Working with vi/vim Mode:

------------------------

=> Insert Mode : press "i" or "insert" button

=> Exit Mode : press "esc" button form keyboard

=> Command Mode: file navigation, cut, paste, undo, redo

=> Visual Mode: press "ctrl + v" form keyboard

[student@hostX lesson04]$ vim file4

=> Press "i" for insert mode

=> write something as your requirments ; (Hello world !!)

=> press "esc" button exit from "insert" mode

=> :x ; save and quit

[student@hostX lesson04]$ ls

[student@hostX lesson04]$ cat file4

Hello world !!

[student@hostX lesson04]$ vim file4


=> Press "i" for insert mode

=> write "welcome to linux training"

=> press "esc" quit from insert mode

=> :w ; only save not quit

=> Press "i" for insert mode

=> write "goodbye"

=> :q! ; quit without save

[student@hostX lesson04]$ cat file4

[student@hostX lesson04]$ vim passwd

:set nu

Cursor Movement:

----------------

h j k l - Left, down, up, right

^ - Go to the beginning of the line

$ - Go to the end of the line

gg - Go to the frst line

G - Go to the last line

:n - Go to line n

Replacing Text:

---------------

r - Replace character
Copy/Paste:

-----------

yw - word copy

yy - Yank line

nyy - n lines copy

p - Paste after cursor

P - Paste before cursor

Inserting Text:

---------------

i - Insert at cursor

I - Insert at the beginning of the line

a - Append after cursor

A - Append at the end of the line

o - Open a new line below the current line

O - Open a new line above the current line

Deleting Text:

--------------

x - delete (cut) character

dd - delete (cut) line

ndd - delete (cut) n lines

dw - delete (cut) word

D - delete (cut) to the end of the line

Undo/Redo:

---------

u - Undo
Ctrl-r - Redo

Searching:

----------

/{pattern} - Forward search for {pattern}

?{pattern} - Reverse search for {pattern}

n - Repeat the last search

N - Repeat the last search in the opposite direction

Find and Replace:

-----------------

:%s/{old}/{new}/gc - Search and Replace with confirmation

:%s/{old}/{new}/g - Search and Replace without confirmation

Save and Quit:

-------------

:w - Write (save)

:wq or :x - Write and quit

:q - Quit

:q! - Force quit, don’t save changes

:wq! - Force write and quit

#vimtutor

======================== Thank you ===================


USER AND GROUP ADMINISTRATION

Lesson: User and Group Administration

-------------------------------------

[root@desktopX ~]# less /etc/passwd

UID (User ID):

-------------

root : 0

system user: 1 - 999

regular user: 1000 +

[root@desktopX ~]# id root

[root@desktopX ~]# id student

[root@desktopX ~]# id bin

[root@desktopX ~]# useradd tarek

[root@desktopX ~]# tail /etc/passwd

[root@desktopX ~]# grep tarek /etc/passwd

tarek: x: 1001: 1001: :/home/tarek :/bin/bash

1 2 3 4 5 6 7

1 - username

2 - user password info (/etc/shadow)

3 - userid (UID)

4 - groupid (GID): primary

5 - user's comment/descriptions

6 - user's home dir


7 - user's shell

[root@desktopX ~]# id tarek

uid=1001(tarek) gid=1001(tarek) groups=1001(tarek)

[root@desktopX ~]# tail /etc/shadow ; user password related info

[root@desktopX ~]# grep tarek /etc/shadow ; tarek password related info

[root@desktopX ~]# useradd hasib ; user create

[root@desktopX ~]# useradd mamun

[root@desktopX ~]# passwd mahfuz

[root@desktopX ~]# tail /etc/shadow

Alt+Ctrl+F2 -- Alt+Ctrl+F6

login: hasib ; login as regular user

pass: 123 ; (note: please numlock on)

[mahfuz@desktopX ~]$ exit

[root@desktopX ~]# groupadd trainer ; Group Add

[root@desktopX ~]# groupadd staff ; Group Add

[root@desktopX ~]# tail /etc/group ; group related info

trainer :x: 1004:

1 2 3 4
1 - group name

2 - group password info (/etc/gshadow)

3 - gid

4 - group members

[root@desktopX ~]# grep trainer /etc/group ; check trainer group

trainer:x:1004:

[root@desktopX ~]# usermod -G trainer tarek ;existing user modify

[root@desktopX ~]# useradd -G trainer lalin ; newuser to group

[root@desktopX ~]# grep trainer /etc/group

trainer:x:1004:tarek,lalin

[root@desktopX ~]# useradd ikbal

[root@desktopX ~]# passwd ikbal

[root@desktopX ~]# usermod -G trainer,staff ikbal ; single user assign to multiple groups

[root@desktopX ~]# grep staff /etc/group

[root@desktopX ~]# grep trainer /etc/group

[root@desktopX ~]# id ikbal

[root@desktopX ~]# useradd -u 3000 roman ; user careate with UID

[root@desktopX ~]# grep roman /etc/passwd

[root@desktopX ~]# groupadd -g 3100 admin

[root@desktopX ~]# tail /etc/group


[root@desktopX ~]# groupmod -n faculty trainer ;change group name

[root@desktopX ~]# tail /etc/group

[root@desktopX ~]# gpasswd -d ikbal staff ; remove from group

[root@desktopX ~]# grep staff /etc/group

[root@desktopX ~]# tail /etc/shadow

[root@desktopX ~]# passwd -d ikbal ; password remove

[root@desktopX ~]# tail /etc/shadow

Login regular user:

-------------------

Linux GUI terminal: 1 (Alt + Ctrl + F1)

Linux Command Terminal: (Alt+Ctrl+F2 - Alt + Ctrl + F6)

Login as root user

-----------------

[root@desktopX ~]# id rafat

[root@desktopX ~]# useradd rafat

[root@desktopX ~]# passwd rafat

[root@desktopX ~]# grep rafat /etc/passwd

rafat:x:1003:1003::/home/rafat:/bin/bash

[root@desktopX ~]# usermod -c "Linux X student" rafat

[root@desktopX ~]# grep rafat /etc/passwd

rafat:x:1000:1000:Linux X student:/home/rafat:/bin/bash

[root@desktopX ~]# grep rafat /etc/passwd


rafat:x:1003:1003::/home/rafat:/bin/bash

[root@desktopX ~]# mkdir -p /newhome/rafat2

[root@desktopX ~]# usermod -d /newhome/rafat2 rafat

[root@desktopX ~]# grep rafat /etc/passwd

rafat:x:1003:1003: :/newhome/rafat2:/bin/bash

[root@desktopX ~]# cat /etc/shells

[root@desktopX ~]# id student

[root@desktopX ~]# grep student /etc/passwd

[root@desktopX ~]# usermod -s /sbin/nologin student ;change user shell

[root@desktopX ~]# grep student /etc/passwd

student :x:1002:1002::/home/student :/sbin/nologin

Check: Alt + Ctrl + F3 (use username password)

[root@desktopX ~]# usermod -s /bin/bash student ;shell enable

Check: Alt + Ctrl + F3 (use username password)

[root@desktopX ~]# usermod -L student ; user account lock

[root@desktopX ~]# grep student /etc/shadow

student: ! $.............../:18026:10:30:7:::

Check: Alt + Ctrl + F3 (use username password)


[root@desktopX ~]# grep student /etc/shadow

[root@desktopX ~]# tail /etc/shadow

[root@desktopX ~]# usermod -U student ; user account unlock

[root@desktopX ~]# grep student /etc/shadow

student: $.............../:18026:10:30:7:::

[root@desktopX ~]# userdel rafat ; user delete without home dir

or

[root@desktopX ~]# userdel -r rafat ; delete user with home dir

[root@desktopX ~]# cat /etc/passwd

[root@desktopX ~]# groupdel admin ; groupdel

[root@desktopX ~]# tail /etc/group

[root@desktopX ~]# useradd mahedi

[root@desktopX ~]# passwd mahedi

Alt+Ctrl+F3

Login: mahedi

Pass: *****

[mahedi@desktopX ~]$ useradd rasel

-bash: /usr/sbin/useradd: Permission denied

What is SUDO do ?
-----------------

Sudo allows an regular user to execute a specifc command or a

group of commands or all commands as the superuser.

regular user: rumon, rony, lucky

=> rm,cp,mv,

=> mkdir,touch

=> pwd,free -m,

=> ping, df -HT

=> ip addr, tail

Command run from: /bin/

super user: root

=> useradd, passwd, groupadd

=> reboot, systemctl

=> shutdown, poweroff

=> setenforce

Command run from: /sbin

Note: [root@desktopX ~]# which useradd ; command for location of useradd command

[root@desktopX ~]# which pwd

Editing sudo configuration File:

--------------------------------

Rules 1: permit for all

-----------------------

[root@desktopX ~]# visudo


:set nu

100 root ALL=(ALL) ALL

101 mahedi ALL=(ALL) ALL ; mahedi allow for any command

:x (save and exit)

Test:

-----

Send Kye (VM): Alt + Ctrl + F3

[mahedi@desktopX ~]$ useradd rasel

[mahedi@desktopX ~]$ sudo useradd rasel

[sudo] password for mahedi: ****

[mahedi@desktopX ~]$ tail /etc/passwd

[mahedi@desktopX ~]$ exit

Working with /etc/shadow file:

------------------------------

[root@desktopX ~]# useradd lucky

[root@desktopX ~]# passwd lucky

[root@desktopX ~]# tail /etc/shadow | grep lucky

lucky:$6$ciiMIfom$cPpqBIf2NOwan2byi5BUA.G6D0iM/g.tw7fcUyLDWIs.nbp0:18026:0:99999:7:::

[root@desktopX ~]# chage -l lucky ;password info


Last password change : MM DD, YYYY

Password expires : never

Password inactive : never

Account expires : never

Minimum number of days between password change :0

Maximum number of days between password change : 99999

Number of days of warning before password expires :7

password: P@ssword123 (new password)

[root@desktopX ~]# chage lucky

Minimum Password age [0]: 3

Maximum Password age [99999]: 30

Last Password Changed (YYYY-MM-DD): Press Enter (today)

Password Expiration Warning [7]: 5

Password Inactive [-1]: 5

Account Expiration Date (YYYY-MM-DD) [-1]: YYYY-MM-DD

note: If press Enter account never expire

[root@desktopX ~]# tail /etc/shadow | grep lucky

[root@desktopX ~]# date

[root@desktopX ~]# date MMDDHHMMYY

[root@desktopX ~]# date

[root@desktopX ~]# vim /etc/login.defs ;user password related info


25 PASS_MAX_DAYS 99999

26 PASS_MIN_DAYS 0

27 PASS_MIN_LEN 5

28 PASS_WARN_AGE 7

[root@desktopX ~]# chage -d 0 lucky

=================================== x ===========================

Extra:

Rules 2: shutdown disallow

--------------------------

49 Cmnd_Alias SHUTDOWN = /usr/sbin/shutdown, /usr/sbin/poweroff, /usr/sbin/reboot

102 mahedi ALL=(ALL) ALL, !SHUTDOWN

Rules 3: permit for specific command

------------------------------------

49 Cmnd_Alias MAHEDI = /usr/sbin/useradd, /usr/sbin/userdel

102 mahedi ALL=(ALL) MAHEDI

Rules 4: permit group (support) for specific command

----------------------------------------------------

49 Cmnd_Alias SUPPORT = /usr/sbin/fdisk, /usr/sbin/passwd,

111 %support ALL=(ALL) SUPPORT

=================== The End ===============


LINUX FILE PERMISSION
Application => System Tools => Virtual Machine Manager:

Working with Linux File/Directory permission & owernship:

==========================================================

[root@dektopX ~]# mkdir linux

[root@dektopX ~]# cd linux

[root@dektopX linux]# ls

[root@dektopX linux]# mkdir lesson06

[root@dektopX linuxY]# cd lesson06

[root@dektopX lesson06]# mkdir newdir

[root@dektopX lesson06]# touch file1

[root@dektopX lesson06]# cp /etc/hostname . ; copy to current dir

[root@dektopX lesson06]# ll

d rwxr-xr-x. 2 root root 6 May 10 17:54 newdir

- rw-r--r--. 1 root root 2662 May 10 17:55 hostname

- rw-r--r--. 1 root root 0 May 10 17:54 test1

1 2 3 4 5 6 7 8

1 - Linux File/dir types

2 - User+Group+Others permission, (.) => ACL Permission

3 - file Hard link

4 - file/dir owner

5 - file/dir group owner

6 - file/dir size

7 - created/modify date & Time

8 - file/dir name
working with link file:

=======================

Type of link file:

------------------

1) hard link - same inode number (backup)

2) soft link - different inode number (if original file delete, linked file delete too).

Hardlink - file

softlink - file & folder (start with 'l')

[root@dektopX lesson06]# ls -li

[root@dektopX lesson06]# cat hostname

[root@dektopX lesson06]# ln -s hostname hostname-soft ;softlink

[root@dektopX lesson06]# ln hostname hostname-hard ;hardlink

[root@dektopX lesson06]# ll

[root@dektopX lesson06]# cat hostname-hard

[root@dektopX lesson06]# cat hostname-soft

[root@dektopX lesson06]# ls -li

[root@dektopX lesson06]# echo server.example.com > hostname

[root@dektopX lesson06]# cat hostname

[root@dektopX lesson06]# cat hostname-hard

[root@dektopX lesson06]# cat hostname-soft

[root@dektopX lesson06]# rm -f hostname

[root@dektopX lesson06]# ll

[root@dektopX lesson06]# cat hostname-hard

[root@dektopX lesson06]# tail hostname-soft

[root@dektopX lesson06]# ln -s /etc/sysconfig/network-scripts network

[root@dektopX lesson06]# ls
[root@dektopX lesson06]# cd network

[root@dektopX network]# pwd

/home/student/linux21/day6/network

Field no: 2 (Permission)

-----------------------

[root@dektopX lesson06]# ll

- rw-r--r--. 1 root root 0 Sep 26 09:52 test1

d rwxr-xr-x. 2 root root 4096 Sep 26 09:33 newdir

subfield:

---------

- rw- r-- r-- . = 644 (file)

d rwx r-x r-x . = 755 (dir)

u g o A

u = user

g = group

o = others

r = read (4)

w = write (2)

x = execute (1)

- = no permission (0)

. = ACL Permission (+)

**** Special Permission (S,s,T,t)


Group: users others

====== ========= ========

students: malek, sumon, sadat all (except group members)

File/dir permission for new file/dir:

=====================================

dir: 755

file: 644

Maximum File Permission: 666 => (rw-rw-rw-)

Maximum Directory Permission: 777 => (rwxrwxrwx)

[root@dektopX lesson06]# groupadd students

[root@dektopX lesson06]# useradd -G students malek

[root@dektopX lesson06]# useradd -G students sadat

[root@dektopX lesson06]# useradd -G students sumon

[root@dektopX lesson06]# useradd tamim

[root@dektopX lesson06]# grep students /etc/group

students:x:5005:malek,sadat,sumon

user: (malek) : full permission

group: students: read

others: others : no

[root@dektopX lesson06]# ls -l

-rw-r--r--. 1 root root 0 Jun 14 19:55 test1


[root@dektopX lesson06]# chown malek test1

[root@dektopX lesson06]# ls -l

-rw-r--r--. 1 malek root 0 Jun 14 19:55 test1

[root@dektopX lesson06]# chgrp students test1

[root@dektopX lesson06]# ls -l

-rw-r--r--. 1 malek students 0 Sep 26 09:52 test1

[root@dektopX lesson06]# chmod 740 test1

[root@dektopX lesson06]# ls -l

-rwxr-----. 1 malek students 0 Jun 14 19:55 test1

Testing:

--------

(Ownership Test)

[root@dektopX lesson06]# su malek

[malek@dektopX lesson06]$ ls

[malek@dektopX lesson06]$ echo this is malek > test1 ; malek can rw

[malek@dektopX lesson06]$ cat test1

[malek@dektopX lesson06]$ exit

(Groupowner Test)

[root@dektopX lesson06]# su sumon

[sumon@dektopX lesson06]$ ls

[sumon@dektopX lesson06]$ cat test1

[sumon@dektopX lesson06]$ echo this is sumon > test1 ; read only

[sumon@dektopX lesson06]$ exit


(Others)

[root@desktopX lesson06]# su tamim

[tamim@desktopX lesson06]$ cat test1 ; access denied

[tamim@desktopX lesson06]$ echo this is tamim > test

[tamim@desktopX lesson06]$ exit

Linux SUID, SGID and Sticky Bit Concept:

----------------------------------------

4 = SUID (s,S) - 1st field

2 = SGID (s,S) - 2nd field

1 = Sticky bit (t, T) - 3rd field

Workint with Test SUID:

----------------------

[root@dektopX lesson06]# which passwd

[root@dektopX lesson06]# ls -l /bin/passwd

-rwsr-xr-x. 1 root root 34512 Aug 12 2018 /bin/passwd

[root@dektopX lesson06]# ls -l /usr/bin/ls

-rwxr-xr-x. 1 root root 166448 Jan 11 2018 /usr/bin/ls

[root@dektopX lesson06]# su student

[student@dektopX lesson06]$ ls /root

[student@dektopX lesson06]$ exit

[root@dektopX lesson06]# ls -l /usr/bin/ls

-rwxr-xr-x. 1 root root 166448 Jan 11 2018 /usr/bin/ls

[root@dektopX lesson06]# chmod 4755 /usr/bin/ls ; SUID Permission


[root@dektopX lesson06]# ls -l /usr/bin/ls

-rwsr-xr-x. 1 root root 166448 Jan 11 2018 /usr/bin/ls

[root@dektopX lesson06]# su student

[student@dektopX lesson06]$ ls /root

[student@dektopX lesson06]$ exit

Working with SGID:

------------------

[root@dektopX lesson06]# mkdir resource

[root@dektopX lesson06]# ls -ld resource

drwxr-xr-x. 2 root root 6 Sep 18 22:13 resource

[root@dektopX lesson06]# grep students /etc/group

students:x:1008:malek,sumon,sadat

[root@dektopX lesson06]# chmod 770 resource

[root@dektopX lesson06]# chgrp students resource

[root@dektopX lesson06]# ls -ld resource

drwxrwx---. 2 root students 6 Sep 18 22:13 resource

[root@dektopX lesson06]# su malek

[malek@dektopX lesson06]$ touch resource/malek1

[malek@dektopX lesson06]$ exit

[root@dektopX lesson06]# su sadat

[sadat@dektopX lesson06]$ touch resource/sadat1

[sadat@dektopX lesson06]$ exit


[root@dektopX lesson06]# ll resource

[root@dektopX lesson06]# chmod 2770 resource ; SGID Permission

[root@dektopX lesson06]# ls -ld resource

[root@dektopX lesson06]# su sumon

[sumon@dektopX lesson06]$ touch resource/sumon1

[root@dektopX lesson06]# ll resource

Working with Sticky Bit:

------------------------

[root@dektopX lesson06]# ls -ld /tmp

[root@dektopX lesson06]# mkdir mydir1

[root@dektopX lesson06]# mkdir mydir2

[root@dektopX lesson06]# ll

[root@dektopX lesson06]# chmod 777 mydir1 ; regular permission

[root@dektopX lesson06]# chmod 1777 mydir2 ; sticky bit

[root@dektopX lesson06]# ls -ld mydir1 mydir2

drwxrwxrwx. 2 root root 6 Sep 18 21:53 mydir1

drwxrwxrwt. 2 root root 6 Sep 18 21:53 mydir2

[root@dektopX lesson06]# touch mydir1/file1

[root@dektopX lesson06]# touch mydir2/file2

[root@dektopX lesson06]# su student

[student@dektopX lesson06]$ rm mydir1/file1


[student@dektopX lesson06]$ rm mydir2/file2

rm: cannot remove ‘mydir2/file2’: Operation not permitted

======================== Thank you ==================

LINUX ACL PERMISSION


Linux Advnced File Permission (ACL)

-----------------------------------

[root@desktopX ~]# cd

[root@desktopX ~]# mkdir linux/lesson07 -p

[root@desktopX ~]# cd linux/lesson07

[root@desktopX lesson07]# ls

[root@desktopX lesson07]# touch tutorial profile

[root@desktopX lesson07]# ll

-rw-r--r--. 1 root root 0 Jun 28 17:00 tutorial

-rw-r--r--. 1 root root 0 Jun 28 17:00 profile

[root@desktopX lesson07]# useradd jack

[root@desktopX lesson07]# useradd rose

[root@desktopX lesson07]# useradd tomy

ACL Test:

----------

[root@desktopX lesson07]# getfacl tutorial

# owner: root

# group: root
user::rw-

group::r--

other::r--

User ACL:

---------

[root@serverX lesson07]# setfacl -m u:rose:rw,jack:rw profile

[root@serverX lesson07]# ll

-rw-rw-r--+ 1 root root 0 Jun 28 17:00 profile

[root@serverX lesson07]# getfacl profile

[root@serverX lesson07]# su jack

[jack@serverX lesson07]$ cat profile

[jack@serverX lesson07]$ echo hello > profile

[jack@serverX lesson07]$ cat profile

[jack@serverX lesson07]$ exit

[root@serverX lesson07]# su rose

[rose@serverX lesson07]$ cat profile

[rose@serverX lesson07]$ echo hi >> profile

[rose@serverX lesson07]$ exit

[root@serverX lesson07]# su tomy

[tomy@serverX lesson07]$ cat profile

[tomy@serverX lesson07]$ echo welcome >> profile

[tomy@serverX lesson07]$ exit

***** Permission Denied


Group acl:

----------

[root@serverX lesson07]# groupadd staff

[root@serverX lesson07]# setfacl -m g:staff:rw- tutorial

[root@serverX lesson07]# getfacl tutorial

Directory Permission:

---------------------

[root@serverX lesson07]# mkdir acldir

[root@serverX lesson07]# touch acldir/file1

[root@serverX lesson07]# touch acldir/file2

[root@serverX lesson07]# setfacl -R -m u:rose:rwx acldir ;-R (recursively)

[root@serverX lesson07]# getfacl acldir

[root@serverX lesson07]# ls -l acldir

ACL Remove (user):

-------------------

[root@serverX lesson07]# setfacl -x u:rose: profile

[root@serverX lesson07]# getfacl profile

ACL Remove (Gruop):

------------------

[root@serverX lesson07]# setfacl -x g:staff: tutorial

[root@serverX lesson07]# getfacl tutorial

Remove ACL from File:

---------------------

[root@serverX lesson07]# setfacl -b tutorial


------------ Thank you ----------

LINUX COMPRESSION UTILITIES


Linux Archive & Compression Utilities:

======================================

Working Machine: HostX

compression:

--------------

Windows: zip, rar, 7zip

linux: .gz, .bz2, .xz optional (.zip, .rar)

Archive:

---------

.tar

Archive + compression:

-----------------------

.tar.gz

.tar.bz2

.tar.xz

10 MB: .gz(4MB)compress, .bz2(3 MB)more compress, .xz(2MB)more and compress,

[root@desktopX ~]# mkdir /linux/lesson08 -p

[root@desktopX ~]# cd /linux/lesson08

[root@desktopX lesson08]# cp -rv /etc /linux/lesson08


[root@desktopX lesson08]# ls

[root@desktopX lesson08]# du -sh etc

Archive (tar):

=============

[root@desktopX lesson08]# tar -cvf etcarchive.tar etc

[root@desktopX lesson08]# ls

[root@desktopX lesson08]# du -sh *

[root@desktopX lesson08]# rm -rf etc

[root@desktopX lesson08]# ls

c = Create

v = verbose

f = files

x = extract

Arcive extract:

---------------

[root@desktopX lesson08]# tar -xvf etcarchive.tar

[root@desktopX lesson08]# ll

archive + compress:

-------------------

-z - gzip (less)

-j - bz2 (more)

-J - xz (more and more)

[root@desktopX lesson08]# tar -czvf etcbackup.tar.gz etc

[root@desktopX lesson08]# ll
archive + more compress:

----------------------

[root@desktopX lesson08]# tar -cjvf etc.tar.bz2 etc

[root@desktopX lesson08]# ll

New: (More and More Compress)

------------------------------

[root@desktopX lesson08]# tar -cJvf etc.tar.xz etc

[root@desktopX lesson08]# ll

[root@desktopX lesson08]# du -sh *

Extract:

---------

[root@desktopX lesson08]# rm -rf etc

[root@desktopX lesson08]# tar -xzvf etcbackup.tar.gz

[root@desktopX lesson08]# ll

extract: (.bz2)

========

[root@desktopX lesson08]# rm -rf etc

[root@desktopX lesson08]# tar -xjvf etc.tar.bz2

[root@desktopX lesson08]# ls

extract: (.xz)

========

[root@desktopX lesson08]# rm -rf etc

[root@desktopX lesson08]# tar -xJvf etc.tar.xz


[root@desktopX lesson08]# ls

Only compress:

--------------

[root@desktopX lesson08]# seq 10000000 > file1

[root@desktopX lesson08]# seq 10000000 > file2

[root@desktopX lesson08]# seq 10000000 > file3

[root@desktopX lesson08]# ls

[root@desktopX lesson08]# du -sh file*

File Compression:

----------------

[root@desktopX lesson08]# gzip file1

[root@desktopX lesson08]# bzip2 file2

[root@desktopX lesson08]# xz file3

[root@desktopX lesson08]# ls

etc file1.gz file2.bz2 file3.xz

[root@desktopX lesson08]# du -sh file*

extract:

---------

[root@desktopX lesson08]# gunzip file2.gz

[root@desktopX lesson08]# bunzip2 file2.bz2

[root@desktopX lesson08]# unxz file3.xz

[root@desktopX lesson08]# ls

etc file1 file2 file3

Extra Knowledge:
----------------

[root@desktopX lesson08]# tar -cvf archive.tar file1 file file3

[root@desktopX lesson08]# tar -tvf etcarchive.tar ;view content

[root@desktopX lesson08]# mkdir new

[root@desktopX lesson08]# tar -xvf etcarchive.tar -C new

[root@desktopX lesson08]# cd new

[root@desktopX new]# ls

=================== Thank you =====================

Test: tar -czvf etc33.tar.gz etc --remove-files etc

LINUX PROCESS MANAGEMENT


Linux Process Management:

========================

[root@desktopX ~]# ps ; process current terminal

CPU Time

[root@desktopX ~]# ps ax

[root@desktopX ~]# ps -f ; full description of process

[root@desktopX ~]# ps -e ; everyting, all processes

[root@desktopX ~]# ps -ef | less ; pid, ppid, time, cmd

[root@desktopX ~]# ps -e --forest

Type of Process:

----------------

1. User Defined Process : jobs & ps


2. System Defined Process : ps

[root@desktopX ~]# ps -u ; for user processes

[root@desktopX ~]# ps -au ; pid, process, mem, cpu, tty, cmd

[root@desktopX ~]# ps -x ; systems processes

[root@desktopX ~]# ps -u student ; specific user processes

[root@desktopX ~]# ps -u root ; list of process for specifc user

[root@desktopX ~]# ps -af

[root@desktopX ~]# ps -au | less

[root@desktopX ~]# ps -ef | grep http

=> list of prcocess

=> PID

=> PPID

=> CPU%

=> Memory%

=> Process time

=> Process name

=> User's Process information

[root@desktopX ~]# top

PID - Process ID

USER - User Name

PR - Priority

NI - NICE Value

VIRT - Virtual Memory

RES - Residential Memory


SHR - Shared Memory

S - Status

%CPU - CPU Uses

%MEM - Memory Uses

TIME+ -

COMMD

Process ID: (1-65,535)

RHEL/CentOS - 7

=> PID 1 (systemd)

RHEL/CentOS - 6

=> PID 1 (init )

[root@desktopX ~]# pidof systemd

[root@desktopX ~]# pstree

Graphical Process Tools:

------------------------

Application => System Tools => System Monitor

Process Dealing:

---------------

ps - list the processes running on the system

kill - send a signal to one or more processes (usually to "kill" a process)

jobs - an alternate way of listing your own processes


bg - put a process in the background

fg - put a process in the forground

nice - new process with specific nice value

renice - reset process priority

[root@desktopX ~]# firefox

=> Run Firefox to test (ctrl+z, Ctrl+c)

[root@desktopX ~]# sleep 5

[root@desktopX ~]# sleep 500 &

[root@desktopX ~]# firefox &

[root@desktopX ~]# top (ctrl+Z)

[root@desktopX ~]# ping 172.25.11.1 (ctrl+c)

[root@desktopX ~]# ping 172.25.11.1 (ctrl+Z)

[root@desktopX ~]# jobs

[root@desktopX ~]# fg %1 (sleep)

[root@desktopX ~]# (Ctrl+c)

[root@desktopX ~]# jobs

Process Dealing:

=================

=> End : "Ctrl + c"

-> Kill

=> stop : "Ctrl + z"

-> process continue:


(ctrl+Z) - send to bra

(ctrl+C) - Terminate

List of Stoped process:

========================

[root@desktopX ~]# jobs [shows all stoped process]

[root@desktopX ~]# ps [shows stoped process with PID]

Process Findout:

================

[root@desktopX ~]# firefox &

[root@desktopX ~]# pidof firefox

2869

Process Kill:

============

[root@desktopX ~]# pkill <Process name>

[root@desktopX ~]# kill <PID> ; Normal kill

[root@desktopX ~]# kill -9 <PID> ; Forcely killed

; "-9" killing frequecy (highest)

Nice Value Range:

----------------

(Low) 19.................. 0 ................ -20 (High)

Nice Value:

----------

[root@desktopX ~]# ps axo pid,comm,nice --sort=-nice


[root@desktopX ~]# firefox &

[root@desktopX ~]# ps axo comm,nice | grep firefox

firefox 0

New Process Priority:

---------------------

[root@desktopX ~]# nice -n 15 firefox &

[root@desktopX ~]# ps axo comm,nice | grep firefox

firefox 15

Existing Process Priority:

-------------------------

[root@desktopX ~]# pidof firefox

[root@desktopX ~]# renice -n -7 [pid]

[root@desktopX ~]# ps axo comm,nice | grep firefox

=================== The End ==================


LINUX CRONTAB AND AT

Linux Scheduling using Crontab

---------------------------------

Daemon: crond

Package: crond

[root@desktopX ~]# rpm -qa | grep crontab

[root@desktopX ~]# yum install cron* -y

[root@desktopX ~]# service crond restart

[root@desktopX ~]# chkconfig crond on

Crontab Format:

================

* * * * *

1 2 3 4 5

1 = Minutes (0-59)

2 = Hour (0-23)

3 = day of month(0-31)

4 = Months (1-12)

5 = Day of Week (0-7) here 0 is sunday

List of current Cronjob

-----------------------

[root@desktopX ~]# crontab -l ; list of current job for root


[root@desktopX ~]# mkdir /backup

Crontab Edit

--------------

[root@desktopX ~]# crontab -e

Example:

-----------

1) Run a cronjob everday 10:30PM

30 22 * * * cp -r /etc/* /backup

2) Run a cronjob every 5 min

*/5 * * * * ping -c 4 192.168.11.254 >> /backup/ping

3) run a cronjob Monday at 23.59 PM

59 23 * * 1 cd /backup && tar -cvf etcbackup.tar /etc/* -c

5) RUn a cronjob december 31 every year

* * 31 12 * /backup/backup.sh

6) run a cronjob for system shutdown everday 11.59PM

59 23 * * * /sbin/shutdown -h now

tar -cvf etcbackup_$(date +%y%m%d).tar /etc/*


LINUX FILE SYSTEM MANAGEMENT
Linux Partition Management:

============================

Window File System: FAT32, NTFS

Linux File sytem: ext2, ext3, ext4, XFS (current),

vfat, swap, ZFS, GlusterFS.

All device files location: /dev/*

* hdd, dvd, cdrom, usb, serial, swap, tty

BIOS (Basic Input Output System)

UEFI (United Extensibel Firmware Interface)

Partition Table Stucture:

------------------------

BIOS ==> MBR (Master Boot Record)

UEFI ==> GPT(GUID Partition Table)

MBR ==> 512-byte sectors, 2TB Max Partition Size

GPT ==> 512-byte sectors, 9.4 Zettabytes Max Partition Size

Total Partition: MBR - BIOS

----------------------------------------------------------

Linux Partition = 15 (4 Primary + 11 Logical)

Windows Partition: 63 C-Z, A- Floppy, B-zip

Total Partition: GPT

-------------------------------------------------------------

Total Partition: 128


IDE/SATA/SAS/SCSI HDD: sda, sdb, sdc

Virtual Machine: vda, vdb

USB: sda1, sdb1

DVD: sr0

[root@desktopX ~]# fdisk -l ; all partition

sda = 1st sata

sdb = 2nd sata

sdc = 3rd sata

vda = 1st virtual disk

vdb = 2nd virtual disk

Linux partition ID:

------------------

NTFS - 7

Extended - 5

ext3/ext4/xfs - 83

swap - 82

LVM - 8e

vfat - f

RAID - fd

[root@hostX ~]# lsblk

[root@hostX ~]# df -HT | grep sda

[root@desktopX ~]# fdisk -l

[root@desktopX ~]# df -HT | grep vda


/dev/vda2 xfs 5.3G 1.1G 4.2G 20% /

/dev/vda1 xfs 521M 94M 427M 19% /boot

[root@desktopX ~]# lsblk

Create New Extended Partition:

-----------------------------

[root@desktopX ~]# fdisk -l

[root@desktopX ~]# parted

(parted) print free

Note: 'q' fore quite

[root@desktopX ~]# fdisk /dev/vda ; MBR based

Command (m for help): m

d delete a partition

l list known partition types

m print this menu

n add a new partition

p print the partition table

q quit without saving changes

t change a partition's system id

w write table to disk and exit

Command (m for help): p


Command (m for help): n

Partition type:

p primary (3 primary, 0 extended, 1 free)

e extended

Select (default e): e

Selected partition 4

First sector (12314624-16777215, default 12314624): {press Enter}

Using default value 12314624

Last sector, +sectors or +size{K,M,G} (12314624-16777215, default 16777215): {press Enter}

Using default value 16777215

Partition 4 of type Extended and of size 4.1 GiB is set

Command (m for help): p

Command (m for help): w

[root@desktopX ~]# fdisk -l

[root@desktopX ~]# partprobe /dev/vda ; partition table update

Create New Logical Partition:

-----------------------------

[root@desktopX ~]# fdisk /dev/vda

Command (m for help): n

All primary partitions are in use

Adding logical partition 5


First sector (12316672-16777215, default 12316672): {press Enter}

Last .. +sectors or +size{K,M,G}. default 16777215): +350M {press Enter}

Partition 5 of type Linux and of size 350 MiB is set

Command (m for help): p

Command (m for help): w

[root@serverX ~]# partprobe /dev/vda

Do: 400 MiB Another Partition

Partition Format Command:

-------------------------

[root@desktopX ~]# mkfs.xfs /dev/vda5

[root@desktopX ~]# mkfs.ext4 /dev/vda6

Partition Mount:

----------------

[root@desktopX ~]# mkdir /data1

[root@desktopX ~]# mkdir /data2

[root@desktopX ~]# df -HT | grep vda

[root@desktopX ~]# mount /dev/vda5 /data1

[root@desktopX ~]# mount /dev/vda6 /data2

[root@desktopX ~]# df -HT | grep vda


Filesystem Type Size Used Avail Use% Mounted on

/dev/vda2 xfs 5.3G 1.1G 4.2G 20% /

/dev/vda1 xfs 521M 94M 427M 19% /boot

/dev/vda5 xfs 364M 19M 345M 6% /data1

/dev/vda6 ext4 416M 19M 396M 1% /data2

[root@desktopX ~]# seq 10000000 > /data2/test

[root@desktopX ~]# df -HT | grep data

[root@desktopX ~]# reboot

[root@desktopX ~]# df -HT | grep vda

Filesystem Type Size Used Avail Use% Mounted on

/dev/vda2 xfs 5.3G 1.1G 4.2G 20% /

/dev/vda1 xfs 521M 94M 427M 19% /boot

Parmanent Mount:

---------------

[root@desktopX ~]# blkid /dev/vda5

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

:set nu

UUID=1b42c7df-717a-420d-b054-81d5a594b5 /dataX xfs defaults 0 0

or

########### Add the following lines ############


/dev/vda5 /data1 xfs defaults 0 0

/dev/vda6 /data2 ext4 defaults 0 0

1 2 3 4 5 6

1 - partition

2 - mountpoint

3 - filesystem

4 - options(quota,acl,ro,luks)

5 - Dumping

*** specifies the option that need to be used by the dump program.

If the value is set to 0, then the partition is execluded from

taking backup and if the option is a nonzero value, the device will be backed up

6 - file system check options

*** mentions the fsck option. That is if the value is set to zero,

the device or partition will be excluded from fsck check and if

it is nonzero the fsck check will be run in the order in which

the value is set. The root partition will have this value set to

one so that it will be checked first by fsck.

[root@desktopX ~]# mount -a ;fstab file update

[root@desktopX ~]# mount

[root@desktopX ~]# reboot

[root@desktopX ~]# df -HT | grep vda


Partition delete

================

*** Warning ****

=> Remove fstab entry (vim /etc/fstab)

=> Unmount

=> Then delete

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

[root@desktopX ~]# umount /dataX

[root@desktopX ~]# df -HT

[root@desktopX ~]# fdisk /dev/vda

Command (m for help): d

Partition number (1-5): 6

Command (m for help): p

Command (m for help): d

Partition number (1-4):4

Command (m for help): w

Note: Before delete, you should unmount partion and delete fstab entry.
[root@desktopX ~]# partprobe /dev/vda

[root@desktopX ~]# fdisk -l

/dev/vda1

/dev/vda2

/dev/vda3

Mount USB pendrive:

-------------------

[root@desktopX ~]# fdisk -l

Disk /dev/sdb: 32.2 GB, 32176472064 bytes

[root@desktopX ~]# mount /dev/sdb1 /mnt

[root@desktopX ~]# cd /mnt

[root@desktopX mnt]# ls

[root@desktopX mnt]# cp cv.docx /root/Desktop

[root@desktopX mnt]# cp /etc/passwd /mnt

[root@desktopX mnt]# cd

[root@desktopX ~]# umount /mnt

[root@desktopX ~]# cd /mnt

[root@desktopX mnt]# ls

Mount DVD:

------------

[root@desktopX ~]# mount /dev/sr0 /media

[root@desktopX ~]# cd /media

[root@desktopX media]# ls

[root@desktopX media]# cd Packages

[root@desktopX Packages]# ls

[root@desktopX Packages]# cd
[root@desktopX ~]# umount /media

[root@desktopX ~]#

============== The End ==============

LINUX SWAP SPACE


Lab Setup:

----------

Application => systemtools => Vritual Machine Manager

DesktopX# virsh snapshot-revert serverX rh200

Working with Linux Swap Partition:

----------------------------------

[root@serverX ~]# free -m ; memory info physical memory & swap space

Minimum required Swap Memory:

------------------------------

RAM Recommended Swap Space:

--------------------------------------

up to 4GB at least 2GB

up to 16GB at least 4GB

up to 64GB at least 8GB

64GB to 256GB at least 16GB

[root@serverX ~]# fdisk -l

/dev/vda2 40183 40314 1048576 82 Linux swap / Solaris

[root@serverX ~]# lsblk


[root@serverX ~]# fdisk /dev/vda

Command (m for help): p

Command (m for help): n

Partition type:

p primary (3 primary, 0 extended, 1 free)

e extended

Select (default e): e

Selected partition 4

First sector (12314624-16777215, default 12314624): {Press Enter}

Using default value 12314624

Last sector, +sectors or +size{K,M,G} (12314624-16777215, default 16777215): {Press Enter}

Using default value 16777215

Partition 4 of type Extended and of size 4.1 GiB is set

Command (m for help): n

All primary partitions are in use

Adding logical partition 5

First sector (12316672-16777215, default 12316672): {Press Enter}

Using default value 12316672

Last sector, +sectors or +size{K,M,G} (12316672-16777215, default 16777215): +750M

Partition 5 of type Linux and of size 750 MiB is set

Command (m for help): p

Command (m for help): t

Partition number (1-5, default 5): 5


de (type L to list all codes): L

Hex code (type L to list all codes): 82

Change type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): p

Command (m for help): w

[root@serverX ~]# partprobe /dev/vda

[root@serverX ~]# swapoff -a

[root@serverX ~]# free -m

[root@serverX ~]# mkswap /dev/vda5

Setting up swapspace version 1, size = 511996 KiB

no label, UUID=7906ac34-4e2a-4b06-b57d-79dd6c66399a

[root@serverX ~]# free -m

total used free shared buffers cached

Mem: 994 141 852 6 0 63

-/+ buffers/cache: 77 916

Swap: 0 0 0

[root@serverX ~]# swapon /dev/vda5

[root@serverX ~]# free -m

total used free shared buffers cached

Swap: 749 0 699

[root@serverX ~]# swapon -a ;all


[root@serverX ~]# free -m

total used free shared buffers cached

Swap: 1260 0 1211

[root@serverX ~]# swapon -s

Filename Type Size Used Priority

/dev/vda5 partition 716796 0 -1

/dev/vda3 partition 524284 0 -2

(Optional)

============

[root@serverX ~]# blkid /dev/vda5

/dev/vda5: UUID="ff6b7c42-f875-4562-b51b-9e245017e37a" TYPE="swap"

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

:set nu

#UUID=aea149e5-a8b4-4fe9-be5e-fce23877468c swap defaults 0 0 ;comment with #'

/dev/vda5 swap swap defaults 0 0

[root@serverX ~]# mount -a

[root@serverX ~]# swapoff -a

[root@serverX ~]# swapon -a

[root@serverX ~]# free -m

or

[root@serverX ~]# reboot


[root@serverX ~]# free -m

================= The End ==================

LINUX LVM MANAGEMENT


Lab Setup:

----------

Application => systemtools => Vritual Machine Manager

[root@localhost ~]# fdisk -l

[root@localhost ~]# fdisk /dev/vda

Command (m for help): n

Select (default e): e

Selected partition 4

First sector (12314624-16777215, default 12314624): {Press Enter}

Using default value 12314624

Last sector, +sectors or +size{K,M,G} (12314624-16777215, default 16777215): {Press Enter}

Using default value 16777215

Partition 4 of type Extended

Command (m for help): p

Command (m for help): n

First sector (902815744-976771071, default 902815744): [press Enter]

Last ... +size{K,M,G} (902815744-976771071, default 976771071): +250M

Command (m for help): p

Command (m for help): t

Command (m for help): Enter your patition no


Command (m for help): l

Command (m for help): 8e

Command (m for help): p

Command (m for help): w

Note: Do 2 more parttion for LVM

[root@localhost ~]# lsblk

[root@localhost ~]# partprobe /dev/vda

Physical Volume Create:

-----------------------

[root@localhost ~]# pvcreate /dev/vda5

[root@localhost ~]# pvcreate /dev/vda6

[root@localhost ~]# pvcreate /dev/vda7

[root@localhost ~]# pvdisplay

Group Volume Create:

-----------------------

[root@localhost ~]# vgcreate vg1 /dev/vda5 /dev/vda6 /dev/vda7

[root@localhost ~]# vgdisplay

Note for Exam: vgcreate –s 32M vg1 /dev/vda5 /dev/vda6 /dev/vda7

(note: Defautl PE Size 4MiB)

Logical Volume Create:


----------------------

[root@localhost ~]# lvcreate -n lv1 -L 400M vg1

[root@localhost ~]# vgdisplay

[root@localhost ~]# lvdisplay

PE Size: 32 MB

[root@localhost ~]# lvcreate -n lv2 -l 5 vg1

[root@localhost ~]# lvdisplay

[root@localhost ~]# lvscan

[root@localhost ~]# mkfs.xfs /dev/vg1/lv1

[root@localhost ~]# mkdir /data1

[root@localhost ~]# mount /dev/vg1/lv1 /data1

[root@localhost ~]# df -HT

[root@localhost ~]#

[root@localhost ~]# mkfs.ext4 /dev/vg1/lv2

[root@localhost ~]# mkdir /data2

[root@localhost ~]# mount /dev/vg1/lv2 /data2

[root@localhost ~]# df -HT

[root@localhost ~]#

Parmanent Mount:

----------------

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


/dev/vg1/lv1 /data1 xfs defaults 0 0

/dev/vg1/lv2 /data2 ext4 defaults 0 0

[root@localhost ~]# mount -a

[root@localhost ~]# mount

VG Extended:

------------

=> fdisk /dev/vda (300 MB)

=> partprobe /dev/vda

[root@localhost ~]# pvcreate /dev/vda8

=> vgextend

[root@localhost ~]# vgextend vg1 /dev/vda8

[root@localhost ~]# vgdisplay

=> lvextend (xfs file system)

[root@localhost ~]# lvextend -L +100M /dev/vg1/lv1

[root@localhost ~]# df -HT | grep data

[root@localhost ~]# lvscan

[root@localhost ~]# xfs_growfs /data1

[root@localhost ~]# df -HT | grep data

=> lvextend (ext4 file system)

[root@localhost ~]# lvextend -l +3 /dev/vg1/lv2


[root@localhost ~]# df -HT | grep data2

[root@localhost ~]# lvscan

[root@localhost ~]# resize2fs /dev/vg1/lv2

[root@localhost ~]# df -HT | grep data

Lv remove:

----------

[root@localhost ~]# vim /etc/fstab ;remove fstab entery

[root@localhost ~]# umount /data1

[root@localhost ~]# umount /data2

[root@localhost ~]# lvremove /dev/vg1/lv1

[root@localhost ~]# lvremove /dev/vg1/lv2

VG Remove:

----------

[root@localhost ~]# vgremove vg1

PV Remove:

----------

[root@localhost ~]# pvremove /dev/vda5

[root@localhost ~]# pvremove /dev/vda6

[root@localhost ~]# pvremove /dev/vda7

[root@localhost ~]# pvremove /dev/vda8

[root@localhost ~]# fdisk /dev/vda

Command (m for help): d

Partition number (1-8, default 8): 4

Command (m for help): w


[root@localhost ~]# partprobe /dev/vda

[root@localhost ~]# fdisk -l

/dev/vda1

/dev/vda2

/dev/vda3

[root@localhost ~]# reboot

================ Done =================

LINUX NETWORK MANAGEMENT

IPV4 (LAN/MAN/WAN)

----------------------

Class A: 0.0.0.0 - 126.255.255.255

Class B: 128.0.0.0 - 191.255.255.255

Class C: 192.0.0.0 - 223.255.255.255

Private:

--------

A: 10.0.0.0 - 10.255.255.255

B: 172.16.0.0 - 172.31.255.255

C: 192.168.0.0 - 192.168.255.255

Linux Network Management

----------------------------

Windows NIC1: Local Area Netowrk

Windows NIC2: Local Area Network 2


Linux

-------

1st NIC : en* or eth0

2nd NIC : en* or eth1

loopback: lo

virtual : en* or eth0:0

Bridge : br0

Wireless: wl

[root@desktop1 ~]# cat /etc/redhat-release

CentOS Linux release 7.0.1406 (Core)

[root@desktop1 ~]# uname -r

3.10.0-123.el7.x86_64

Host Name Configure

---------------------

[root@desktop1 ~]# hostname

[root@desktop1 ~]# vim /etc/hostname

desktopX.example.com

[root@desktop1 ~]# reboot

or

[root@desktopX ~]# hostname

[root@desktopX ~]# hostnamectl status

[root@desktopX ~]# hostnamectl --static set-hostname desktopX.example.com


[root@desktopX ~]# reboot

Check Physical Connectivity:

----------------------------

[root@desktopX ~]# ifconfig

[root@desktopX ~]# mii-tool en** [eth0]

eno16777736: negotiated 1000baseT-FD flow-control, link ok

eno16777736: no link (not connected)

[root@desktopX ~]# ip addr

Check All LAN Card Status

---------------------------

[root@desktopX ~]# ifconfig

[root@desktopX ~]# ip addr

eno16777736 - ethernet card information

[root@desktopX ~]# ifconfig en*** ; sepecific LAN

HWaddr 8C:89:A5:E4:F3:64 => MAC

inet addr:192.168.0.X => IP Address

Bcast:192.168.11.255

Mask:255.255.255.0

N.B: (For Command Mode)

[root@desktopX ~]# yum install net-tools* -y

[root@desktopX ~]# yum install setuptools* -y

Check Default Gateway:


---------------------

[root@desktopX ~]# route -n

[root@desktopX ~]# route add default gw 192.168.11.1

Gateway Testing

--------------------------

[root@desktopX ~]# ping 192.168.11.1

64 bytes from 192.168.11.1: icmp_seq=1 ttl=64 time=0.451 ms

64 bytes from 192.168.11.1: icmp_seq=2 ttl=64 time=0.317 ms

[root@desktopX ~]# ping -c 4 192.168.11.1

IP Configure

--------------------------

=> Tempoary (IP remove after system reboot)

=> Parmanet

Temporary IP Address Configure:

-------------------------------

[root@desktopX ~]# ifconfig

[root@desktopX ~]# ifconfig en*** 192.168.11.100+X

[root@desktopX ~]# ifconfig en*** 192.168.11.100+X netmask 255.255.255.0

[root@desktopX ~]# ifconfig

IP Client Configure

-------------------

=> Static

=> dhcp : autmatically ip configure


Static (parmanent) IP configure:

--------------------------------

[root@desktopX ~]# cd /etc/sysconfig/network-scripts/

[root@desktopX network-scripts]# ls

[root@desktopX network-scripts]# vim ifcfg-en*** or ifcfg-br0, ifcfg-eth0 ; NIC info

NAME="en***" ; no change

TYPE="Ethernet" ; no change

HWADDR="01:1C:2D:35:26:C0" ; no change

BOOTPROTO="none" ; none/static=static

IPADDR=X.X.X.X (192.168.11.X) ;X is your IP address

NETMASK=Y.Y.Y.Y (255.255.255.0)

GATEWAY=X.X.X.G (192.168.11.1)

DNS1=A.A.A.A (4.2.2.2)

DNS2=B.B.B.B (8.8.8.8)

ONBOOT="yes" ; must yes

[root@desktopX network-scrip]# systemctl stop NetworkManager.service

[root@desktopX network-scrip]# systemctl disable NetworkManager.service

[root@desktopX network-scripts]# systemctl restart network.service

[root@desktopX network-scripts]# systemctl enable network.service

[root@desktopX network-scrip]# ifconfig

[root@desktopX ~]# nmtui-edit en*** ; Network Manager must be run

en i.e: enp2s0 or ens33


Note: NM works only in GUI Mode

[root@desktopX ~]# ping 192.168.11.X

LINUX YUM CONFIGURATION

RPM Installation:

-----------------

=> Manually (rpm command)

=> Automatically (YUM Server)

Yum Server Configure:

----------------------------------

=> Requirments:

-------------

=> DVD (centos/redhat)

=> 5GB Free Space in "/var"

=> Default FTP Dir: "/var/ftp/pub"

=> Packages:

1) createrepo - server

2) vsftpd (for yum client)

Step 01: Check free space "/var"

======= ------------------------

[root@serverX Desktop]# df -HT

Filesystem Type Size Used Avail Use% Mounted on

/dev/sda6 ext4 16G 7.1G 7.7G 48% /


note: By default "/var location under "/" partition"

Step 02: Mount DVD under "/mnt"

======= -------------------------

[root@serverX Desktop]# mount /dev/sr0 /mnt ; here "sr0" is dvd device

mount: block dvice /dev/sr0 is write-protected, monting read-only

[root@serverX Desktop]# cd /mnt

[root@serverX mnt]# ls

[root@serverX mnt]# cd Packages

[root@serverX Packages]# ls

Step 03: Dependency Install

======= -------------------------

[root@serverX Packages]# rpm -ivh vsftpd-3.0.2-9.el7.x86_64.rpm

[root@serverX Packages]# systemctl restart vsftpd.service

[root@serverX Packages]# systemctl enable vsftpd.service

Step 04: RPM copy to "/var/ftp/pub"

======= -------------------------

[root@serverX Packages]# cd ..

[root@serverX mnt]# cp -rv Packages /var/ftp/pub

Note: All "Packages" will be copy to "/var/ftp/pub". If old

rpm exist, please delete first.

Step 05: yum server confiugraiton file

======= ------------------------------

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


[root@serverX yum.repos.d]# ls

[root@serverX yum.repos.d]# rm -rf *

[root@serverX yum.repos.d]# ls

[root@serverX yum.repos.d]# vi server.repo

[server]

name = yum server

baseurl = file:///var/ftp/pub/Packages

enabled = 1

gpgcheck = 0

:x

[root@serverX yum.repos.d]# createrepo -v /var/ftp/pub/Packages

[root@serverX yum.repos.d]# yum clean all ; cache clear

[root@serverX yum.repos.d]# yum list all ; list of installed rpm

[root@serverX yum.repos.d]# systemctl disable firewalld.service

[root@serverX yum.repos.d]# setenforce 0

[root@serverX yum.repos.d]# systemctl restart vsftpd.service

[root@serverX yum.repos.d]# ifconfig

YUM Server Test:

----------------

[root@serverX yum.repos.d]# yum install mysql -y ; test command

YUM client Configure:

--------------------

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

[root@desktopX yum.repos.d]# ls

[root@desktopX yum.repos.d]# rm -rf *

[root@desktopX yum.repos.d]# vi client.repo


[client]

name = yum client

baseurl = ftp://192.168.11.X/pub/Packages ;x=254

enabled = 1

gpgcheck = 0

:x

[root@desktopX yum.repos.d]# yum clean all ; cache clear

[root@desktopX yum.repos.d]# yum list all ;list of installed rpm

[root@desktopX yum.repos.d]# yum install php -y ; test installation

================ The End =====================

LINUX VIRTUALIZED SYSTEM

Check VT Support

-----------------

[root@desktopX ~]# grep -i vmx /proc/cpuinfo --color

[root@localhost ~]# cat /proc/cpuinfo

[root@localhost ~]# cat /proc/meminfo

[root@localhost ~]# free -m

Packages

========

=> virt-manager (GUI interface)

=> libvirt (daemon + API collection)

=> qemu-kvm (emulator for virtual OS)


Interface Bridge:

=================

[root@desktopX ~]# yum install bridge-utils -y

[root@desktopX ~]# systemctl stop NetworkManager.service

[root@desktopX ~]# systemctl disable NetworkManager.servie

[root@desktopX ~]# cd /etc/sysconfig/network-scripts

[root@desktopX network-scripts]# cp ifcfg-en*** ifcfg-br0

[root@desktopX network-scripts]# ls

[root@localhost network-scripts]# vim ifcfg-en***

DEVICE=en***

HWADDR=aa:bb:cc:dd:ee:ff

TYPE=Ethernet

BOOTPROTO=none

ONBOOT=yes

BRIDGE=br0

[root@localhost network-scripts]# vim ifcfg-br0

DEVICE=br0

TYPE=Bridge

IPADDR=192.168.0.X ; (100+X)

NETMASK=255.255.255.0

BOOTPROTO=none

ONBOOT=yes

DELAY=0
[root@localhost network-scripts]# systemctl restart network.service

[root@localhost network-scripts]# cd

[root@desktopX ~]# ifconfig

Download CentOS ISO:

--------------------

=> Open Mozila Firefox

=> ftp://192.168.11.254

Step 02:

--------

=> Create a 10G partition

Create Partion:

---------------

[root@ns1 Desktop]# fdisk /dev/sda

Command (m for help): n

First sector (415141888-976773119, default 415141888): {press Enter}

Using default value 415141888

Last sector, +sectors or +size{K,M,G} (415141888-976773119, default 976773119): +10G

Command (m for help): p

Command (m for help): w


[root@desktop1 ~]# partprobe /dev/sda ; partition table update

[root@desktop1 ~]# lsblk

Package Installation

-----------------------

[root@desktopX ~]# yum install virt-manager* libvirt* qemu-kvm* -y

[root@desktopX ~]# systemctl restart libvirtd.service

[root@desktopX ~]# systemctl enable libvirtd.service

Create a ISO:

-------------

[root@desktopX ~]# dd if=/dev/sr0 of=/root/Desktop/centos7.iso

Run VM:

=======

Application => System Tools => VMM

VM Name: Linux-7

Interface: br0

Installation Method: Minimal

Size: /boot (500 MB), / (7 GB), swap (1024)

=> IP configure
[root@serverX ~]# ip addr

[root@serverX ~]# cd /etc/sysconfig/network-scripts

[root@serverX network-scripts]# ls

[root@localhost network-scripts]# vi ifcfg-eth0

DEVICE=eth0

TYPE=Ethernet

HWADDR=XX:XX:XX:XX:XX:XX

IPADDR=192.168.11.X ; (200+X)

NETMASK=255.255.255.0

BOOTPROTO=none

ONBOOT=yes

[root@localhost network-scripts]# systemctl restart network.service

[root@localhost network-scripts]# systemctl enable network.service

[root@localhost network-scripts]# ip addr

=> yum client configure

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

[root@localhost network-scripts]# ls

[root@localhost network-scripts]# rm -rf *

[root@localhost network-scripts]# vi client.repo

[client]

name=yum client

baseurl=ftp://192.168.11.254/pub/Packages ; yum server IP

enabled=1

gpgcheck=0
:x (SAVE & exit)

=> yum install net-tools

=> yum install vim

[root@localhost network-scripts]# ifconfig

Hostname:

---------

[root@serverX ~]# vi /etc/hostname

serverX.example.com

[root@serverX ~]# reboot

HTTP SERVER WITH VIRTUAL HOSTING


HTTP Server:

=============

Pakcages: httpd

daemon: httpd

port: 80 (http), 443 (https)

Configuration file: /etc/httpd/httpd.conf

default index file: /var/www/html

Step 01: DNS Part:

-------------------

[root@ns1 Desktop]# cd /var/named/

[root@ns1 named]# ls

[root@ns1 named]# vi example.com.for


ns1 IN A 192.168.11.254

www IN CNAME ns1.example.com. ; same server

www IN A 192.168.11.80 ; different srever

[root@ns1 named]# vi example.com.rev

80 IN PTR www.example.com. ; different srever

[root@ns1 named]# systemctl restart named.service

[root@ns1 named]# nslookup www.example.com

[root@ns1 named]# dig www.example.com

Step 02: Package Install

-------:

[root@ns1 named]# yum install httpd* -y

[root@ns1 named]# systemctl restart httpd.service

[root@ns1 named]# chkconfig httpd on

Step 03: web hosting

---------------------

[root@ns1 named]# cd /var/www/html/

[root@ns1 html]# ls

squirrelmail webmail

[root@ns1 html]# vi index.html

<html>

<head>

<body bgcolor="#f25dfd">

<h1 allign="center"> ##### welcome to our domain ### </h1>

</body>
</head>

</html>

Step 04: web server configure

-----------------------------

[root@ns1 httpd]# cd /etc/httpd/conf

[root@ns1 conf]# ls

httpd.conf magic

[root@ns1 conf]# vi httpd.conf

95 ServerName www.example.com

96 ServerName 192.168.11.254

[root@ns1 httpd]# systemctl restart httpd.service

Step 05: Open Browser & Test

-----------------------------

Name Based Virtual Hosting

------------------------------------

DNS Part:

-----------

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

[plase add following forward zones as per required ]

19 zone "example.com" IN {

20 type master;

21 file "example.com.for";

22 allow-update { none; };
23 };

24 zone "test.om" IN {

25 type master;

26 file "test.com.for";

27 allow-update { none; };

28 };

29 zone "hello.com" IN {

30 type master;

31 file "hello.com.for";

32 allow-update { none; };

33 };

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

[root@ns1 named]# cp example.com.for test.com.for

[root@ns1 named]# cp example.com.for hello.com.for

[[root@ns1 named]# chgrp named hello.com.for

[root@ns1 named]# chgrp named test.com.for

[root@ns1 named]# vi hello.com.for

[add following line in below]

www IN CNAME ns1.hello.com.

ns1.hello.com. IN A 192.168.11.254

[root@ns1 named]# vim test.com.for

www IN CNAME ns1.test.com.

ns1.test.com. IN A 192.168.11.254

[root@ns1 named]# systemctl restart named.service

[root@ns1 named]# nslookup www.test.com


[root@ns1 named]# nslookup www.hello.com

[root@ns1 named]# cd /var/www/html

[root@ns1 html ]# mkdir example test hello

[root@ns1 html ]# ls

[root@ns1 html ]# cd test

[root@ns1 example]# vi index.html

<html>

<head>

<body bgcolor="#fed2fd">

<h1 allign="center"> ##### welcome to our test ### </h1>

</body>

</head>

</html>

[root@ns1 example]# cd /var/www/html/hello

[root@ns1 hello]# vi index.html

<html>

<head>

<body bgcolor="#d2f8cd">

<h1 allign="center"> ##### welcome to hello ### </h1>

</body>

</head>

</html>

step 02: Web Server configuration Part:

------------------------------

[root@ns1 httpd]# cd /etc/httpd/conf


[root@ns1 conf]# ls

httpd.conf magic

[root@ns1 conf]# vi httpd.conf

95 ServerName www.example.com

96 ServerName 192.168.11.254

119 #DocumentRoot "/var/www/html"

355 NameVirtualHost 192.168.11.254

357 <VirtualHost 192.168.11.254>

358 DocumentRoot /var/www/html/example

359 ServerName www.example.com

360 </VirtualHost>

363 <VirtualHost 192.168.11.254>

364 DocumentRoot /var/www/html/test

365 ServerName www.test.com

366 </VirtualHost>

369 <VirtualHost 192.168.11.254>

370 DocumentRoot /var/www/html/hello

371 ServerName www.hello.com

372 </VirtualHost>

Step 03: Hositng

-----------------

see book and video


ISCSI

Reference Table:

===============

Packages: targetcli (server), iscsi-initiator-utils (Client)

Daemon: target (server), iscsi (client)

Port: 3260

Protocol: TCP

Configuraiton file: /etc/iscsi/initiatorname.iscsi (Client)

New Commands: targetcli, iscsiadm,

Step 01: Package Install and Service enable

-------------------------------------------

[root@serverX ~]# yum install targetcli

[root@serverX ~]# systemctl enable target

[root@serverX ~]# systemctl start target

Step 02: Port Open on System Firewall

------------------------------------------

[root@serverX ~]# firewall-cmd --permanent --add-port=3260/tcp

[root@serverX ~]# firewall-cmd --reload

Step 03: Create a 1GB Diks Space for LVM

----------------------------------------

[root@serverX ~]# fdisk -l

[root@serverX ~]# fdisk /dev/vda

=> Create 1GB Partition


[root@desktopX ~]# partprobe /dev/vda

=> Make a PV for VG

=> Create a VG (iscsi_vg1)

=> Create a LV (iscsi_lv1)

[root@desktopX ~]# pvcreate /dev/vdaX

[root@desktopX ~]# vgcreate iscsi_vg1 /dev/vdaX

[root@desktopX ~]# lvcreate -n iscsi_lv1 -L 1024M iscsi_vg1

Step 04: Configure iSCSI Target

-------------------------------

[root@desktopX ~]# targetcli

/> ls

o- / ........................................... [...]

o- backstores ................................ [...]

| o- block ................................... [Storage Objects: 0]

| o- fileio .................................. [Storage Objects: 0]

| o- pscsi ................................... [Storage Objects: 0]

| o- ramdisk ................................. [Storage Objects: 0]

o- iscsi ..................................... [Targets: 0]

o- loopback .................................. [Targets: 0]

Creating block storage:

----------------------

/> /backstores/block create serverX.disk1 /dev/iscsi_vg1/iscsi_lv1

Create IQN for the target:


--------------------------

/> /iscsi create iqn.2015-05.com.example:serverX

Create a ACL for desktopX:

--------------------------

/> /iscsi/iqn.2015-05.com.example:serverx/tpg1/acls create iqn.2015-05.com.example:desktopX

LUN Mapping:

-----------

/> /iscsi/iqn.2015-05.com.example:serverx/tpg1/luns create /backstores/block/serverX.disk1

Create a Portal for Server on port 3260:

----------------------------------------

/> /iscsi/iqn.2015-05.com.example:serverx/tpg1/portals create 192.168.11.X

Note: /> /iscsi/iqn.2015-05.com.example:serverx/tpg1/portals delete 0.0.0.0 3260

Client Configuration Part:

=========================

Step 05: Package Installation

-----------------------------

[root@desktopX ~]# yum install iscsi-initiator-utils

Step 06: Change default Initiator Name (Defined in ACL)

-------------------------------------------------------

[root@desktopX ~]# vim /etc/iscsi/initiatorname.iscsi


InitiatorName=iqn.2015-05.com.example:desktopX

Step 07: Service Restart and Check Status

-----------------------------------------

[root@desktopX ~]# systemctl enable iscsi

[root@desktopX ~]# systemctl restart iscsi

[root@desktopX ~]# systemctl status iscsi

Step 08: Target Discover

------------------------

[root@desktopX ~]# iscsiadm -m discovery -t st -p 192.168.11.X

192.168.11.X:3260,1 iqn.2015-05.com.example:serverx (output)

Step 09: Connect the iSCSI Target and Verify:

---------------------------------------------

[root@desktopX ~]# lsblk

[root@desktopX ~]# iscsiadm -m node -T iqn.2015-05.com.example:serverx 192.168.11.254 -l

[root@desktopX ~]# lsblk

[root@desktopX ~]# systemctl restart iscsi

[root@desktopX ~]# fdisk -l

Step 10: Create a Partition and Mount

-------------------------------------
[root@desktopX ~]# fdisk /dev/sdX

[root@desktopX ~]# mkfs.xfs /dev/sdX

[root@desktopX ~]# partprobe /dev/sdX

[root@desktopX ~]# mkdir /iscsidisk1

[root@desktopX ~]# mount /dev/sdX /iscsidisk1

[root@desktopX ~]# df -HT

Step 11: Parmanent Mount:

------------------------

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

/dev/sdX /iscsidisk1 xfs defaults 00

[root@desktopX ~]# mount -a

================== Thanks =================

NFS SERVER

NFS (Network File System):

=========================

NFS, stands for Network File System, is a server-client protocol used for

sharing files between linux/unix to unix/linux systems. NFS enables you to

mount a remote share locally. You can then directly access any of the files

on that remote share.

Reference Table:

----------------
Package: nfs-utils, nfs-utils-lib

Daemon: nfs

NFS Server: 192.168.11.200+X (Virtual Machine)

NFS Client: 192.168.11.100+X (Desktop Machine)

Step 01: Package Install

------------------------

[root@serverX ~]# yum install nfs-utils nfs-utils-lib -y

Step 02: Service Restart and enable

-----------------------------------

[root@serverX ~]# systemctl enable rpcbind

[root@serverX ~]# systemctl enable nfs-server

[root@serverX ~]# systemctl enable nfs-lock

[root@serverX ~]# systemctl enable nfs-idmap

[root@serverX ~]# systemctl start rpcbind

[root@serverX ~]# systemctl start nfs-server

[root@serverX ~]# systemctl start nfs-lock

[root@serverX ~]# systemctl start nfs-idmap

Step 03: Create a shared directory

-----------------------------------

[root@serverX ~]# mkdir /nfsshare -p

[root@serverX ~]# cd /nfsshare

[root@serverX nfsshare]# ls

[root@serverX nfsshare]# mkdir download documents software project office

[root@serverX nfsshare]# ls

documents download office project software


[root@serverX nfsshare]# cd documents/

[root@serverX documents]# ls

[root@serverX documents]# touch doc{1..10}

[root@serverX documents]# cd ..

[root@serverX nfsshare]# cd download/

[root@serverX download]# touch file1 file2 file3

[root@serverX download]# cd ..

[root@serverX nfsshare]# cd office

[root@serverX office]# touch job cv profile

[root@serverX office]# cd ..

[root@serverX nfsshare]# cd project/

[root@serverX project]# touch new old test

[root@serverX project]# cd ..

[root@serverX nfsshare]# cd software/

[root@serverX software]# touch office.exe vlc.exe skype.exe

[root@serverX software]# cd ..

[root@serverX nfsshare]#

Step 04: Export shared directory on NFS Server:

----------------------------------------------

[root@serverX ~]# vim /etc/exports

/nfsshare/software 192.168.11.0/24(rw,sync,no_root_squash,no_all_squash)

/nfsshare/project 192.168.11.0/24(ro,sync,no_root_squash,no_all_squash)

/nfsshare/download *(ro,sync,no_root_squash,no_all_squash)

/nfsshare/documents 192.168.11.254(rw,sync)

/nfsshare/office *.example.com(rw,sync)

Note:
====

=> /var/nfshare – shared directory

=> 192.168.11.0/24 – IP address range of clients

=> rw – Writable permission to shared folder

=> sync – Synchronize shared directory

=> no_root_squash – Enable root privilege

=> no_all_squash - Enable user’s authority

Step 05: Restart the NFS service:

--------------------------------

[root@serverX ~]# systemctl restart nfs-server

Client Side Confiugration:

=========================

Step 06: Install NFS packages in your client system

---------------------------------------------------

[root@instructor ~]# yum install nfs-utils nfs-utils-lib

Step 07: Service Restart and enable

-----------------------------------

[root@instructor ~]# systemctl enable rpcbind

[root@instructor ~]# systemctl enable nfs-server

[root@instructor ~]# systemctl enable nfs-lock

[root@instructor ~]# systemctl enable nfs-idmap

[root@instructor ~]# systemctl start rpcbind

[root@instructor ~]# systemctl start nfs-server


[root@instructor ~]# systemctl start nfs-lock

[root@instructor ~]# systemctl start nfs-idmap

Step 08: View NFS Share on NFS Server

-------------------------------------

[root@server254 ~]# showmount -e 192.168.11.154

Export list for 192.168.11.154:

/nfsshare/download *

/nfsshare/office *.example.com

/nfsshare/project 192.168.11.0/24

/nfsshare/software 192.168.11.0/24

/nfsshare/documents 192.168.11.254

Step 09: Mount NFS shares On clients

------------------------------------

[root@instructor ~]# mount -t nfs 192.168.11.X:/nfsshare/documents /mnt

[root@instructor ~]# cd /mnt

[root@instructor mnt]# ls

Step 10: Mount NFS shares On clients

------------------------------------

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

192.168.11.1154:/nfsshare /mnt nfs defaults 0 0

DNS

Application: Name Resulation


Name => IP (www.btcl.gov.bd => 203.112.194.17)

IP => Name (203.112.194.17 => www.btcl.gov.bd)

Daemon: named

Packages: bind

Port: 53

Protocol: TCP and UdP

Configuration file:

=> /etc/sysconfig/network-scripts/ifcfg-en*

=> /etc/hosts

=> /etc/hostname

=> /etc/named.conf

=> /etc/named.rfc1912.zones

=> /var/named/named.localhost (Forward Zone)

=> /var/named/named.looback (Reverse Zone)

Step 01: Set Static IP Address and DNS:

--------------------------------------

[root@desktopX ~]# cd /etc/sysconfig/network-scripts/

[root@desktopX network-scripts]# ls

[root@desktopX network-scripts]# vim ifcfg-e* ; your Interface name

NAME=********

HWADDR=*******

TYPE=Ethernet

BOOTPROTO=none

IPADDR=192.168.11.X

NETMASK=255.255.255.0
GATEWAY=192.168.11.1

ONBOOT=yes

DNS1=192.168.11.X

[root@desktopX network-scripts]# systemctl stop NetworkManager.service

[root@desktopX network-scripts]# systemctl disable NetworkManager.service

[root@desktopX network-scripts]# systemctl restart network.service

[root@desktopX network-scripts]# cat /etc/resolv.conf

Step 02: Local resolver entry:

------------------------------

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

192.168.11.X ns1.example.com ns1 ; add below of 2 lines

* save and exit

[root@desktopX ~]# ping ns1.example.com

Step 03: Set Static Host Name and Reboot:

----------------------------------------

[root@desktopX ~]# vim /etc/hostname

ns1.example.com

[root@desktopX ~]# reboot

Step 04: Install Required RPM:

------------------------------
[root@ns1 ~]# yum install bind* -y

Step 05: Allow DNS Server IP and Network:

----------------------------------------

[root@ns1 ~]# cp /etc/named.conf /etc/named.conf.backup

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

11 listen-on port 53 { 127.0.0.1; 192.168.11.X; };

12 # listen-on-v6 port 53 { ::1; };

17 allow-query { localhost; 192.168.11.0/24; };

Step 06: Set Forward and Reverse Zones:

---------------------------------------

[root@ns1 ~]# cp /etc/named.rfc1912.zones /etc/named.rfc1912.zones.backup

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

19 zone "example.com" IN {

20 type master;

21 file "example.com.for";

22 allow-update { none; };

23 };

31 zone "11.168.192.in-addr.arpa" IN {

32 type master;

33 file "example.com.rev";

34 allow-update { none; };

35 };

Step 07: Create Forward and Reverse Zone Files:


-----------------------------------------------

[root@ns1 Desktop]# cd /var/named/

[root@ns1 named]# ls

[root@ns1 named]# cp named.localhost example.com.for

[root@ns1 named]# cp named.loopback example.com.rev

[root@ns1 named]# ls -l

Step 08: Set Ownership to Forward and Reverse Zone Files:

---------------------------------------------------------

[root@ns1 named]# ll example.com.*

-rw-r-----. 1 root root 152 Mar 21 13:59 example.com.for

-rw-r-----. 1 root root 168 Mar 21 13:59 example.com.rev

[root@ns1 named]# chgrp named example.com.*

[root@ns1 named]# ll example.com.*

-rw-r-----. 1 root named 152 Mar 21 13:59 example.com.for

-rw-r-----. 1 root named 168 Mar 21 13:59 example.com.rev

Step 09: Edit Forward Zone File:

--------------------------------

[root@ns1 named]# vim example.com.for

$TTL 1D

@ IN SOA ns1.example.com. root.example.com. (

0 ; serial

1D ; refresh

1H ; retry

1W ; expire
3H ) ; minimum

IN NS ns1.example.com.

IN A 192.168.11.X

ns1 IN A 192.168.11.X

Note:

-----

SOA - Start of Authority

IN - Internet

NS - Name Server (DNS Server)

A - Host Record (IP Address)

root - email admin

PTR - Pointer (Reverse)

Step 10: Edit Reverse Zone File:

--------------------------------

[root@ns1 named]# vim example.com.rev

$TTL 1D

@ IN SOA ns1.example.com. root.example.com. (

0 ; serial

1D ; refresh

1H ; retry

1W ; expire

3H ) ; minimum

IN NS ns1.example.com.
X IN PTR ns1.example.com.

Step 11: Service restart and configured active at boot time:

------------------------------------------------------------

[root@ns1 named]# systemctl restart named.service

[root@ns1 named]# systemctl enable named.service

Step 12: Checking DNS

---------------------

[root@ns1 named]# nslookup ns1.example.com

Server: 192.168.11.X

Address: 192.168.11.X#53

Name: ns1.example.com

Address: 192.168.11.X

[root@ns1 named]# dig -x 192.168.11.X ; here -X is option

status: NOERROR

[root@ns1 named]# dig ns1.example.com

status: NOERROR

[root@ns1 named]# ping www.google.com

======================= Thank you ======================


MAIL SERVER

Mail Server:

============

=> MUA (Mail user Agent): outlook, thunderbird, eudora, webmail

=> MTA (Mail Transfer Agent): MS exchange,qmail,postfix,sendmail

=> MDA (Mail Delivery Agent): POP3 Server (Dovecot)

Email Protocol:

================

=> SMTP 25 : client to Server, server to server

=> PoP3 110: server to client

=> IMAP 143: client to server (simultaniously used)

DNS Part:

----------

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

[root@ns1 named]# vim example.com.for

IN NS ns1.example.com.

IN MX 10 mail.example.com.

IN A 192.168.11.X

ns1 IN A 192.168.11.X

mail IN CNAME ns1.example.com.

[root@ns1 named]# systemctl restart named.service


note: CNAME - Canonical Name ( If we want to configure multiple server like DNS, FTP, MAIL, Web in
same machine then, we can use CNAME insted of "A" record.

[root@ns1 named]# nslookup mail.example.com

Server: 192.168.11.251

Address: 192.168.11.251#53

mail.example.com canonical name = ns1.example.com.

Name: ns1.example.com

Address: 192.168.11.251

Firewall: off

SElinux: off

Step 01:

--------

[root@ns1 named]# yum install postfix* -y

Step 02:

--------

[root@ns1 ~]# cp /etc/postfix/main.cf /etc/postfix/main.cf.backup

[root@ns1 named]# vim /etc/postfix/main.cf

75 myhostname = mail.example.com

83 mydomain = example.com

99 myorigin = $mydomain

113 inet_interfaces = all

116 #inet_interfaces = all

164 #mydestination = $myhostname, localhost.$mydomain, localhost


165 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

250 mynetworks_style = subnet

264 mynetworks = 198.168.11.0/24, 127.0.0.0/8

419 home_mailbox = Maildir/

572 smtpd_banner = $myhostname ESMTP $mail_name

[root@ns1 named]# systemctl restart postfix.service

[root@ns1 named]# systemctl enable postfix.service

[root@ns1 named]# yum install telnet -y

Step 03: SMTP Testing

=====================

[root@ns1 named]# telnet mail.example.com 25

Trying 192.168.11.251...

Connected to mail.example.com.

Escape character is '^]'.

220 mail.example.com ESMTP Postfix

quit

221 2.0.0 Bye

Connection closed by foreign host.

Step 04: dovecot install

========================:

[root@ns1 named]# yum install dovecot* -y

Step 05: dovecot configure

========================:
[root@linux06 ~]# vim /etc/dovecot/dovecot.conf

24 protocols = imap pop3 lmtp

30 listen = *

42 login_greeting = Welcome to CSL Training

[root@ns1 named]# vim /etc/dovecot/conf.d/10-mail.conf

24 mail_location = maildir:~/Maildir

[root@ns1 named]# vim /etc/dovecot/conf.d/10-auth.conf

10 disable_plaintext_auth = no

100 auth_mechanisms = plain login

[root@ns1 named]# vim /etc/dovecot/conf.d/10-master.conf

90 #mode = 0600

91 user = postfix

92 group = postfix

93 }

[root@ns1 named]# systemctl enable dovecot.service

[root@ns1 named]# systemctl restart dovecot.service

Step 06: POP Testing

=====================

[root@ns1 ~]# telnet mail.example.com 110

Trying 192.168.11.253...

Connected to mail.example.com.

Escape character is '^]'.

+OK Welcome to CSL Training


quit

+OK Logging out

Connection closed by foreign host.

Mail User Create:

-------------------

[root@ns1 ~]# useradd -s /sbin/nologin sadia.afroz

[root@ns1 ~]# useradd -s /sbin/nologin rose

[root@ns1 ~]# useradd -s /sbin/nologin jack

[root@ns1 named]# passwd jack

[root@ns1 named]# passwd rose

[root@ns1 named]# passwd sadia.afroz

BASH SCRIPTING
Shell:

=======

input from keyboard via users

out put to monitor from kernel

Types of shell:

-----------------

1. shell sh(.sh)

2. bash shell (commonly used)


3. zshell

4. cshell (c programming based)

5. kshell

Current installed shell in system:

===================================

[root@serverX ~]# cat /etc/shells

/bin/sh

/bin/bash

/sbin/nologin

/usr/bin/sh

/usr/bin/bash

/usr/sbin/nologin

how to write a script:

=========================

#!/bin/bash

# this is a test script

echo "hello"

varibale types:

=================

user defined: small character

system variable: block (USER/SHELL/HOME: (no=88)

command:

[root@ns1 ~]# printenv ; list of common env variable

simple wite a shell script:

==========================
root#vim myshell.sh

#!/bin/bash

#this a shell comment

clear

echo "hello"

sleep 2

echo -n "Enter your name":

read name

echo " you type, your name is" $name

echo "my MAC address is:" `ifconfig eth:x0 | grep ether`

sleep 2

echo "My IP address Is": `ifconfig eth0 |grep 'inet'|cut -d':' -f2|awk '{print $2}'`

echo "you login as " $USER

sleep 2

echo "Thank you"

shell permission

-----------------

[root@ns1 ~]# chmod u+x myshell.sh

shell run:

===========

[root@ns1 ~]# ./myshell.sh

or

[root@ns1 ~]# sh myshell.sh


yum client script:

=================

#!/bin/bash

#this script for yum client configuraiotn

echo "welcome to yum client configuration"

echo "Enter your yum server IP address: "

read server

echo "you type your server ip address is:" $server

echo "pinging your server:"

echo "`ping -c 2 $server`"

cd /etc/yum.repos.d/

`rm -rf * `

`touch client.repo`

`echo [client] > /etc/yum.repos.d/client.repo`

echo name=my yum client >> /etc/yum.repos.d/client.repo

echo baseurl=ftp://$server/pub/Package >> /etc/yum.repos.d/client.repo

echo gpgcheck=0 >> /etc/yum.repos.d/client.repo

echo enabled=1 >> /etc/yum.repos.d/client.repo

echo "your yum client is ready"

sleep 1

echo "thank you"

FTP

FTP Server:

============

FTP - File Transfer Protocol

Port: 20 (Data),21 (Control)

Protocol: TCP
Packages: vsftpd

Daemon: vsftpd

Configuration file: /etc/vsftpd/vsftpd.conf

Directory location: /var/ftp/pub/*

Step 01: (RPM check)

---------

[root@serverX Desktop]# rpm -qa | grep vsftpd

[root@serverX Desktop]# yum install vsftp* -y

[root@serverX Desktop]# rpm -qa | grep vsftpd

[root@serverX Desktop]# cd /var/ftp

[root@serverX ftp]# mkdir download movie software

[root@serverX ftp]# touch file1 file2

[root@serverX Desktop]# systemctl restart vsftpd.service

[root@serverX Desktop]# systemctl enable vsftpd.service

[root@serverX Desktop]# systemctl stop firewalld.service

[root@serverX Desktop]# setenforce 0 ; selinux disabled

Now Open your browser: (Client)

--------------------

Type: ftp://192.168.11.x

[root@serverX Desktop]# yum install firefox -y

FTP Server Types:

========================
1) Normal FTP

2) Authentication based

FTP user:

--------------

1) Anononymous user: guest user (no password)

2) Authentication FTP user: FTP group user

3) local user (local user of server crated by root)

FTP Access:

-------------

1) Web Based: ftp://ftp.serverXcbt.com or ftp://192.168.11.254

2) Command Based: # ftp 192.168.11.254

3) Software Based: Filezilla, cuteFTP

username: xxxxs

passwword: ****

port: 21

Commaand Mode: Anonymous Login

------------------------------

[root@serverX ~]# yum install ftp -y

[root@serverX ~]# ftp 192.168.11.252

Connected to 192.168.11.254 (192.168.11.254).

220 (vsFTPd 2.2.2)

Name (192.168.11.254:root): anonymous

password: ***** (any)

ftp> dir

ftp> cd pub
ftp> ls

ftp> bye

User Authentic Based FTP Server:

--------------------------------------

[root@serverX ~]# cd /

[root@serverX /]# mkdir ftpdir

[root@serverX /]# touch ftpdir/file{1..10}

[root@serverX /]# groupadd ftpusers

[root@serverX /]# chgrp ftpusers ftpdir

[root@serverX /]# chmod 770 -R ftpdir ; see below permisison

[root@serverX /]# useradd -G ftpusers -d /ftpdir shakil

[root@serverX /]# useradd -G ftpusers -d /ftpdir shahin

[root@serverX /]# useradd -G ftpusers -d /ftpdir shamim

[root@serverX /]# cat /etc/group

ftpusers:x:603:shakil,shahin,shamim

[root@serverX /]# passwd shahin

[root@serverX /]# passwd shamim

[root@serverX /]# passwd shakil

[root@serverX /]# vi /etc/vsftpd/vsftpd.conf

12 anonymous_enable=NO ; NO => YES

[root@serverX Desktop]# systemctl restart vsftpd.service


Try with Web Browser: ftp://192.168.11.X

Chroot Jail:

--------------

[root@serverX /]# vi /etc/vsftpd/vsftpd.conf

101 #chroot_list_enable=YES ; before

101 chroot_list_enable=YES ; after

103 #chroot_list_file=/etc/vsftpd/chroot_list ; before

103 chroot_list_file=/etc/vsftpd/chroot_list ; after

[root@ns1 Desktop]# vi /etc/vsftpd/chroot_list

shakil

shamim

shahin

[root@serverX Desktop]# systemctl restart vsftpd.service

[root@ns1 Desktop]# chmod a-w /ftpdir

*** Now Check

---------- Test Now ----------

User Protect:

=================

[root@serverX /]# vi /etc/vsftpd/ftpusers

shahin ; add below of file


[root@serverX Desktop]# systemctl restart vsftpd.service

CACTI

What is Cacti?

--------------

Cacti tool is an open source web based network monitoring and system monitoring

graphing solution for IT business. Cacti enables a user to poll service at regular

intervals to create graps on resulting data using RRDtool. Generally, it is used

to graph time-series data of metrics such as network bandwidth utilization, CPU load,

running process, disk space etc.

Cacti Required Packages:

------------------------

=> Apache : A Web server to display network graphs created by PHP and RRDTool.

=> MySQL: : A Database server to store cacti information.

=> PHP : A script module to create graphs using RRDTool.

=> PHP-SNMP : A PHP extension for SNMP to access data.

=> NET-SNMP : A SNMP (Simple Network Management Protocol) is used to manage network.

=> RRDTool : A database tool to manage and retrieve time series

Step 01: Install Required Packages:

-----------------------------------

[root@serverX ~]# yum install httpd httpd-devel mariadb-server php-mysql php-pear

php-common php-gd php-devel php php-mbstring php-cli -y


[root@serverX ~]# yum install php-snmp net-snmp-utils net-snmp-libs rrdtool -y

Step 02: Service Restart and Onboot on:

---------------------------------------

[root@serverX ~]# systemctl restart httpd.service

[root@serverX ~]# systemctl enable httpd.service

[root@serverX ~]# systemctl restart snmpd.service

[root@serverX ~]# systemctl enable snmpd.service

[root@serverX ~]# systemctl restart mariadb.service

[root@serverX ~]# systemctl enable mariadb.service

Step 03: Enable EPEL Repo:

--------------------------

[root@serverX ~]# cd /opt/

[root@serverX ]# yum install epel-release -y

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

[root@serverX yum.repos.d]# ls

CentOS-Base.repo

CentOS-Debuginfo.repo

CentOS-Sources.repo

CentOS-Vault.repo

epel.repo

epel-testing.repo

Step 04: Install Cacti through EPEL:

------------------------------------

[root@serverX ~]# yum install cacti -y

[root@serverX ~]# rpm -qa | grep cacti


cacti-0.8.8b-7.el7.noarch

Step 05: Set MySQL Password:

----------------------------

[root@serverX ~]# mysqladmin -u root password centos ;here password is 'centos'

Step 06: Create MySQL Cacti Database:

-------------------------------------

[root@serverX ~]# mysql -u root -p

Enter password: ****** (centos)

#####################################################################################
###

# #

# MariaDB [(none)]> create database cacti; #

# Query OK, 1 row affected (0.00 sec) #

# #

# MariaDB [(none)]> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'centos';

# Query OK, 0 rows affected (0.00 sec) #

# #

# MariaDB [(none)]> FLUSH privileges; #

# Query OK, 0 rows affected (0.00 sec) #

# #

# MariaDB [(none)]> quit; #

# Bye #

# #
#####################################################################################
###

Step 07: Install Cacti Tables to MySQL:

---------------------------------------

[root@serverX ~]# rpm -ql cacti | grep cacti.sql

/usr/share/doc/cacti-0.8.8b/cacti.sql

Now we’ve of the location of Cacti.sql file, type the following command to install tables,

here you need to type the Cacti user password.

[root@serverX ~]# mysql -u root -p cacti < /usr/share/doc/cacti-0.8.8b/cacti.sql

Step 08: Configure MySQL settings for Cacti:

--------------------------------------------

[root@serverX ~]# vim /etc/cacti/db.php

/* make sure these values refect your actual database/host/user/password */

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "cacti"; ;change name

$database_password = "centos"; ;change password

$database_port = "3306";

$database_ssl = false;

Step 09: Configuring Firewall for Cacti:

----------------------------------------
[root@serverX ~]# firewall-cmd --permanent --zone=public --add-service=http

[root@serverX ~]# firewall-cmd --reload

or

[root@serverX ~]# systemctl stop firewalld

[root@serverX ~]# systemctl disable firewalld

Step 10: Configuring Apache Server for Cacti:

---------------------------------------------

[root@serverX ~]# vim /etc/httpd/conf.d/cacti.conf

17 Require all granted

23 Allow from 172.25.11.0/24

[root@serverX ~]# systemctl restart httpd.service

Step 11: Setting Cron for Cacti:

--------------------------------

[root@serverX ~]# vim /etc/cron.d/cacti

*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1

[root@server254 ~]# systemctl restart crond.service

[root@server254 ~]# systemctl enable crond.service

Step 12: Running Cacti Installer Setup:

---------------------------------------

=> Open your browser and browse http://X.X.X.X/cacti


username: admin

password: admin

Step 13: Create a Bandwidth Graph:

----------------------------------

=> Click Device

=> Add

=> Description: Linux-Server

=> Host Name: 172.25.11.X

=> Host Template: Local Linux Machine

=> SNMP Version: 2

=> Community: public

=> Click Create

=> Create Graph Template for Linux-Server host:

-------------------------------------------

=> Click Device

=> Click Linux-Server

=> Add Associate Data Queries

=> Select "SNMP - Interface Statistics"

=> Click "Add"

=> Select "UNIX - Mounted Partition"

=> Click "Add"

=> Select "SNMP - Processor Information"

=> Click "SAVE"


Configure SNMP:

---------------

[root@server254 ~]# vim /etc/snmp/snmpd.conf

55 view systemview included .1.3.6.1.2.1.1 ;[old config]

55 view systemview included .1.3.6.1.2.1 ;[new config]

[root@server254 ~]# systemctl restart snmpd

=> Create New Graph:

-----------------

=> Click New Graph for this host

=> Select: Host (Linux-Server)

=> Selct Graph Template

=> Select Data Query: (Mounted partition: /, /boot, swap), Interface: eth0

=> Slect 64 bit counter

=> Create

SQUID

Proxy Server

==============

=> Caching

=> Monitoring

=> Filtering & Access Control

=> BW control

=> Authentication

=> Gateway
=> Log

Proxy Types:

=========

=> normal proxy (user can by pass)

=> transparent proxy (user cannot bypass)

=> reverse proxy

packages:

-------------

=> squid

=> daemon: squid

=> configuration file: /etc/squid/squid.conf

=> port: 3128 (Default)

Step 01: Package Installation

-----------------------------

[root@serverX ~]# rpm -qa | grep squid

[root@serverX ~]# yum install squid* -y

[root@serverX ~]# cd /etc/squid/

[root@serverX squid]# ls

[root@serverX squid]# cp squid.conf squid.conf.bkf

Step02: Basic Configure

-----------------------

[root@serverX squid]# vim squid.conf

8 #acl localnet src 10.0.0.0/8 # RFC1918 possible internal network


9 #acl localnet src 172.16.0.0/12 # RFC1918 possible internal network

10 #acl localnet src 192.168.0.0/16 # RFC1918 possible internal network

11 #acl localnet src fc00::/7 # RFC 4193 local private network range

12 #acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) mac hines

13 acl mylan src 192.168.11.0/24

52 # http_access allow localnet ; add '#'

54 http_access allow mylan ; add new line (allow local network)

63 cache_dir ufs /var/spool/squid 100 16 256 ; remove '#'

67 visible_hostname proxy.example.com ; add new line

Note:

=====

100 - MB

16 - Folder

256 - Subfolder

[root@serverX squid]# systemctl restart squid.service

[root@serverX squid]# systemctl enable squid.service

[root@serverX squid]# systemctl stop firewalld.service

Chekcing:

---------

[root@serverX squid]# squid -z

[root@serverX squid]# netstat -tlnup | grep 3128


Proxy Setting:

--------------

Firefox => Edit > Preference => Advanced => Network => Settings

Monitoring Live access:

========================

[root@ns1 yum.repos.d]# tail -f /var/log/squid/access.log

[root@serverX ~]# vim /etc/squid/badsite.txt

www.bdnews24.com

www.bdjobs.com

www.porn.com

29 acl badsite dstdomain "/etc/squid/badsite.txt"

35 http_access deny badsite

[root@serverX ~]# vim /etc/squid/keywords.txt

movie

bdnews

sex

29 acl keywords url_regex -i "/etc/squid/keywords.txt"

35 http_access deny keywords

[root@serverX ~]# vim /etc/squid/badip.txt

192.168.11.100
192.168.11.150

192.168.11.200

29 acl badip src "/etc/squid/badip.txt"

35 http_access deny badip

[root@serverX ~]# vim /etc/squid/https.txt

www.facebook.com

www.youtube.com

www.twitter.com

29 acl https_site dstdomain "/etc/squid/https.txt "

35 http_access deny CONNECT https_site

[root@serverX ~]# vim /etc/squid/allowip.txt

192.168.11.251

192.168.11.252

192.168.11.253

DHCP

DHCP Server Configure:

-----------------------

=> Package: dhcp-4.2.5-27.el7

=> Daemon: dhcpd

=> port: 67(client), 68(server)


=> protocol: UDP

=> Configuration File Location:

> Sample file: /usr/share/doc/dhcp-4.2.5/dhcpd.conf.sample

> config file: /etc/dhcp/dhcpd.conf

=> Application: Automatically IP/DNS/domain/subnetmask provide to host

Link Status Check:

-------------------

[root@localhost mnt]# ifconfig

[root@localhost mnt]# mii-tool enp2s0

enp2s0: negotiated 100baseTx-FD flow-control, link ok

Setting Static IP:

-------------------

[root@localhost mnt]# systemctl stop NetworkManager.service

[root@localhost mnt]# systemctl disable NetworkManager.service

[root@localhost mnt]# cd /etc/sysconfig/network-scripts

[root@localhost network-scripts]# vim ifcfg-enp2s

HWADDR=74:D4:35:7C:F8:0F

TYPE=Ethernet

BOOTPROTO=none

NAME=enp2s0

UUID=45cf6de7-1098-45c8-ad7c-44c24cbd80d8

ONBOOT=yes

IPADDR=192.168.99.254

NETMASK=255.255.255.0
GATEWAY=192.168.99.1

DNS1=8.8.8.8

DNS2=4.2.2.2

[root@localhost network-scripts]# systemctl enable network.service

[root@localhost network-scripts]# systemctl restart network.service

[root@localhost network-scripts]# ifconfig

[root@localhost network-scripts]# ifconfig

enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.99.254 netmask 255.255.255.0 broadcast 192.168.99.255

OR

[root@localhost network-scripts]# ip addr

Step 01:

--------

[root@csl ~]# rpm -qa | grep dhcp

[root@csl ~]# yum install dhcp* -y

[root@csl ~]# rpm -qa | grep dhcp

dhcp-4.2.5-27.el7.centos.x86_64

Step 02: configuration File copy

---------

[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

cp: overwrite `/etc/dhcp/dhcpd.conf'? y ; press "y"

root@csl ~]# vi /etc/dhcp/dhcpd.conf


47 subnet 192.168.99.0 netmask 255.255.255.0 { # network ID

48 range 192.168.99.30 192.168.99.45; # dhcp IP range

49 option domain-name-servers 8.8.8.8; # dns server

50 option domain-name "cslcbt.com"; # domain name

51 option routers 192.168.99.1; # gateway

52 option broadcast-address 192.168.11.255; # netowrk Broadcast Address

53 default-lease-time 600;

54 max-lease-time 7200;

55 }

#fixed Address

75 host printer {

76 hardware ethernet 8C:89:A5:E4:F3:64;

77 fixed-address 192.168.99.99;

78 }

Note: DHCP server must configure with Static IP address with same subnet.

[root@localhost ~]# systemctl enable dhcpd.service

[root@localhost ~]# systemctl restart dhcpd.service

[root@localhost ~]# systemctl status dhcpd.service

====================== Thank you ==================

You might also like