How to Configure RAID-1 in Redhat Linux

Configuring RAID-1(Mirroring)

RAID-1 Mirroring means having the same data on both the hard-disks,i.e exact clone of the same data copied on both the disks.

Minimum Requirements to configure RAID-1:

1.Minimum 2 Hard-disks required(You can also add more than two disks 4,6,8 for that the server should have the RAID Physical adapter installed)

Advantages of RAID-1

1. Read performance is better than writing data to the hard disk

2.If one disk fails there is no data loss since we have the same data on both the disks.

3.50% of space will be lost,i.e if we have two disks with 250GB size total, it will be 500GB but in mirroring it will show only 250GB.

Configure RAID-1

Step:1 Check the drives whether there is already RAID configured by using the below command

#mdadm  -E  /dev/[b-c]

As you can see from the above output there is no RAID superblock detected i.e no RAID defined yet

Step:2 Partition Drive for RAID

As I have mentioned already minimum 2 harddisks required to configure RAID-1, I have attached two disks /dev/sdb,/dev/sdc for configuring RAID-1, Let us create partitions on these two hard disks and change the pariton type to RAID while creation.

Procedure to create RAID type partitions on the drives

1. Choose ‘n’ to create a new partition

2. Then choose ‘p’ for a primary partition

3. Now select the partition number ‘1’

4. Give the default full size and then press enter

5. Now press ‘p’ to check the mentioned partition

6.Press “L” to list all the available partition types

7.Type ‘t‘ to choose the partition

8. Now choose ‘fd’ for the Linux RAID and press enter

9.choose ‘p’ once again to confirm the changes we made

10.type ‘w’ to save the changes

Step:3

#fdisk /dev/sdb

 

Follow the same above  procedure to create the partition on /dev/sdc drive

Step:4

#fdisk /dev/sdc

Step:5

We have successfully created the partitions on both the drives, verify the changes on both the drives /dev/sdb & /dev/sdc  using the following command

#mdadm  -E /dev/sd[b-c]

From the above output, you will see no md superblock detected because there is no RAID defined on /dev/sdb1 and /dev/sdc1.

Step:4 Configure RAID device  /dev/md0  using the following syntax

#mdadm   --create   /dev/md0   --leve=raid1 --raid-devices=2  /dev/sdb  /dev/sdc

After executing the above command, check the RAID-1 status by using the below syntax

#cat  /proc/mdstat

 

Step:7 Check the RAID Array and device types by using the following command

#mdadm  -E /dev/sd[b-c]

#mdadm  --detail   /dev/md0

From the above output, RAID devices successfully created by using the /dev/sdb and /dev/sdb drives

Step:8 Creating a file system on RAID devices

#mkfs  /dev/md0

Step:9 Mount the file system to some mount point directory

#mkdir  /RAID

#mount  /dev/md0    /RAID

To check the mounted filesystem status

#df -h

From the above output, the RAID devices successfully mounted under the RAID directory.

If you found this article useful, Kindly Subscribe here 👉  Click this link to Subscribe

Never miss an article Do like my official  FB page 👉 Learn Linux in an easier way

##############################################################################################

 

 

Learn Solaris OS Device Naming conventions

In Solaris operating systems all the devices are identified with the three different names, Let us see what all are the  types of names available

1.Logical device name or Block disk devices

2.Physical device name or Character disk devices.

3.Instance name

Logical Device Name:

A user can access the hardware or device with this logical names, after login to the operating system if a user needs to access the system devices he/she has to access  the device with the logical name.So a logical device name is used to refer to a device when you are entering the commands on the command line

All Logical device names are kept in the directory path /dev and these logical device names are symbolically linked to the physical device names under the path /devices directory.So all the devices have an entry inside the /dev/dsk (logical device name path)and /dev/rdsk (physical device name path).

rdsk means RAW DISK

The logical device name contains the controller number, target number, disk number and slice number i.e c#t#d#s#

To check all the logical device names run the following command

# ls /dev/dsk
c0t0d0s0 c0t0d0s4 c0t2d0s0 c0t2d0s4 c1t1d0s0 c1t1d0s4
c0t0d0s1 c0t0d0s5 c0t2d0s1 c0t2d0s5 c1t1d0s1 c1t1d0s5
c0t0d0s2 c0t0d0s6 c0t2d0s2 c0t2d0s6 c1t1d0s2 c1t1d0s6
c0t0d0s3 c0t0d0s7 c0t2d0s3 c0t2d0s7 c1t1d0s3 c1t1d0s7

c0t0d0s0 to c0t0d0s7  = Represent the device name for the disk slice0 to slice 7 for a disk that is attached to the controller 0 at target 0, on disk unit 0.

c0t2d0s0 to c0t2d0s7 = Represent the device name for the disk slice0 to slice 7 for a disk that is attached to the controller 0 at target 2, on disk unit 0.

c1t1d0s0 to c1t1d0s7 = Represent the device name for the disk slice0 to slice 7 for a disk that is attached to the controller 1 at target 1, on disk unit 0.

Note: On X86 hardware you will not find target, target shows only on SPARC hardware.

Physical Device Names:

The physical device name is nothing but it has the device hardware location i.e the complete PCI address of a device, the physical addresses contain the series of nodes which is separated by slashes, that indicates the path to the devices.All the physical devie names are kept under the /devices directory.

To check all the physical device name details

#ls  -l  /dev/rdsk

To list a individual disk hardware path details

#ls -l /dev/dsk/c0d0s0

Note: Am running the Solaris server fromX86 hardware that is why from the above output it is not showing the target id.

3.Instance Names:

Kernel will assign a shorten name for all the available devices  that are connected to the server that is called as an instance name or we can say like it is a shortened name for the physical device name

Let me show you this with one example:

1.sdn = which means here sd is the disk name and n is the number, such as sd0 for the first SCSI disk  device

2.dadn = which means here dad is the disk name and n is the number, such as dad0 for the first IDE disk  device

for example run the ls -l  /dev/rdsk command to get the physical path details from that output you can find the instance name as below

 

As you can see from the above screenshot sd shows it is an SCSCI disk and the disk number is 0.

How to List the system devie details?

In solaris operating system there are several ways avaiable to list the device physical path information.Let us see that one by one

1./etc/path_to_inst_file

As I explained above the instance name for the devices, For each and every devices the  system stores its physical name and instance name inside the /etc/path_to_inst file.These names are used by the kernel to identify the devices.This file is maintained by the kernel and it is not recommed to edit this file for any purpose

Let me show the entires inside the /etc/path_to_inst file below

Note: Different system have different physical device paths

The following is  a /etc/path_to_inst file from a system that has a diffrent bus architecture, here in this case it is an example of an system that has  onboard sun system bus(SBus)

# cat /etc/path_to_inst
#
# Caution! This file contains critical kernel state
#
“/sbus@1f,0” 0 “sbus”
“/sbus@1f,0/espdma@e,8400000” 0 “dma”
“/sbus@1f,0/espdma@e,8400000/esp@e,8800000” 0 “esp”
“/sbus@1f,0/espdma@e,8400000/esp@e,8800000/sd@3,0” 3 “sd”
“/sbus@1f,0/espdma@e,8400000/esp@e,8800000/sd@2,0” 2 “sd”
“/sbus@1f,0/espdma@e,8400000/esp@e,8800000/sd@1,0” 1 “sd”
“/sbus@1f,0/espdma@e,8400000/esp@e,8800000/sd@0,0” 0 “sd”
“/sbus@1f,0/espdma@e,8400000/esp@e,8800000/sd@6,0” 6 “sd”
“/sbus@1f,0/espdma@e,8400000/esp@e,8800000/sd@5,0” 5 “sd”

2. The prtconf command

prtconf means Print configuration  to get all the system configuration details like Total memory installed, configuration of the peripheral  which is formatted as device tree.The main adavantage of prtconf is it will display all possible instances of devices, wherether the device is attached to the system or not.

#prtconf

This command display all possible instances of devices, wherether the device is attached to the system or not.

If you dont want to see the devices which are not attached you can use the option -v with the prtconf command.

#prtconf   |grep  -v not

 

3.With “format” command

By using the format command you can get the physical name as well the logical names of the disks that are connected to your server and also you can check how many harddisk connected to the server by using this command (In Linux we use fdisk command to list all the disk details the same like here in solaris we use the format command)

#format

Note: Press Control+d to exit  the format command without selecting the disk.

 

If you found this article useful, Kindly Subscribe here  👉🏿 Click this link to Subscribe
Never miss an article Do like my official  FB page 👉🏿Learn Linux in an easier way

Understanding SSH and SCP Protocols in Linux Operating System

What is SSH?

SSH is a Secure Shell protocol that lets you to open the remote terminal or shell session on any Unix based server where according to the permission available to the account you logged in to and execute commands.The primary advantage of ssh over other protocols including telnet is that everything you do during the session  will be encrypted so that anyone who might be watching at any point between you and  remote host will see only the unreadable text

Note: SSH stands for Secure Shell.All SSH session is encrypted and it requires authentication.It provides a very safe and secure way of exchanging the commands, configuring the services over remotely.Another important point is when you connect to the remote server using ssh you log in using an account that exists on the remote server.

Note: The port number for SSH protocol is 22

An Overview of how SSH works?

1.When an administrator connects to the remote server using SSH he will be dropped in to a shell session (usually bash), where you can execute commands, it will allow you to use only text-based  interface, whatever command you execute in to your local terminal are sent through an SSH tunnel (with encryption)and then it executed on your server

2.The SSH connection is purely based on the client-server model this means for an SSH connection to be established, the remote server must be active with the ssh daemon(sshd).This daemon will listen for the connections on the specific port(ssh), it authenticates the connection request and allows the connection if the user provides the correct credential details.

3.The client system must have an SSH client software and this software knows how to communicate with the SSH protocol, provides information about the remote host, username to use, credentials that need to passed to authenticate and many more.

How does SSH Authenticate users?

1.Most clients use to authenticate by using the password which is very less secured and not recommended to use, use the SSH keys which is a very secure way to connect.

2.SSH keys are sets of cryptographic keys which can be used for the authentication.Each set contains Public key and Private key.

Public Key: It is made available to everyone, it can be shared with anyone without concern.

Private Key: It must remain confidential to its respective owner

Note: Whatever is encrypted with a public key only be decrypted by its corresponding private keys.

Let me tell you how ssh key-based authentication works at the backend,

If you want to authenticate using SSH keys, the user should have an SSH key pair on their local system, now on the remote server, the public key must be copied to the file within the user’s home directory at ~/.ssh/authorzied_keys.This file contains a list of public keys, one per line, that are authorized to log in to this account.

Now when a user connect to a host, wishing to use the SSH key-based authentication, it will inform the server of this request and tell the server which public key to use,then the server checks its authorized_keys file for the public key,generate a random string and encrypts it using the public key,this encrypted message can be only decrypted with the associated private key.The server then will send this encrypted message to the user to test whether they actually have the associated private key.

Upon receipt of this message, the client will decrypt it using the private key, it then compares both the values if both the values are same then it allows the connection.This is how  SSH key based authentication works.

Now let us see how to connect to the remote server with SSH protocol

Ex:1 Connect to remote server  from local server:

The basic syntax to for this as follows,

#ssh <remote server ip address or host name>

In this example, I use my two  Linux servers for the demonstrations.

Server details:

Server1 IP address:10.250.1.50/linuxvasanth.com-Located at USA

Server2 IP address:10.250.1.100/productionclient-Located at LONDON

Let us see how to connect to server2 from server1.

linuxvasanth.com #ssh   10.250.1.100

If this is the first time you use the SSH you will see the below messages on your terminal

 

After giving Yes this will add your server to your list of known hosts(~/.ssh/known_hosts)

Each and every server will have a host key and the above confirmation question is related to verify and save the host key, Now next time when you connect to the server, it can easily verify that it is a trusted known server.After the server authentication is successfully finished it asks for a password.

Note: By default, SSH allows the direct root login, so here you have to give the root user password of the remote server(i.e 10.250.1.100 ip root user)

Now you can execute any commands, can configure services and many more.Here, for example, my task is to create a user account and password on remote server

The above output says the account has been created successfully on the remote server.

Once you have done with your task with the remote server you can leave the session or disconnect by using the exit command

To exit the connection

A

As you can see from the above output after executing “exit” command the remote server login session gets disconnected and your terminal now changes it to your local server session.

Ex 2: How can I log in as a normal user to a remote server?

In our first example I have explained how to login to remote server as a root user, As you know by default SSH allows the direct root login to remote server, in case if you want to connect to the remote server with non-root user run the following syntax

Note: Check the non-root user account exists or not on the remote server before you start.

Syntax:

linuxvasanth.com #ssh non-rootuser@remoteserverip
linuxvasanth.com #ssh john@10.250.1.100

After giving john user password you will connect it to the remote server terminal session as follows

Now if you want to gain root access you can use the switch user command “su” to switch to multiple user accounts as follows

Now to disconnect the session first you need to log out from the accounts you have connected as follows

How to change the default SSH Port number?

To protect your server from anonymous attack changing the default port number to another any unused port number would help .all users with Linux servers can change the SSH port number from SSH configuration file(the default port number for SSH is 22).

The configuration file for SSH is /etc/ssh/sshd_config

All you need to do is edit this sshd _config file, open the file with your preferred editor, before that it is always good to take a backup of the original file before you made any changes in it.

#cp  /etc/ssh/sshd_config    /etc/sshd_config.original

Open the file with the vi editor

#vi   /etc/ssh/sshd_config

# $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options change a
# default value.

#Port 22 -->default port number used for SSH now change this to your prefered port number
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
"/etc/ssh/sshd_config" 137L, 3848C

From the above file the line #port 22 here the # means it tells the server to ignore anything after it on the same line, now we will need to remove that character and put your preferred new port number.

Note: Make sure you are not using the port number which is already in use.If you are unsure check this TCP/IP and UDP Port numbers and its uses

Try to use the port number which is not listed in the above link, here I use 2222 port number.

Note: In firewall also you will need to change SSH port number to the new one.

Now restart the SSH service as follows

After making any changes in the default configuration file you will need to restart the respective service to make the changes come in to effect.here we have to restart the ssh service

#service sshd restart

From now onwards SSH will listen to the port number you have specified.

Understanding SCP Protocol in Unix/Linux operating system:

Scp stands for Secure Copy used to send files from Local server to remote server(Uploading) and copying files from remote server to local server(uploading) with securely, secured means all the data while transferring through the network  is encrypted.

SCP is installed by default on all Linux distributions as a part of OpenSSH package

Note: SSH is used to connect to the remote server with text-based interface

SCP- used to transfer files between the different servers

Scp it uses the  SSH port number 22 to establish the connectivity between the server

Ex:1 How to transfer  a file from Local server to remote server

For this example, the syntax would look like this

#scp  <FILE TO BE TRANSFER FROM LOCAL SERVER>  <USERNAME@REMOTESERVER IP ADDRESS>  :<DESTINATION PATH REMOTE SERVER>

Server1:10.250.1.50(Local server)

Server2:10.250.1.100(Remote server)

Now  am going to transfer a file from local server to remote server

#scp  /documents root@10.250.1.100:/tmp

Note:/documents is the local server file to be transfer

/tmp is the remote server destination directory path

Once the authentication is successful the file will transfer to the remote server destination path, you will see the percentage as 100 which indicates the entire data has been successfully transferred to the remote server.

Now to verify go to the remote server (10.250.1.100) /tmp directory and list whether the file /docments is successfully saved.

#cd  /tmp

#ls -t

Note: -t option is to list the latest modified or create file to display  in the first

The above screenshot has confirmed the file has been successfully saved under /tmp directory of the remote server.

Ex:2 How to transfer a directory and all its contents from local server to the remote server?

To copy the entire directory we need to use the option -r  with the scp command i.e recursive which will select the entire directory contents.

Syntax:

#scp  -v  -r  <Local server dir>   <user@remote server ip>:<remote server destination dir path>

you can also use the -v verbose option to view the detail output on your screen.

From Server1 (10.250.1.50) am going to transfer /mydatabase directory to the remote server /myfolder path

As you can see from the above output mydatabase directory is have some files and subdirectories.

#scp   /mydatabase root@10.250.1.100:/myfolder

Note: If you forget to mention -r option while transferring the entire directory you will get the error message it is not a regular file, check the above screenshot.

Always use  -r while transferring the entire directory to the remote server.

After giving the correct password scp will transfer the /mydatabase directory to the remote server directory /myfolder

Now go to the remote server /myfolder path and confirm whether the directory /mydatabase is successfully transferred.

#cd  /myfolder

#ls

AS YOU CAN SEE FROM THE ABOVE OUTPUT THE ENTIRE DIRECTORY ALL ITS CONTENTS FROM THE LOCAL SERVER /MYDATABASE  WAS SUCCESSFULLY TRANSFERRED TO /MYFOLDER PATH.

 

Note: To copy the files from remote server to the local server path you would use the same syntax in reverse as follows
#scp  username@remoteserverip:<remote serverfile>   <local server path>

I hope now you have understood the SSH and SCP protocols their uses in production environment

Never miss an article from this blog, Kindly do like my FB page Learn Linux in a easier way
If you found this article useful, Kindly Subscribe here 👉👉🏿Click this link to Subscribe

Understanding Remote sync(rsync) in RHEL

Introduction:

Rsync(Remote Synchronization) program is used to transfer and sync the files between the servers.rsync is very fast and secure way to transfer and sync the files.You can also use the Rsync command to copy and synchronize your data remotely and locally across the directories, disks, networks, to perform backup and mirroring between two Linux servers.
It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied.

Advantages of rsync:
1.It efficiently syncs and copies files to/from the servers.
2.It is much faster than the SCP(secure protocol) to transfer the files between the servers.
3.rsync it consumes very less bandwidth as it uses compression and decompression method to transfer the files from/to the servers.
Points to  remember:
1.When you are using the rsync command to copy/sync the data between the server for the first time ,it copies the whole content from the source file and pastes it in the destination file.
2.Next time when you run the rsync command it copies/sync only the updated bytes from the source file and paste it in the destination file.(coz of this rsync consumes less bandwidth while transferring data)
3.rsync uses delta-transfer algorithm, which maximum reduces the amount of data sent over the network by sending only the differences between source files and existing files in the destination.
Note1: This utility(rsync) is mostly used for backup and mirroring and as an improved copy command for everyday use.
Note 2: rsync finds the files that need to be transferred by using the quick-check algorithm that looks for files that have changed in size or in last modified time.Any changes in the other preserved attributes (as requested by options) are made on the destination file directly when the quick check indicates that the file’s data doesn’t need to be updated.
Syntax to run the rsync command:
#rsync   <options>   <source >      <destination >
Options available with rsync command:
-v = Verbose output
-r = Copies the data recursively(it will not preserve the timestamp and permission while transferring data)
-a = Archive mode(In this mode it allows copying the data recursively and it also preserve symbolic links, file permission, timestamp, user and group ownership)
-z = Compress file data
-h = Human readable format(display the size in MB,GB,kb format)
Before you start using the rsync utility you need to check whether rsync package is already installed on your server as follows,
#rpm  -qa rsync

The above output says the rsync package is installed already, so no need to install the package again.(Do this check on both the servers)
EX:1 To Copy/Sync Files and Directory Locally
In this example, we will sync a file on a local machine from one path to another path, Here we have a file  /mywhatsapp.txt needs to be copied/synced  to /var/mybackup  file

Syntax:

#rsync   <option>  <source>  <destination>
#rsync    -zvh   /mywhatsapp.txt   /var/mybackup

 

In the above example, the destination file mybackup is not already existed,rsync will create the destination file if it does not exist already.
Let us check whether the contents of the /mywhatsapp.txt is properly synced to the /var/mybackup file

The above screenshot has confirmed Everything is successfully synced to the destination without any data loss.
Note: As I said already in the beginning when you are running rsync for the first time it copies the entire content from the source file and paste it in the destination by default,After appending some more bytes to the source file,,again run the same command this time it transfers only the  updated bytes from the source to destination.
Now let us add some more bytes to the source file (in our case /whatsapp.txt is the source file)
#cat >>/whatsapp.txt

This is my second line

Control + d to save

Now run the  rsync command again,
#rsync -zvh   /whatsapp.txt    /var/mybackup

As you can see from the above screenshot rsync this time it transfers only the updated bytes to the destination.
Ex:2 Copy/Sync files/Directory from Local server to Remote Server
In this example, we will see how to sync data from local server to remote server.I have a directory on my local server with the name “Softwares” which contains rpm packages and you want that local server directory contents to be sync to a remote server.

Syntax:

#rsync <option> <Local serverfile path>  user@ipaddrofremoteserver:<remote server destinationpath>
Note: Remember to the sync files within your local system we use different syntax and for remote sync, we use the above syntax.

Server Details:

On server1: /Softwares (Source directory)

IP address:10.250.1.16
On server2: /tmp/mydatabase (destination file)

IP address:10.250.1.15
From 10.250.1.16 run the following command to sync:
Before I sync the data’s from /Softwares directory Let me check the total size of the directory by using the following command
#du -sh /Softwares

So the total data to be sync to the remote path is 3.3GB
#rsync  -avzh  /Softwares root@10.250.1.15:/tmp/mydatabase

As you can see from the above screenshot after authentication the files from the Softwares directory started syncing to the /tmp/mydatabase file.
Ex:3 Copy/Sync a Remote Directory to a Local server
In this example, we will see how to copy/sync a remote directory to local directory.Here we have a directory under /var/log/student which is on a remote server is being copied to your Local server under /tmp/serverdata

Syntax:

#rsync  <option> user@remoteserverip:<Remote server path>   <Local server path>
Note: The syntax will change always the way we use the rsync command.
On server1(10.250.1.16) run the following command:
#rsync   -avzh   root@10.250.1.15:/var/log/student   /tmp/serverdata

Now go to the local server path /tmp/serverdata and check whether the remote server directory “student” synced without any error.
On server 10.250.1.16 run the below command to confirm:
#cd /tmp/serverdata

#ls

As you can see from the above output the directory successfully synced to the local server path /tmp/serverdata.
Tips: The rsync utility by default it uses the  SSH port number 22  to sync the files over the local server to remote server.
Never miss any article from this blog ,Kindly do like my FB page   My FB official Linux Page

If you found this article useful, Kindly Subscribe here 👉👉🏿Click this link to Subscribe

*********************************************************************************************************************************

 

How to configure IP address in RHEL server?

Introduction

In this article we are going to cover how to configure the IP address and what all are the initial checks up we need to perform before you configure the IP address.

Every system in a network needs an IP address to communicate with another system, it can be easily configured in RHEL with the help of “ifconfig” command.

Types if IP:

IP address can be configured in two ways

1)Static IP

2)Dynamic IP

Static IP:

The IP can be configured manually by the system administrator or by individuals.Static IP mostly use with the devices like router, printer etc…

Dynamic IP:

In this method, the IP address is automatically configured from the DHCP server, when you set the IP should configure automatically in the network management tool then the system will call the DHCP server for the IP address, DHCP service provides the IP address to the system when it joins the network.

Procedure to configure the IP address:

1)Check how many adapters available and its status from your server

2)Choose the adapter to which you are going to configure

3)Deactivate the network adapter before you assign IP address

4)Configure the IP with the help of “ifconfig” command

5)Make the assigned IP address permanent with the help of “setup” command.

6)After assigned the IP address permanently to the network management file activate the network adapter.

Configure the IP address:

Method: Static IP

To check the network adapter status:
#ifconfig

from the above output, we have only one adapter connected to the server and the logical name for the network adapter is “eth0”, the current IP address for the adapter is 10.0.2.15 and the adapter is in running state.

eth0 –>eth indicates the adapter manufacturer name and “0” indicates the first adapter .if  the server is having two network adapter means it would display as eth1.

Note: You don’t have to worry about the  adapter names and numbers since the kernel device driver will generate all these by default.

To deactivate the network adapater:

syntax:

#ifdown   <Network adapatername>
#ifdown   eth0

Now check the network adapter status whether it is successfully deactivated or not

#ifconfig

From the output, eth0 adapter has been turned in to deactivated mode successfully

Now let us configure the IP address to the eth0 adapter by  using the following command:

syntax:

#ifconfig   <Network adapter>  <ipaddress>
#ifconfig  eth0   10.250.1.50

Check whether the IP is assigned to the eth0 adapter

#ifconfig  eth0

from the output, you could see the IP 10.250.1.50 has been successfully assigned

Note: Now if you deactivate the adapter , next time when you bring it back to the activate state, the IP will get assigned from the DHCP service.This is the default mode in RHEL.Below is the screenshot how the IP get assigned automatically after deactivate and activate the eth0 adapter👇👇

Now its time to make this ip address permanent by using the following command
#setup

From this tool choose the network configuration

Now choose edit devices

Choose the eth0 device from the option

Now check the default setting for the network adapter devices

From the above screenshot, you could find the default mode to configure the IP is in DHCP always.

Now Unselect the DHCP mode and add your static IP here to make it permanent one

Note: Use spacebar from your keyboard to deselect the DHCP

We have now successfully added the static IP 10.250.1.50 to the adapter eth0.

That’s it…Now save the information and exit the network management tool

 

Now activate the network adapater:

syntax:

#ifup  <network adapater>
#ifup  eth0

So from now onwards 10.250.1.50 is the default IP address for your server , even after restart , deactivate and activate the adapter this IP would be the permanent one.

#ifconfig eth0

From the above output, the IP has been permanently activated with the static method.

Note:

If you forget to add the IP address in the network management with the “setup” command then the assigned IP would be a temporary one,if you do a restart or deactivate and activate the adapter it will assign the IP from the DHCP server since in RHEL the default mode after restart or activate the network adapter will be in Dynamic IP mode.

Tips and tricks:

*If you are facing issues while you bringing up your network adapter or assigning the IP address just try to restart the network management service

#service NetworkManagement restart

The above command will do a refresh on all the network adapter configuration files and then try to configure or activate the adapter.

I hope you have enjoyed this article, in our next tutorial I will explain you the troubleshooting concepts in IP configuration.

Never miss any article from this blog ,Kindly do like my FB page 👉👉  Learn Linux in a easier way

*************************************************************************************************************************************

If you found this article useful, Kindly Subscribe here 👉🏿👉🏿Subscribe here

Visit and Subscribe My Youtube Channel for More Videos  https://youtu.be/6vYQYY_zL0o

 

 

 

How to Configure “SUDO” access for users in Linux?

SUDO stands for (Super User Do) when a normal user needs a root user privileges he can attain that functionality by the SUDO mechanism.SUDO is the good way to get the root privileages,In another way we know to access the root privileages by using the su(switch user) command, here you need the root user password to get the access, sharing the root user password to others  is not safe always,after login you will get the prompt # which says you are logged in as a root user, if you enter any dangerous command then the server will have to face  the critical issues, you can erase the entire hardisk, you can change the default parition layout information and many more which leads to  so many problems.

But when we give the root privileges via sudo the user has to run the admin commands with sudo permission only, The user has to run the command with the sudo permission as follows #sudo <full path of the command to be run>, this works in a safe way.

Sudo configuration file:
file path=/etc/sudoers

Once you have decided to give the root privileges to non-root users, you will have to configure their names inside this file with the permission you allowed(full permission or partial access).So whenever the user runs any admin commands the sudo command will check the username inside this file, if the name exists then the user authentication is success he is allowed now to execute the commands.In this way, only the sudo mechanism works.

If you remove the user from this file then the user will not have the root privileges, he cant access the root privileges via sudo.Now let us configure the sudo access for a user.

Ex:1 How to Configure Sudo access(Full privileges) for a user:

Open the file with your preferred editor, I always use the vi to edit the files.we can also open this id configuration file by using the command “visudo”

#vi  /etc/sudoers

<add the username to whom you are going to give sudo access>

below the ROOT user add the non-root user privileges

vasanth ALL=(ALL) ALL means full privileges(user can execute all the admin commands)

Now we have successfully added a user john inside the sudo configuration file.Let us see how the user gains the root privileges.

Note: Vasanth should have the valid password before he executes the commands via sudo.

Now let us log in as a Vasanth and perform the admin command

#su  – Vasanth

$pwd

$reboot
Sample output:: Must be Superuser

Run the command  via sudo

$sudo  /sbin/fdisk -l

Note: Always mention the full path of the command else you will get error message command not found as users are accessing the commands via sudo temporary.(Bash will not read the full path of the command automatically from $PATH unless you are a root user)

after executing it will ask the john password for authentication, once you have submitted the password it will check the username inside the sudoers file and if the user matches then it allows running the command.

From the above output, the user Vasanth gain the root privileges via sudo successfully.

Ex:2 Give access to no-root user to run certain commands via sudo

In our previous example, we gave the full privileges to run the admin commands, in this example, the non-root user is allowed to run only the certain commands which are defined in the sudoers file, let us see how to do this.

#vi /etc/sudoers

<add the username and mention the command full path the user is allowed to sun>

So from now onwards the user Vasanth is allowed to run the only fdisk and partprobe command via sudo, if he tries to run some other command via sudo  it will not allow to run, let us see  this with practical  below,

#su – Vasanth
$sudo reboot

here you will get the permission denied or command not found messages

$sudo /sbin/fdisk -l

$sudo /sbin/partprobe

As you can see from the above output the user Vasanth  is only allowed to run two commands via sudo ,

if the user Vasanth  try to run any other commands with sudo he will get permission deny or command not found WARNING message

from the above output, the user Vasanth tried to run reboot command via sudo which is not added inside the sudoers file to Vasanth so he received a  warning message.

Ex:3 How to allow a user to run the command without providing his password.

In our last two examples every time the user runs the command via sudo it will prompt the user to enter his/her password to verify the user in sudoers and in /etc/shadow file.

If you want the user to run the command via sudo without supplying the password we need to put additional entries inside the sudoers file, let me show you how to configure this.

#visudo

vasanth ALL=(ALL) NOPASSWD: <FULL PATH  TO COMMAND>

save and exit

Now  ask the non-root user to check:

su –  nirmal
$sudo /sbin/fdisk  -l

As you can see from the above output it is not prompting the user to enter his password, without providing the password the command executed.

Note: Everytime you run the command via sudo permission you should give the full path of the command which is how it provided inside the sudoers file, without the full path you will get the command not found error message.

***************************************************************************************************************************************

I hope you have enjoyed this article.If you found this article useful, Please do subscribe  here Subscribe here

 

 

How to delete the Partition in RHEL

 Delete the partition:


In our previous tutorials, we have seen the concepts of  Linux disk management and creating the partitions, MBR, GPT partitions schemes, Now we are going to learn how to delete the partition permanently.

Whatever the task we do in Linux there are some procedures available for each and every task that we must have to follow in order to avoid the critical errors.

Procedures to delete the partition:


1.Check the hard disk  partition details

2.Check the filesystem is in active state  or in inactive state (i.e mounted state or unmounted state)

3.Unmount the mounted filesystem.

4.Verify whether it is unmounted properly

45Using the “fdisk “command to delete the partition

6.Save the changes and confirm it by using the fdisk command

Step:1 Check the  harddisk partition details


#fdisk  -l

From the above screenshot, the disk /dev/sdb is having two paritions, we will select the second partition(/dev/sdb2/) here to delete.

Step:2 Check the filesystem is in mounted state  or in unmounted state


#df  -h

The above screenshot says the partition /dev/sdb2 is in mounted state, so now we have to make this in to unmounted state(i.e inactive)

Step:3 Unmount the mounted filesystem


Syntax: To unmount a filesystem

#umount   <filesystem>

or

#umount  <mount point directory>

#umount   /dev/sdb2

or you can use the mount point directory to unmount (I have displayed both the ways to unmount, you can either use the mount point directory or use the filesystem name)

Step:4 Verify whether it is unmounted properly


#df  -h

From the above output, we have confirmed the /dev/sdb2 partition is in inactive state

Step:5  Using the fdisk command delete the partition


#fdisk   /dev/sdb

From the above screenshot, we have successfully deleted the partition /dev/sdb2

Step:6 Confirm it by using the “fdisk” command


#fdisk  -l

Now the partition /dev/sdb2 successfully remove from the hard disk

Note: If you forget to save the partition changes by pressing “w” then it won’t save the changes to the kernel memory when you run “fdisk -l you will see only the previous partition layout information.So always make sure you have saved the partition table changes to the kernel memory by pressing “w” before you exit from the fdisk program.

I hope now you have understood the Linux disk management concepts…if you have any queries feel free to leave a comment….. 

 

If you found this article useful, Kindly Subscribe 👉🏿👉🏿Click this link to Subscribe 

 

 

How to create a Partition in Linux

Understanding Linux Disk Management


Before we start creating the partitions it’s very important to know the basis of the disk management, So let us first learn the basic concepts of the Linux disk management.

The disk management Includes  Adding the disk, Removing a disk from the storage, creating partitions and mounting the partitions to the directory structure

1.BIOS(Basic Input and Output System)

2UEFI(Unified Extensible Firmware Interface)

3.File system type

4.MBR (Master Boot Recorder)

5.Primary Partition

6.Extended  Partition

BIOS/UEFI:

a)This is the first program that starts when you power on your system(based upon the operating system either BIOS/UEFI it starts)

b)The main task for the BIOS/UEFI is to perform the hardware test on your system,This will check each and every hardware devices that are associated with your system,if it found no error then it will search  and run the next process(i.e starting the boot loader program)This test is called as Power on Self-Test(POST).

Let me show you some of the important difference between BIOS and UEFI

BIOS(Basic Input and Output System)

1.Very old method to connect and detect the hardware in the system.

2.It doesn’t provide us any Troubleshooting options.

3.It runs in 16-bit processor mode &4.It has only 1MB of space

4.It supports only MBR partition.

5.It doesn’t have drivers for the latest network cards and other storage devices.

6.Settings are saved in Non-Volatile CMOS memory

UEFI(Unified Extensible Firmware Interface)

1.It came as a replacement of BIOS

2.It has very advanced options for troubleshooting such as emergency mode, remote diagnosis, internet connectivity and backup.

3.It can run in 32-bit or 64-bit mode

4.It supports MBR and GPT partition

5.It can detect and support all the latest modern devices.

6.All settings are saved in Flash memory

Now let us see  what is MBR partition and GPT Partition

MBR(Master boot recorder) Partition :

1.It stores in the 1st sector of the hard disk, it contains the information that is necessary to boot the systems, Inside MBR the bootloader program resides.

2.Bootloader contains only the partition layout pieces of information and how many harddisks connected, it doesn’t know anything about the operating system filesystems.

3.The default size of the sector is only 512 bytes and from these only 64 bytes are taken to save the partition table pieces of information.So due to this less space, it allows creating only 4 partitions(With the limitations of 2Tib(Tebibyte) in each partition).

4.Out of four partitions, MBR it allows one partition to use as an extended partition, with this extended partition we can create more logical partitions(It depends upon the operating system it allows to create more logical partitions), In Linux, we could create 15 partitions.

Note: The size of the extended partition and it’s all logical partitions should not exceed 2TiB

The below diagram explains you  the MBR partition scheme:

 

 

GPT Partition:

1.It supports a maximum of 128 partitions.

2.Here all partitions are equal(i.e, Primary, Extended and Logical partition method not used here)

3.It allows the maximum partition size is 8 ZiB(Zebibyte)

4.It uses the 64-bits standard to save the partition information

5.It has one main feature the information is saved in two locations, so if any one location is corrupted, the system will boot from the alternative one.

Note: In MBR all the information are saved in first sector of the hard disk, so in case if this sector corrupted, then booting process will get fail.

Linux file system types:

In order to use the disk to store your data, a filesystem must be created on the partition.We can also create a separate filesystem type in each partition or can create same filesystem type in all partitions.

File system types support in Red Hat Enterprise Linux:

EXT:(Extended file system): Early version of Linux, Now  EXT is not in use.

EXT2:( Extended file system2): It has very less features only, This was the default file system up to RHEL4.

EXT3:( Extended file system3): The default file system for RHEL5, It has so many features.

EXT3: (Extended file system3)

1.It supports the Journaling features

2.A directory can have 32,000 sub-directories

3.Supports filesystem up too 16TiB in size.

4.Up to 2TiB file size, it supports

EXT4: (Extended file system4) The default file system in RHEL6

1.A directory can have 62,000 subdirectories

2.Supports filesystem up too 1EiB in size.

3.Up to 16TiB file size, it supports

4.It also supports the Journaling features with an additional feature to enable and disable the journaling features.

Now, Let us see how to create a partition from the command line Before you start creating you should know the procedures to create the partition.

Procedure to create a partition:

1.Identify the correct hard disk from the server(coz in production servers you will see more than one hard disk connected)

2.Plan the layout(i.e How many partitions needed, size of the partition, where to mount that partition etc..)

3.Create the partition with the required size

4.Save the partition to the memory

5.Reboot the Linux system (so that that newly created partitions information will get saved in the kernel memory)

6.Make a new filesystem on the partition(i.e in Windows we call it as format a drive )

7.Mount the partition to some mount point directory

Ex:1 Create a 10GB Partition  and mount it to the directory   /sysbase

Let me demonstrate  by using oracle virtual box,  let me show you first how to add a new  hard disk to the server in virtual box

First Power off  the running virtual box,  we cannot add a disk when the  machine is in running state(In real production servers you can add and remove the disk while the server is in running state)

Step:1 Power off the virtual machine

Step:2 Now add a new hard disk to the server with the size 30GB(U can give the size as u wish, but I recommend  minimum 15 Gb you have to give)

Step:3  After choosing the new hard disk click the option .vdi disk and in the next screen it will ask you to choose the storage on the physical hard drive, here you have to choose “Dynamically allocated” after that the size of the hard disk screen will display, give the total size of the hard disk.

After assigning the size click create, you will see the newly attached disk under the controller

 

Then give ok and power on the virtual machine,thats it.. we have completed the initial steps up, now it’s time to create a partition on the newly attached hard disk

Step 4: Run the following command to check  how many harddisks attached and its partition layout information:
#fdisk  -l

From the above output we have confirmed two harddisk were attached on the server, The first one /dev/sda is a default bootable harddisk and the second one /dev/sdb is a newly attached disk to the server.

Note:/dev/sda indicates  either SCSI or SATA hard disk, The name of the first hard disk start with the letter “a” ,if the server has more hard disk, the next avaiable letter will be used for that one(ex:sdb,sdc,sde so on)

 

Step:5  To format the Hard Disk, run the following command
syntax:
#fdisk   <Logical name of the harddisk>
#fdisk   /dev/sdb

This will take you to the format menu ..

choose “m” to see all the available options  from the format menu

From this output u  will come to know which option to use to create a new partition, “n” to ccreate a new partition..

Now, choose “n” and enter, this will prompt you two options which partion you are going to create either primary or extended, choose primpary by giving “p”, As we know in MBR partition it allowed to create only four partions.If you want to create more partition then we have to use one primary partition as extended  one, In extended it allowed to create 15 logical partitions.

We are going to create the first partition on this disk, Since we haven’t created any partitions on this, so give the partition number as  “1”. Then after that it will ask you to give the starting cylinder value,don’t give any value here since system will take the default available cylinder, After this, it will prompt you to enter the total size of the parrtition(give the desired size at the end cylinder)

Step 6: Now to save this allocated partition information we have to press “w”

From the above output,  u can see a  Warning message, it says the fdisk program cannot update the inmemory kernel partiton table since the disk is mounted(busy), so we have to restart the system then after that the kernel reads the partion table.

Note: You can also use the command “partprobe” to force the kernel to read the partition table with out reboot.

#partprobe

From the above output if you see it didn’t show any warning or error messages because here we used the disk which doesn’t contain any mounted partition.

Step 7: Check the partiton details
#fdisk  -l

Now the partition created successfully, inorder to use this partition(i.e to store your data) we need to create a filesystem on this, if we dont create a filesystem on this partiton then it would become useless.

Step 8: Create a new file system

Syntax:

#mkfs   -t  <filesystem>  <Partition>

-t  =To mention the filesystem type

Now format the newly created partition with ext3 filesystem.

#mkfs   -t   ext3   /dev/sdb1

Step 9: Mount the filesystem
Mount: In order to make  use of this partition and visible to  all users you need to mount the filesystem to  some mount point directory
Note: Mounting and unmounting concepts I will explain in our next Tutorial

To mount a file system to a directory

Syntax: 

#mount   <filesystem>   <mount point directory>

Let me create a mount point directory

#mkdir  /ios.txt

Now mount  the newly created partition to this directory

#mount   /dev/sdb1   /Sybase

 

Step 10:  Now to check the currently mounted filesystem details,run the following command
#df  -h

df (Disk File System)- to display the disk space usage details

h- Human readable format(to display the size in (kb,mb.gb format)

From the above output, it’s  now confirmed the filesystem /dev/sb1 is mounted on the directory /Sybase

In our next tutorial, we will see how to create an extended partition.

If you found this article useful, Kindly Subscribe here 👉🏿👉🏿 Click this link to Subscribe