Sunday 17 April 2016

RUN LEVELS/TARGETS IN LINUX

RUN LEVELS/TARGETS IN LINUX


Run Levels/Targets in Linux
Welcome guys to our linux tutorial, In this article we will discuss about different runlevels in unix-linux system. We will briefly describe runlevel, its associated configuration file, boot process,stages of boot process and finally we will discuss briefly about each runlevel. These runlevels or modes run system or boot process defined by user/system admin. But in latest version system uses target instead of runlevels so I am going to use both runlevel or target word so don’t confuse.
Introduction
Runlevels is basically modes in *nix based systems which is initializing operating system. Every runlevel has certain numbers of services started or stopped. This gives user flexibility to run/boot system in different modes( run system with certain services) as per requirements
Init stand for initialization is the program file in *nix operating system. Its run as a daemon and has typically process identity (PID)  1.
Feb2516-19usd-sitewide728X90
Configuration File
/etc/inittab is a configuration file used to setup the default runlevels for *nix system.After the linux system is booted the init program reads this configuration file and determines runlevel set in this file. If user/admin has not specified any runlevel system will boot with default runlevel.  Applications which  are started by init program located in the/etc/rc.d folder, then within this folder there are  separate folders for each runlevel  e.g rc0.d, rc1.d etc. These runlevels or targets are defined in below.
To Change in configuration file is open it in vi editor or any other editor of your own choice .
I am going to open with vi
vi /etc/inittab.
In older version you can change the run level in last line of this file see below example
id:5:initdefault: or id:3:initdefault    #(choose as per your requirement)
In latest version there are only two main targets by default
# multi-user.target: analogous to runlevel 3

# graphical.target: analogous to runlevel 5         #(choose as per your requirement)
BOOT Process
There are following stages of boot process.
runlevel or target in linux
Runlevel or Target with Commands
There are seven runlevels in *nix OS and runlevels are identified by numbers.
Init 0
Init 0 is for immediately shutdown system and powers it off you may also use halt and poweroff. Syntax init 0 orpoweroff or halt.
[fahmed@faraz ~]$ init 0

[fahmed@faraz ~]$ poweroff

[fahmed@faraz ~]$ halt
Init 1
It is also known as Single-User mode and it is used for system maintenance and root in CLI mode. Syntax init 1. No network interfaces configured
[fahmed@faraz ~]$ init 1
Init 2
Used for without networking in CLI mode and it is multi-user mode. Syntax init 2.
[fahmed@faraz ~]$ init 2
Init 3
It is also used as multi-user mode but with networking in CLI mode. Syntax init 3. this is like normal startup
[fahmed@faraz ~]$ init 3
Init 4
This is an un-defined mode or you can say not in used mode. Syntax init 4.
[fahmed@faraz ~]$ init 4
Init 5
This is a GUI mode. A standard and default runlevel/target  for most *nix OS. Syntax init 5.
[fahmed@faraz ~]$ init 5
Init 6
It is used to restart your system when required and you may also use reboot.
Syntax init 6 or reboot.
[fahmed@faraz ~]$ init 6
OR
[fahmed@faraz ~]$ reboot
NOTE: Don’t set runlevel 0, 1 and 6 as default runlevel. Otherwise you will face the problems.
To check who is logon in system by using command who. Or list of user login by using command who –u.
[fahmed@faraz ~]$ who

fahmed   :0           2016-02-24 06:09 (:0)

fahmed   pts/0        2016-02-24 06:10 (:0)

fahmed   pts/1        2016-02-24 06:10 (192.168.40.112)
To view current runlevel/target by using command who –r.
[fahmed@faraz ~]$ who -r

run-level 5  2016-02-24 05:33
To view boot system time by using command who –b.
[fahmed@faraz ~]$ who -b

system boot  2016-02-24 05:32

[fahmed@faraz ~]$
For all options by using who –a.
[fahmed@faraz ~]$ who -a

system boot  2016-02-24 05:32

fahmed   ? :0           2016-02-24 06:09   ?          4601 (:0)

run-level 5  2016-02-24 05:33

fahmed   + pts/0        2016-02-24 06:10 00:22        5430 (:0)

fahmed   + pts/1        2016-02-24 06:10   .          5584 (192.168.40.112)

[fahmed@faraz ~]$

In this tutorial we discussed about runlevels or targets with command init 0 to 6 and who command who –r, who –u, who –a and who –b. Please subscribe our newsletter for new upcoming tutorials.





Hello and welcome guys, In this new and exciting tutorial/article we will learn step by step how to configure DHCP Server in Linux (Red Hat/ CentOS). We will do configuration by using configuration file.  This is used for enterprise network to reduce manual  IP configuration efforts (for instance it will take hours and hours to do ip configuration on 1000 systems).

What is DHCP Server

DHCP stands for Dynamic Host Configuration Protocol.
Network/Server/System Administrator designs and implements DHCP server to centrally manage and automate the process of assigning Internet Protocol (IP) in company/organization. DHCP has ability to assign IP automatically for the system as well as Subnet Mask, Gateway and DNS (if you have configured),
when system boots it gets the IP from DHCP. DHCP uses DORA process in backend. DHCP uses the concept of lease time or we can say the amount of time that given an IP address is valid for computer. The lease time may vary depending on the user to require internet connection with a specific location. It is useful in education sector or other environment where users change frequently.
DORA Stand for Discover Offer Request Acknowledgement.

DHCP Discover

When a client is configure with obtain automatic IP address, then the client PC searches for DHCP server. The UDP is broadcasted to discover the DHCP server.
Available IP address in the pool offered by DHCP Server and the Client PC waiting for the IP address.

DHCP Request

In the response of the offer, Client will request IP address.

DHCP Acknowledge

In the response to the request, DHCP server will respond with IP address, subnet mask, Gateway and DNS info along with the acknowledgement.

DHCP PORTS

DHCP client is running on the client machine. It begins broadcasting requests for configuration information. By default, these requests are listening on UDP port # 68. The server responds to client on UDP port # 67.

Installation of DHCP Server on CentOS / Red Hat 7

For installation of DHCP server by using command yum. Syntax yum install dhcp
[root@faraz ~]# yum install dhcp*

Loaded plugins: fastestmirror, langpacks, priorities

base                                                                        | 3.6 kB  00:00:00
epel/x86_64/metalink                                                        | 4.0 kB  00:00:00
epel                                                                        | 4.3 kB  00:00:00
extras                                                                      | 3.4 kB  00:00:00
updates                                                                     | 3.4 kB  00:00:00

(1/4): epel/x86_64/updateinfo                                               | 523 kB  00:00:02
(2/4): extras/7/x86_64/primary_db                                           | 101 kB  00:00:03
(3/4): epel/x86_64/primary_db                                               | 3.9 MB  00:00:08
(4/4): updates/7/x86_64/primary_db                                          | 3.2 MB  00:00:22
After installation you need to configure a static IP address for DHCP server in the DHCP range for the listening interface. (e.g. enp0s3 for latest version, eth0 for older versions)

Configure Server Interface (Network Interface Card) for DHCP

Open the file /etc/sysconfig/network-scripts/ifcfg-enp0s3 with insertion mode through vim tool and make the changes as per requirement. Here we go…..;
[root@faraz ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

TYPE=Ethernet
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.56.10
NETMASK=255.255.255.0

DHCP Configuration

Now we are going to configure our DHCP server, for configuration we need to go to the file which is in/etc/dhcp/dhcpd.conf. In this file we need to add some parameters for DHCP server configuration by defining IP range, route, domain name server, default and max lease time within subnet and netmask parameters.
[root@faraz ~]# vi /etc/dhcp/dhcpd.conf

# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#

subnet 192.168.56.0 netmask 255.255.255.0
{
range 192.168.56.50 192.168.56.100;
# DNS server IP or additional DNS server IP
#       option domain-name-servers 8.8.8.8, 8.8.4.4 (remove the [#] hash sign if you have domain server)
#Domin name
#       option domain-name shahid-academy.com
option broadcast-address 192.168.56.255;
#Gateway IP
option routers 192.168.56.1;
 
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
}

Reserve IP address with MAC

You can also reserve the IP address for printer or system/ Pc with MAC address in this regard add some parameter which is define in below example;
host myPC
{
hardware ethernet 00:00:00:00:00:00;
fixed-address 192.168.56.90;
}

Add rule for Firewall

If your system’s firewall in running position then you have two choices one is stop the service of firewall by usingsystemctl stop firewalld and the second one is to define the rule for the firewall by using below condition;
[root@faraz ~]# firewall-cmd --permanent --add-service=dhcp
[root@faraz ~]# firewall-cmd --reload

Service

Start the service by using command systemctl. Syntax systemctl start service – daemon – name
[root@faraz ~]# systemctl start dhcpd
You can start the service at the boot time by using enable option. Syntax systemctl enable service – daemon – name
[root@faraz ~]# systemctl enable dhcpd

Verification of DHCP Server Configuration

Finally you can verify whether you DHCP server configure accurately or not by using dhcpd configtest.
[root@faraz ~]# dhcpd configtest

In this tutorial/ article we have learnt how to configure DHCP server with reservation by adding firewall rule if firewall is running. I hope you like it and learn this practical knowledge. Let us know about your suggestions and problem through comment and subscribe our newsletter. Keep learning with us… :-)