Sunday, January 24, 2021

Quick Review in linux

 

 

How to Creating, Removing, Copying, Moving files & Directories in Linux

Using cat command:

[root@dev ~]# cat > filename1
This is world file                                Ctrl+d (To save the file)

To display the content of the file

[root@dev ~]# cat filename1
This is world file

To display the content of the file

[root@dev ~]# cat >> filename1
This second line
[root@dev ~]# cat filename1
This is world file This second line

Creating multiple files at same time using touch command

[root@dev db_bak]# touch file{1..5}
[root@dev db_bak]# ls
file1  file2  file3  file4  file5

Creating a Directory:

[root@dev db_bak]# mkdir dir1
[root@dev db_bak]# ls
dir1

Making multiple directories inside a directory

 [root@dev ~]# mkdir -p technology/{linux/{shell_script,linux},java/{basic,adv_java},mysql/{DBA,Dev}}

[root@dev ~]# tree technology/
technology/
|-- java
|   |-- adv_java
|   `-- basic
|-- linux
|   |-- linux
|   `-- shell_script
`-- mysql
    |-- DBA
    `-- Dev

9 directories, 0 files
 

Copying files into directory

[root@dev ~]# ls
filename    

[root@dev ~]# cp filename technology/
[root@dev ~]# ls
filename  

[root@dev ~]# cd technology/
[root@dev technology]# ls
filename  java  linux  mysql

Copying directories from one location to other

[root@dev technology]# cp -rvfp java  linux/
‘java’ -> ‘linux/java’
‘java/basic’ -> ‘linux/java/basic’
‘java/adv_java’ -> ‘linux/java/adv_java’
[root@dev technology]# cd linux/
[root@dev linux]# ls
java  linux  shell_script

Moving files from one location to other (cut and Paste)
[root@dev technology]# ls
filename  java  linux  mysql
[root@dev technology]# mv filename  java/

[root@dev technology]# cd java/
[root@dev java]# ls
adv_java  basic  filename

Moving a Directory from one location to other

[root@dev technology]# ls
java  linux  mysql
[root@dev technology]# mv java/ linux/
[root@dev technology]# ls
linux  mysql
[root@dev technology]# cd linux/
[root@dev linux]# ls
java  linux  shell_script

Renaming a File

[root@dev linux]# ls
java  linux  shell_script
[root@dev linux]# mv linux/ linux_adv
[root@dev linux]# ls
java  linux_adv  shell_script

[root@dev linux]# rm file

rm: remove regular empty file ‘file’? y

Vim editor command

Command Mode:
gg     To go to the beginning of the page
G       To go to end of the pagew
b       To move the cursor forward, word by word
nb     To move the cursor backward, word by word
nw    To move the cursor forward to n words (5W)
nb     To move the cursor backward to n words (5B)
u       To undo last change (word)  

Ctrl+R   To redo the changes

yy    To copy line 

nyy   to copy no of line

dd    to delete line 

p     to past line

Symbolic Link :-  There are two types of Links

 Soft Link :                                                       

1. Size of link file is equal to no. of characters in the name of original file
2. Can be created across the Partition
3.Inode no. of source and link file is different
4.if original file is deleted, link is broken and data is lost
5.SHORTCUT FILE

[root@dev ~]# ln -s /aws/  aws.slink 

Hard link :

1. Size of both file is same
2 .Can't be created across the partition
3.Inode no. of both file is same
4.If original file is deleted then also link will contain data
5.BACKUP FILE

[root@dev ~]# ln  /aws/  aws.hlink  

File Permissions:

Permissions are applied on three levels:-
 Owner or User level
 Group level
 Others level
Access modes are of three types:-
 r  - read only
 w - write/edit/delete/append
 x  - execute/run a command

[root@dev ~]# chmod u=rwx,g=rw,o=r filename
[root@dev ~]# ls -l filename
-rwxrw-r--. 1 root root 13 Nov 18 15:35 filename

2 Absolute Method (numbers) In Absolute method we use numbers instead of using symbols i.e.
Read=4
Write=2
Execute=1

[root@dev ~]# chmod 764 filename
[root@dev ~]# ls -l filename
-rwxrw-r--. 1 root root 13 Nov 18 15:35 filename

Removing all permissions from others
[root@dev ~]# chmod 760 filename (where 0 indicates no permissions)

Umask:
When we create any file using touch, cat or vi commands they get created with default file permissions as stored in umask (User file creation mask).

[root@dev ~]# umask
0022

Calculation of default permissions for file and directory, basing upon the umask value
Note: For a file by default it cannot have the execute permission, so the maximum full permission for a file at the time of creation can be 666 (i.e. 777 -111 = 666), whereas a directory can have full permissions i.e. 777

The full permission for the file                         666
Minus the umask value                                   -022
The default permission for file is                     644  (rw-,r--,r--)


The full permission for the directory                777

Minus the umask value                                    - 022 

The default permission for file is                    755 (rwx, r-x, r-x)

HOW TO CREATE PARTITION AND MOUNT

[root@dev ~]# fdisk /dev/sdb 

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended

Partition number (1-4, default 1): 1
First sector (2048-16777215, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215): +2048M   
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): w
The partition table has been altered!

[root@dev ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)

Temporary mount
[root@dev ~]# mount /dev/sdb1 linux
[root@dev ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   60G  0 disk
├─sda1            8:1    0    1G  0 part
└─sda2            8:2    0   59G  0 part
  ├─centos-root 253:0    0   37G  0 lvm  /
  ├─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0 18.1G  0 lvm  
sdb               8:16   0    8G  0 disk
└─sdb1            8:17   0    2G  0 part /root/linux

Fuser command used

[root@dev ~]# fuser -cu linux
/root/linux:         23963c(root)

Note :- It is show how many user used this directory  

[root@dev ~]# fuser  -ck linux
/root/linux:         23963c

Note :- forcefully kill user and log out 

To view the usage information of mounted partition:

[root@dev ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G   34M  1.9G   2% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   38G  4.6G   33G  13% /
/dev/sda1               1014M  149M  866M  15% /boot
/dev/mapper/centos-home   19G   33M   19G   1% /home
/dev/sdb1                2.0G  6.0M  1.8G   1% /root/linux

Creating a Swap Partition:

[root@dev ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x13fe498e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   8e  Linux LVM

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (8390656-16777215, default 8390656):
Using default value 8390656
Last sector, +sectors or +size{K,M,G} (8390656-16777215, default 16777215): +2048M
Partition 3 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x13fe498e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   8e  Linux LVM
/dev/sdb3         8390656    12584959     2097152   83  Linux

Command (m for help): t
Partition number (1-3, default 3): 3

Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x13fe498e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   8e  Linux LVM
/dev/sdb3         8390656    12584959     2097152   82  Linux swap / Solaris

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@dev ~]# partprobe
[root@dev ~]# mkswap /dev/sdb3
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=d2fde43f-4e96-42a5-9ac8-8cb7fa6d18c5
[root@dev ~]# swapon /dev/sdb3
[root@dev ~]# swapon -s
Filename                Type        Size    Used    Priority
/dev/dm-1                                  partition    4063228    0    -2
/dev/sdb3                                  partition    2097148    0    -3
 

Check Swap memory 

[root@dev ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3789         829         417          33        2542        2648
Swap:          6015           0        6015
 

Reduce Swap memory

[root@dev ~]# swapoff /dev/sdb3
[root@dev ~]# free -m

              total        used        free      shared  buff/cache   available
Mem:           3789         828         417          33        2542        2648
Swap:          3967           0        3967


Apache Configuration

HOW TO CONFIGURE VIRTUAL WEB HOSTING 

 [root@dev ~]# vi  /etc/httpd/conf.d/ip.conf
<VirtualHost 192.168.0.10:80>
ServerAdmin root@dev.example.com
ServerName  www1.example.com
DocumentRoot /var/www/
</virtualhost>
<Directory "/var/www/">
AllowOverride none
Require all Granted
</Directory>

[root@dev ~]# vi /var/www/index.html 

[root@dev ~]# vi /etc/hosts 

192.168.105.62 www1.example.com
192.168.105.62 www2.example.com

[root@dev ~]# firewall-cmd --permanent --add-service=http
success
[root@dev ~]# firewall-cmd --complete-reload
success

[root@dev ~]# elinks www1.example.com  

HOW TO REDIRECT WEBSITE

 [root@dev ~]# vi  /etc/httpd/conf.d/virtual.conf  

<VirtualHost *:80>
ServerAdmin root@dev.example.com
ServerName  www1.example.com
DocumentRoot /var/www/
Redirect  /  "https://www.ecollege.life"
</virtualhost>
<Directory "/var/www/">
AllowOverride none
Require all Granted
</Directory>
 

[root@dev ~]# vi /var/www/index.html

PORT BASED WEB HOSTING

 [root@dev ~]# vi  /etc/httpd/conf.d/port.conf  

<VirtualHost *:8999>
ServerAdmin root@dev.example.com
ServerName  www1.example.com
DocumentRoot /var/www/
</virtualhost>
<Directory "/var/www/">
AllowOverride none
Require all Granted
</Directory>

[root@dev ~]# vi /var/www/index.html  
[root@dev ~]# vi /etc/httpd/conf/httpd.conf  
Listen 8999
[root@dev ~]# semanage port -a -t http_port_t -p tcp 8999
[root@dev ~]# firewall-cmd --permanent --add-port=8999/tcp
success
[root@dev ~]# systemctl restart httpd
[root@dev ~]# firewall-cmd --complete-reload
[root@dev ~]# elinks www3.example.com:8999
[root@dev ~]#firewall-cmd --permanent --add-port=21/tcp 
[root@dev ~]#firewall-cmd --permanent --add-service=ftp
Restart firewall:
[root@dev ~]#firewall-cmd --reload
[root@dev ~]# netstat -tulpn | grep LISTEN

How to create LVM

Step1 :[root@dev ~]# fdisk /dev/sdb                                    ( Create partition)
Welcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them. Be careful before using the write command. 

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (4196352-16777215, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-16777215, default 16777215): +2G
Partition 2 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x13fe498e

 Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   83  Linux

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris          

Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x13fe498e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@dev ~]# partprobe
 

Step2 :- Phycial Volume Create 

[root@dev ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created.
[root@dev ~]# vgcreate /dev/sdb2 vg_web
  /dev/sdb2: already exists in filesystem
  Run `vgcreate --help' for more information.
 

Step 3: Create Volume Group

[root@dev ~]# vgcreate vg_web_group /dev/sdb2  

 Volume group "vg_web_group" successfully created
[root@dev ~]# vgs
  VG           #PV #LV #SN Attr   VSize   VFree
  centos         1   3   0 wz--n- <59.00g  4.00m
  vg_web_group   1   0   0 wz--n-  <2.00g <2.00g
Step 4 :- Logical Volume Create 

[root@dev ~]# lvcreate -L +500M -n web_lv vg_web_group
Logical volume "web_lv" created.

[root@dev ~]# lvs
  LV     VG           Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home   centos       -wi-ao----  18.08g                                                    
  root   centos       -wi-ao---- <37.04g                                                    
  swap   centos       -wi-ao----  <3.88g                                                    
  web_lv vg_web_group -wi-a----- 500.00m                                                    

Step 5: Format Logical Volume 

[root@dev ~]# mkfs.ext4 /dev/vg_web_group/web_lv
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=34078720
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
    8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

Step6:- Mount the Logical Volume
[root@dev ~]# mount /dev/vg_web_group/web_lv devops/
[root@dev ~]# cd devops/

[root@dev devops]# ls
lost+found
[root@dev devops]# touch file{1..10}
[root@dev devops]# ls
file1  file10  file2  file3  file4  file5  file6  file7  file8  file9  lost+found  

Final Step 7 : Check Mount point 

[root@dev devops]# lsblk
NAME                    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                       8:0    0   60G  0 disk
├─sda1                    8:1    0    1G  0 part /boot
└─sda2                    8:2    0   59G  0 part
  ├─centos-root         253:0    0   37G  0 lvm  /
  ├─centos-swap         253:1    0  3.9G  0 lvm  [SWAP]
  └─centos-home         253:2    0 18.1G  0 lvm  /home
sdb                       8:16   0    8G  0 disk
├─sdb1                    8:17   0    2G  0 part /root/linux
└─sdb2                    8:18   0    2G  0 part
  └─vg_web_group-web_lv 253:3    0  500M  0 lvm  /root/devops
sr0                      11:0    1 1024M  0 rom




Friday, January 1, 2021

How to Manage SELinux

  


SELinux?

Selinux is security it was developed by USA Army .Selinux is used for internal security  that mean It's maily  used to protect internal data not for external in system.
In real time SELinux is disabled and instead of this IP tables and Firewall are used. It protects all the services, files and directories by default if SELinux is enabled.

How many ways we can implement the SELinux?
We can implement the SELinux mainly in 2 modes.
(i)  Enabled
(ii) Disabled (default mode)

Enabled :
Enabled means enabling the SELinux policy and this mode of SELinux is divided into two parts.
(a)Enforcing
(b)Permissive
Disabled :
Disabled means disabling the SELinux policy.

Enforcing mode in SELinux:

It checks SELinux policy and stored a log. No can access the services by default but we can change the policy whenever we needed.

Permissive mode in SELinux

SELinux policy and stored the log. Anybody can access  services by default and you can  change the SELinux policy. It is also called as debugging  or troubleshooting mode.In this mode SELinux policies and rules are applied to subjects and objects but actions are not affected.

Disabled mode in SELinux

SELinux is turned off and no warning and log messages will be generated and stored.

The required files
It is main file for SELinux
              root@server~# vim /etc/selinux/config


It is a link file to the above file
    
    # vim /etc/sysconfig/selinux


SELinux log messages will be stored in this file.                                                                                       
                                                root@server~# vim /var/log/audit/audit.log


Command to see the SELinux mode?

                                            root@server~# getenforce
                                                                                      (to check the SELinux mode)
Set the SELinux mode temporarily?
                                            root@server~# setenforce 0 or 1
(To set the SELinux mode. Where ' 0 ' -----> permissive and ' 1 ' -----> Enforcing)
Note :
(i)You can  change the SELinux mode from Permissive to Enforcing or Enforcing to Permissive modes the system it is not required restart the system.

(ii) You can change Enforcing mode to Disabled mode or Disabled mode to Enforcing mode but It is required restart the system.

(iii) The above the using commands it is changed the SELinux mode temporarily only. You want to change permanently you have to open it.

                                  vim    /etc/selinux/config
Go to this line
                                  SELINUX=Enforcing or Permissive or Disabled
                                   
                                                        (save and exit this file)
root@server~# sestatus    (to see the SELinux policy details)

Other useful commands :

To see the SELinux context of the file
                                               root@server~# ls -ldZ

To see the SELinux context of the process running on the system

                                              root@server~# ps -efZ | grep http



To change SELinux context of the file or directory

                          root@server~# chcon -t public_content_t /public

To change the SELinux context of the /public  directory and its contents

                          root@server~# chcon -R public_content_t /public

To restore the previous SELinux context of the file/directory

                          root@server~# restorecon -v /public
 




Booting process and Kernel

 

Booting

Whenever we  power on the system and server. The system runs and check all self  hardware and software and detects all the connected input and out peripherals device. This process is called POST (Power On Self Test). If It is found any errors .It displays on the screen.Linux booting process is working How it is work at behind the process review by linux user .


 Booting process is done in 6 stages


BIOS :

BIOS stands for Basic Input and Output System. BIOS locates the booting disk in the system and it is locates disk and It is loads the Primary boot loader in disk .
Simply  the BIOS loads the MBR into memory and it is executes the MBR at disk.

MBR :

MBR stands for Master Boot Record. It is found in the 1st sector of the bootable disk (like that  /dev/hda or /dev/sda).
MBR is size 512 bytes and There is three components.
First part is Primary boot loader information and its size is 446 bytes.
Second part is Partition table information and its size is 64 bytes.
Third part is MBR validation check and its size is 2 bytes.

The primary boot loader contains the secondary boot loader we can say GRUB but GRUB or (LILO in old systems).Then primary boot loader find secondary bootloader and loads the secondary boot loader into memory.
So simple way  the MBR loads in secondary boot loader and It is executes the GRUB boot loader.

GRUB  :

GRUB stands for Grand Unified Boot loader It is used in Linux 7. LILO stands for Linux Loader and it is used in old Linux O.S(below 6.0). We have multiple kernel images installed in our O.S, we have option so we can execute as per your choose.
GRUB displays a splash screen, wait for few seconds. If we do not select anything, it loads the default kernel image in the grub configuration file.
GRUB has the information of the file system (but  old LILO didn't have information of file system ). GRUB configuration file is /boot/grub/grub.conf . This file have  kernel and initrd images. So, in simple terms GRUB just loads and executes kernel and initrd images.


init level :

Init program reads the /etc/inittab file and It is choose specified default run level from /etc/inittab file and put the into system .we can change the this default run level whenever we needed. We can find default run level by using command #cat /etc/inittab
Other command using.
# systemctl get-default

Now You want to change run level .
#systemctl set-default graphical.target
Temporary change
#init 3 (CLI RUN LEVEL) .

#init 5 (GUI RUN LEVEL)

The following run levels are vailable in Linux systems.

0 -----> halt or shutdown the system
1 -----> Single user mode
2 -----> Multi user without NFS
3 -----> Full multi user mode but no GUI and only CLI mode
4 -----> Unused
5 -----> Full multi user mode with GUI (X11 system)
6 -----> reboot the system


How to check the default run level in linux

To see the default run level in linux the command is
                       
                             root@server~#who –r


You want to changing the default run level to some  like 3

To change the run level edit the /etc/inittab and make the following changes
                  
Permanent Change
            
                             root@server~#vim /etc/inittab
go to last line change id:3
then reboot system:
                             root@server~#init 6

Temporary Change
                            root@server~#init 3

To see the details regarding the kernel installed

                              root@server~#uname –r

To see the same thing with more details use                             

                            root@server~#uname –a


To check the architecture of the O/S

                              root@server~#uname –m

To check the version of the O/S in the system

                      root@server~# cat /etc/redhat-release

The difference between # reboot and # init 6 commands .

Both commands are used to restart or reboot the system.

# reboot

Reboot command  do not send the kill signals to the system and it will kill all the running processes or services forcefully  then restart the linux system.

# init 6

Init 6 command  send the kill signals to the system and it will stop all the processes and services one by one and  restart the system.



Domain Name System (DNS)

 


              DNS (Domain Naming System)


                                                                 


DNS stands for Domain Naming System. Domain is human readable name .DNS automatically converts the names  into IP address .It is search Public IP address at internet and  send the request on root domain .Root domain is decided the which type request and domain like .com ,.edu .gov .net .

Example :- we type  domain name in our Web browser  it is fetch  to the IP addresses of Web  servers hosting those sites.


(i) Install the packages bind, caching-name
for RHEL - 6 &bind, cashing-name and unbound
for RHEL - 7.

# yum install bind* caching-name* -y
(to install the DNS packages for RHEL - 6)

# yum install bind* caching-name* unbound* -y

(to install the DNS packages for RHEL - 7)

(ii)Change the hostname by adding fully qualified domain name and make it permanent.

# hostname <fully qualified domain name>

(to change the hostname in RHEL - 6)

# hostname server9.example.com

(example for setting hostname temporarily in RHEL - 6)

# hostnamectl set <fully qualified domain name>

(to change the hostname in RHEL - 7)

# hostnamectl set server9.example.com

(example for setting hostname temporarily in RHEL - 7)

# vim /etc/hosts

(open this file and go to last line and type as below in RHEL - 6 only)
<IP address> <fully qualified domain name>
<hostname>  172.25.9.11
server9.example.com
server9
(for example of the above syntax)
# vim /etc/sysconfig/network
(open this file and go to last line and type as below in
RHEL - 6 only)
HOSTNAME=<fully qualified domain name>
HOSTNAME=server9.example.com
(for example of the above syntax)

(ii)Open the DNS main configuration file by

# vim /etc/named.conf command.

* Go to line number 11 and edit this line as below.

listen-on port 53 { 127.0.0.1; <server IP address>; };

Example : listen-on port 53 {127.0.0.1; 172.25.9.11; };
* Go to line number 17 and edit this line as below.allow-query
{ localhost; <Network ID>/<netmask>; };
Example : allow-query
{localhost; 172.25.9.0/24; };
(save and exit this file)

(iii) Open the DNS zone reference file by
# vim /etc/named.rfc1912.zones command
* Go to line number 19 and copy 5 lines and paste them at last of the file.
zone "<domain name>" IN {
type-master;
file "<forward lookup zone file name>";
allow-update { none; };
};

 

Example : zone "example.com" IN {
type-master;
file "named.forward";
allow-update { none; };
};
* Go to line number 31 and copy 5 lines and paste them at last of the file.
zone "<Three octets of the DNS server IP address> . in . addr . arpa" IN {
type-master;
file "<reverse lookup zone file name>";
allow-update { none; };
};
Example : zone "9.25.172 . in . addr . arpa" IN {
type-master;
file "named.reverse";
allow-update { none; };
};
(save and exit this file)

(iv) Copy /var/named/named.localhost file to /var/named/named.forward and edit as follows.
# cp -p /var/named/named.localhost /var/named/named.forward
# vim /var/named/named.forward
* Go to line number 2 and edit as follows.


Example : The line number 2 should be edited as follows.
@
IN SOA server9.example.com. root.example.com. {
The line number 8 should be edited as follows.
NS
server9.example.com.     A             172.25.9.11
server9.example.com.     IN    A     172.25.9.11
client9.example.com.      IN    A     172.25.9.10
client10.example.com.    IN    A     172.25.9.12
client11.example.com.    IN    A     172.25.9.13
www                                IN   CNAME   server9.example.com.
(save and  exit this file)

(v) Copy /var/named/named.empty file to /var/named/named.reverse and edit as follows.
# cp -p /var/named/named.empty /var/named/named.reverse
# vim /var/named/named.reverse


Example : The line number 2 should be edited as follows.
@
IN SOA server9.example.com. root.example.com. {
The line number 8 should be edited as follows.
                     

                               NS                        server9.example.com   

                               11        IN PTR    server9.example.com
                               10        IN PTR    client9.example.com
                               12        IN PTR    client10.example.com
                               13        IN PTR    client11.example.com
                        server9.example.com   IN A        172.25.9.11
                        www        IN    CNAME    server9.example.com
 

    (save and   exit this file)

(v) Check the DNS  configuration files for syntax errors.
# named-checkconf /etc/named.conf
# named-checkconf /etc/named.rfc1912.zones
# name-checkzone <domain name><forward lookup zone>
 

Example : # named-checkzone example.com /var/named/named.forward
 

# named-checkzone <domain name><reverse lookup zone>
 

Example : # named-checkzone example.com /var/named/named.reverse
 

(vii) Give full permissions to the forward and reverse lookup zones.
 

# chmod 777 /var/named/named.forward
# chmod 777 /var/named/named.reverse
 

(viii) Open /etc/sysconfig/network-scripts/ifcfg-eth0 and enter the DNS domain details if not present.
 

# vim /etc/sysconfig/network-scripts/ifcfg-eth0
(go to last line and type as follows)
DNS 1=example.com
(save and exit this file)

(ix) Add the DNS server IP address in /etc/resolve.conf
# vim /etc/resolve.conf

Example :
 search          example.com 

nameserver   172.25.9.11
(save and exit this file)
(x)
 

Restart the DNS server deamons.
 

# service named restart

(x) Restart the DNS server deamons.
# service named restart   (to restart the deamon in RHEL - 6)
# chkconfig named on    (to enable the deamon at next boot time in RHEL - 6)
 

# systemctl restart named unbound
(to restart the deamons in RHEL -7)
 

# systemctl enable named unbound   (to enable the deamons at next
boot time in RHEL -7)
 

(xi) Add the DNS service to the IP tables and Firewall.
 

# setup    (then select the Firewall configuration option and add DNS in RHEL - 6)
 

# service iptables restart       (to restart the IP tables in RHEL - 6)
 

# service iptables save   (to save the IP tables in RHEL -6)


# firewall-cmd --permanent --add-service=dns (to add the DNS service to firewall in RHEL - 7)
# firewall-cmd --complete-reload
(to reload the firewall in RHEL - 7)

Write the syntax for displaying the last 6 lines of a file data in Linux

 
tail command : we can pass the parameter .you want to how much line in retrieves data from file . 

Syntax : tail   -n  /var/log/messages

Display last 6 line in file :  

ex :  tail -n 6 /var/log/messages  

ex:  tail -n 6 auth.log




Create and Restore incremental backup in Linux using tar ?

 

Let's start .

Step 1:

saurabh@server:~$ mkdir linux_file_backup
saurabh@server:~$ cd linux_file_backup/
saurabh@server:~/linux_file_backup$ mkdir -p backup restore
saurabh@server:~/linux_file_backup$ ls
backup  restore
saurabh@server:~/linux_file_backup$ cd backup/
saurabh@server:~/linux_file_backup/backup$ touch file{1..5}
saurabh@server:~/linux_file_backup/backup$ ls
file1  file2  file3  file4  file5
saurabh@server:~/linux_file_backup/backup$

Step 2:

Create snapshot-file  :

  1. If you want to take incremental backup so we have to create snapshot file .
  2. It is used to incremental backup .
  3. If snapshot file exists , it's incremental backup otherwise it's a full backup.
  4. snapshot file is used to track what is changed ,It is keep record 

saurabh@server:~/linux_file_backup$ tar -czvg snapshot-file -f 1-backup.tar.gz backup/
tar: backup: Directory is new
backup/
backup/file1
backup/file2
backup/file3
backup/file4
backup/file5
saurabh@server:~/linux_file_backup$ ls
1-backup.tar.gz  backup  restore  snapshot-file

Step 3: Add new files and takes incremental backup 

saurabh@server:~/linux_file_backup/backup$ ls
file1  file2  file3  file4  file5
saurabh@server:~/linux_file_backup/backup$ touch file{6..10}
saurabh@server:~/linux_file_backup/backup$ ls
file1  file10  file2  file3  file4  file5  file6  file7  file8  file9

saurabh@server:~/linux_file_backup$ tar -czvg snapshot-file -f 2-backup.tar.gz backup/
backup/
backup/file10
backup/file6
backup/file7
backup/file8
backup/file9

Check out Backup only which file add after 1  incremental 

saurabh@server:~/linux_file_backup$ tar -tvf 1-backup.tar.gz
drwxrwxr-x saurabh/saurabh  36 2020-12-22 12:39 backup/
-rw-rw-r-- saurabh/saurabh   0 2020-12-22 12:39 backup/file1
-rw-rw-r-- saurabh/saurabh   0 2020-12-22 12:39 backup/file2
-rw-rw-r-- saurabh/saurabh   0 2020-12-22 12:39 backup/file3
-rw-rw-r-- saurabh/saurabh   0 2020-12-22 12:39 backup/file4
-rw-rw-r-- saurabh/saurabh   0 2020-12-22 12:39 backup/file5

saurabh@server:~/linux_file_backup$ tar -tvf 2-backup.tar.gz
drwxrwxr-x saurabh/saurabh  72 2020-12-23 18:03 backup/
-rw-rw-r-- saurabh/saurabh   0 2020-12-23 18:03 backup/file10
-rw-rw-r-- saurabh/saurabh   0 2020-12-23 18:03 backup/file6
-rw-rw-r-- saurabh/saurabh   0 2020-12-23 18:03 backup/file7
-rw-rw-r-- saurabh/saurabh   0 2020-12-23 18:03 backup/file8
-rw-rw-r-- saurabh/saurabh   0 2020-12-23 18:03 backup/file9

Restore incremental backup

saurabh@server:~/linux_file_backup$ ls
1-backup.tar.gz  2-backup.tar.gz  backup  restore  snapshot-file
saurabh@server:~/linux_file_backup$ tar -xvf 1-backup.tar.gz -C restore/
backup/
backup/file1
backup/file2
backup/file3
backup/file4
backup/file5 

saurabh@server:~/linux_file_backup/restore/backup$ ls
file1  file2  file3  file4  file5
saurabh@server:~/linux_file_backup/restore/backup$ cd ..
saurabh@server:~/linux_file_backup/restore$ cd .. saurabh@server:~/linux_file_backup$ tar -xvf 2-backup.tar.gz -C restore/
backup/
backup/file10
backup/file6
backup/file7
backup/file8
backup/file9





How to install and configure Samba share with windows and Linux (CentOs ,Redhat,Ubantu)

 

#Install and Configure Samba :

Find the package install or not

[root@-86 ~]# rpm -qa samba 

[root@-86 ~]# yum install samba samba-client samba-common

#Create Directory 

[root@-86 ~]#mkdir  /sharedata/

[root@-86 ~]#chmod /sharedata/

[root@-86 ~]#chcon -R  -t  samba_share_t  /sharedata/        (Set selinux )
[root@-86 ~]#setsebool -P samba_enable_home_dirs  on 
 

#Create user and set smb user password 

[root@-86 ~]#useradd  vmbackup

[root@-86 ~]#chcon -R -t samba_share_t /sharedata/
[root@-86 ~]#setsebool -P samba_enable_home_dirs on


[root@-86 ~]#smbpasswd -a vmbackup
[root@-86 ~]#groupadd smbgroup
[root@-86 ~]#usermod -G smbgroup vmbackup

#Configure smb.cnf  file

[root@-86 ~]#vim /etc/samba/smb.conf        (Go to last line past this line)

[WEB_BK]
comment=Shared Directory
browseable=yes
path=/sharedata
public=yes
writeable=yes
valid users=vmbackup
create mask=0770

#Set firewall 

[root@-86 ~]# firewall-cmd --add-service=samba --permanent
[root@-86 ~]#firewall-cmd --reload
 

#Restart samba sevices

[root@-86 ~]# systemctl restart smb
[root@-86 ~]# systemctl restart nmb
 

#Lets check  and Samba & Mount dir at client machine

[root@dev ~]# smbclient -L 192.168.105.86 -U vmbackup
Enter SAMBA\vmbackup's password:

    Sharename       Type      Comment
    ---------       ----      -------
    print$                  Disk      Printer Drivers
    sharedata           Disk      Shared Directory
    IPC$                    IPC       IPC Service (Samba 4.9.1)
    vmbackup           Disk      Home Directories
   Reconnecting with SMB1 for workgroup listing.

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------                      -------
    MYGROUP              48
    SAMBA                   VMS-86
    WORKGROUP        SERVER253
 

#Mount share directory 

[root@dev ~]# mount -t cifs -o username=vmbackup,password=redhat@123 //192.168.103.86/sharedata    dd/
[root@dev ~]# df -h
Filesystem                       Size  Used Avail Use% Mounted on
devtmpfs                         1.9G     0  1.9G   0% /dev
/dev/mapper/centos-home           19G   33M   19G   1% /home
/dev/sdb1                        2.0G  6.0M  1.8G   1% /root/linux
/dev/mapper/vg_web_group-web_lv  477M  2.3M  445M   1% /root/devops
//192.168.103.86/sharedata       5.0T   33M  5.0T   1% /root/dd


configure & install samba server & window