Saturday, 30 December 2017

configure DHCP server in RHEL7

DHCP stands for 'Dynamic Host Configuration Protocol'
It is a protocol for assigning IP address to the host/computer system dynamically.

[root@localhost ~]# yum install dhcp

[root@localhost ~]# cd /etc/dhcp

[root@localhost dhcp]# cd /usr/share/doc

[root@localhost doc]# ls

dhcp-4.2.5/        dhcp-common-4.2.5/

[root@localhost doc]# cd dhcp-4.2.5

[root@localhost dhcp-4.2.5]# ls

dhcpd6.conf.example  dhcpd.conf.example  ldap

[root@localhost dhcp-4.2.5]# cp dhcpd.conf.example  /etc/dhcp/dhcpd.conf 

[root@localhost dhcp-4.2.5]# vim /etc/dhcp/dhcpd.conf

default-lease-time 600;

max-lease-time 7200;

subnet 192.168.0.0 netmask 255.255.255.0{

range 192.168.0.10  192.168.0.200 ;

}

[root@localhost dhcp-4.2.5]# systemctl restart dhcpd

[root@localhost dhcp-4.2.5]# systemctl enable dhcpd


------------------------------- Dhcp client configuration-------------------------

[root@client ~]# dhclient -v  enp2s0



Friday, 29 December 2017

Configure Nginx server as a reverse proxy in RHEL7 / CentOS

INSTALLATION OF Nginx :-

[root@station108 ~]# rpm -ivh http://nginx.org/packages/rhel/7/noarch/RPMS/nginx-release-rhel-7-0.el7.ngx.noarch.rpm

[root@station108 ~]# yum install nginx-1.12.1 -y

second method:-

[root@station108 ~]# vim /etc/yum.repos.d/nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/7/$basearch/
gpgcheck=0
enabled=1

[root@station108 ~]# yum repolist all

[root@station108 ~]# rpm -qc nginx

/etc/logrotate.d/nginx
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug

 [root@station108 ~]# cp /etc/nginx/conf.d/default.conf  /etc/nginx/conf.d/default.conf.bak

[root@station108 ~]# vim /etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  station108.example.com;


    location / {
       # root   /usr/share/nginx/html;
        #index  index.html index.htm;

        proxy_pass   http://192.168.10.105 ;   

            }

[root@station108 ~]#  systemctl restart nginx

[root@station108 ~]#  systemctl enable nginx




Thursday, 28 December 2017

Break Root Password in RHEL or CentOS

  1. Press 'e' at the boot menu





    2. Go to line which starts from linux16  having rhgb quiet with the help of downward arrow key 




   3. Press 'End' key and write rd.break enforcing=0


   4. Then press Ctrl+x

   5. After entering in emergency mode remount root file system in read write mode which is previously in read only mode.

    switch_root:/# mount -o remount,rw /sysroot

  

   6. Once the root file system remounted in read write permission,change into a chroot jail as given below.

   switch_root:/# chroot /sysroot





   7. Now reset the password for root

   sh-4.2# passwd root



   8. Type your new password and also confirm it by retyping






   9. Then press 'Ctrl + d'  two times to exit

   10. After login with new password, open your terminal and type as given   below to restore the security context.

   [root@localhost Desktop]# restorecon /etc/shadow




      

Set grub password in rhel7 or CentOS

--> Anyone can get the root login by breaking the root password in rhel7 or CentOS type OS

--> So to stop anyone to break root password we have to secure it by grub password.

# cd /etc/grub.d/

# ls
00_header  01_users  20_linux_xen     30_os-prober  41_custom
00_tuned   10_linux  20_ppc_terminfo  40_custom     README

--> First you have to generate the hash for password by using this command

# grub2-mkpasswd-pbkdf2
 Enter password: ******
 Reenter password: ******
 PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.1231312121
 fdafagadgg646564365j3j53h524klnlblh242lfhikufhiulaiunmln24wfkkhj
 sflfafjkl3l42kljlhrwi5ojhjb245jlbjhlhlkhjlkjj24lkhlhhkknlnafkjlanlkai99





--> copy the generated hash of password like from grub.pbkdf2... upto last



--> Then you have to select the 40_custom file in which you have to enter the following entries in the last line.



 # vim 40_custom

set superusers='root'
password_pbkdf2 root   ---------------paste here the generated password---------



# cd /boot/grub2/

# ls

# grub2-mkconfig > grub.cfg


# reboot

----> Press 'e' key at boot menu (To Check)

Mariadb Server


 --> To install mariadb-server use following command

# yum install mariadb*


 # systemctl start mariadb

 # mysql



--> to show list of databases

 MariaDB [(none)]> show databases;

--> to create a new database

 MariaDB [(none)]> create database db;

--> here db is the name of database



--> to use the created database

MariaDB [(none)]> use db;


 --> to create table inside the database(db)

MariaDB [(none)]> create table info(name char(20),password char(15));

--> here info is the name of table and name,password are attributes.


 --> to insert values of attributes inside the table info

MariaDB [(none)]> insert into info(name,password)values('sarvesh','redhat');



 MariaDB [(none)]> show tables;

MariaDB [(none)]> desc info;



 --> to see the entire contents of the table

MariaDB [(none)]> select * from info;


 --> to exit out of the database

MariaDB [(none)]> exit



 --> to secure the database with password

[root@mariadb_server ~]# mysql_secure_installation


 
--> set the root password





 --> Now login with the secure password

[root@mariadb_server ~]# mysql -u root -p





 --> In case of forget password

[root@mariadb_server ~]# rm -rf /var/lib/mysql/*




---------------------------------------- #####---------------------------------------------

Some important commands to perform following inside the database

--> To rename Table
  # alter table tablename rename new_tablename ;

--> To add new attribute to the existing table
  # alter table tablename add attribute data_type(size) ;

--> To remove attribute from the existing table
  # alter table tablename drop attribute ;

--> To change size of attribute or type of attribute
  #alter table tablename modify attribute data_type(size) ;

--> Fetching column without repetition of any data
  # select distinct column_name from table_name ;

--> To update the data in particular row
  # update table_name set attribute='xyz' where attribute='zyxa' ;

--> To delete the particular row
 # delete from tablename where attribute='X' ;

--> To delete all rows in which data starting with 'X'
 # delete from tablename where attribute like 'X%' ;


--> To delete all tuples from the table
 #  truncate table table_name ;

--> To delete table schema along with its tuple
 # drop table table_name ;

Configure DNS server in RHEL7 / CentOs

DNS stands for Domain name system used for resolving hostname to ip address or ip address to hostname

server (IP -->  192.168.10.59)

-->install the 'bind' software

# yum install bind

 --> to find out the configuration file of bind

# rpm -qc bind

 --> prepare a backup of configuration file

# cp  /etc/named.conf  /etc/named.conf.bak

--> empty the configuration file

# >/etc/named.conf

# vim /etc/named.conf

options {

directory  "/var/named" ;

};

zone "test.com"  IN  {

type master ;

file  "myfile" ;

};


# cd /var/named

# cp named.localhost  myfile

# vim myfile

$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
        AAAA    ::1

www.test.com.         IN          A       192.168.10.2

try   CNAME  www

hello.test.com.         IN          A        10.10.10.10


# chown named:named myfile

# systemctl restart named

# systemctl enable named


Client (IP --> 192.168.10.60)

# vim /etc/resolv.conf

search    test.com

nameserver    192.168.10.59

# nslookup   www.test.com

# nslookup try.test.com

# host try

# host www

# nslookup  hello.test.com