Thursday, 29 March 2012

Linux Notes


LINUX NOTES

NFS

Packages:

1.      nfs
2.      portmap

Config file :

  /etc/exports

    [ Open the file add the location which you want to share in network ]
    example :
/media/floppy                10.0.0.1/(rw) – To share with secefic machine
/media/cdrom               10.0.0.0/255.0.0.0/(rw)  - To share with 10. network
/var                              *   (rw)        - To share with all the network

Activate service

            # service portmap restart
            # service nfs restart

Not clear with command

            # exports –r
  
Client side configuration

            # mount –t nfs 10.0.0.1:/root/viswa  /mnt/nfsmountpoint  – server IP and location

To view shared file in server

            # exportfs

To view shared file in client

            # showmount –e (server IP>

Note : for the permanent mounting :

            Open /etc/fstab file and make entry in that

To activate service on booting time

            # chkconfig portmap on
            # chkconfig nfs on
Note IP assign

            # system-config-network
            # netconfig

User quota

Each file will occupy 4 blocks one block is 8 M.B.
It is advisable to create separate partition for all the home directories

Config file :

            /etc/fstab- along wih default add [ Default,usrquota,grpquota ]

Remount

            # mount –o remount,rw /home

To create quota file

            # quotacheck /home
            # quotaon –a – To set the quota to all the user
            # quotaoff – a – no idea

Setting quota for users

            # edquota –u <user name>                  

Note :
            Ls –i – check inode of a file
            One file will occupy 4 blocks
            All the admin command stored in /sbin

Crontab schedule

            To create automatic task

Date and time settings

            # date 030215552008(MMDDHRMINYEAR)

Creating auto scheduling

            # crontab –u root –e – After command given it will open a editor inside that we have to type
05 16 02 03 07 /sbin/init 0 (min hr day month dayofweek file to be executed)
05 15 02 03 07 tar –cvf <destination> <Source>
:wq

Service to be restarted

Service crond restart

To list particular user schedule

            # crontab –u <user name> - L

Backup & restore

            Restore from backup files :
                       
                        # tar –xvf /root/backup/doc.tar
                       
            Backup files
                       
            # tar <destination> <Source>
# tar –cvf /root/file name /usr/file name
# tar –cvf /dev/fd0 /root/file – to backup in floppy

Read backup files

# tar –tvf <file name>

DHCP

Packages:

1.      dhcp

Config file:

# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample  /etc/dhcpd.conf

Open dhcpd.conf file goto line number 5 and type following things

Subnet 172.24.0.0 netmask 255.255.0.0
{range 172.24.0.2 172.24.0.50;};
:wq

Service to be restarted

# Service dhcpd restart

MAC based IP assign

            Goto the last line of dhcpd.conf file and type the following

Host <host name>
            {
hardware 00:01:1B:B9:92:02
fixed address 172.24.0.15;
};

Dhcp client configuration
           
            # rpm –ev dhcp* - no idea
            # rpm –qa dhcp * - To search the installed package
            # rpm –qa | grep dhcp*

·        Only RPM installation is mentioned as per my notes

FTP server

Packages

1.      vsftpd(Very secured file transfer protocol)

Config file:

            # vi /etc/vsftpd/vsftpd.conf

Service to be restarted

            # service vsftpd restart

User name for FTP access
            User : ftp
            Password : anypassword

FTP users home directory

            /var/ftp/pub

Client side configuration

            # ftp <Server ip>
            Enter the user name & password

Ftp user file

·        files are who restricted to transfer file in FTP will be located in below given files
1.      /etc/vsftpd/ftpusers
2.      /etc/vsftpd/user_list

Download and upload file from FTP

                        # get <file name>
                        # put <file name>
                        # mget <filename > - for multiple file
                        # mput <filename>
                                   

Changing computer name
1.      /etc/sysconfig/network
2.      /etc/hosts
3.      # hostname <new name>


DNS

Packages

1.      bind
2.      catching name server
Config file

            /var/named/chroot/etc/named.rfc1912.zone (IN EL 5)- Go to the line 37

Forward lookup

Zone “visu.com “ IN
{
    Type master;
    File “<visu.zone>”;

 };

Reverse lookup

 Zone “0.24.172.in-addr.arpa” IN {
            Type master;
            File “<filename.local>”;
            Allow.update { none;};
 };

Creating .zone and .local

 /var/named/chroot/var/named/visu.zone
/var/named/chroot/var/named/visu.local

Inside .zone file

            IN SOA visu.com root (        note:Remoove the @ symbol
                      42 ---
                        ---
            IN NS station1.visu.com
Visu.com         IN A 172.24.0.254 # for web server (Remove the @ symbol)
                                 ---
:wq

Change group

    Chgrp named <filename.zone>
    Chgrp named <filename.local>


Named.conf file

# cp named.catching-nameserver.conf named.conf
#  vi named.conf

            Goto line number 16 and comment it
             In line number 17 type
listen-on port 53 {172.24.0.0/16;};

             In line 26
                        Allow-query {172.24.0.0/16;);
      
             Goto line 36 and 38 type
                        Match-clients {localhost;};
Match-destination{172.24.0.0/16;};

Resolve.conf file

            Open /etc/resolve.conf file and type
                        Name server <DNS server IP>
In /etc/hosts file
            <IP>    visu.zone          station1.visu.com

Service to be restarted

# service named restart

To check the DNS

 # dig station1.visu.com







Note : kudzu – For plug and play linux hardware config tool

Web server configuration
             
            It has to be done where webserver configured

Packges

1.      http

Config file

 # vi      /etc/httpd/conf/conf/httpd.conf – Goto last line <use ‘Esc and G for last line >

                        <virtual hosts <zonename> visu.com:80>
                                    Document root /var/www/html
Servername visu.com
                        </virtual host>
:wq

Create HTML file

            # vi /var/www/html/index.html

Service to be restarted

            # service httpd restart

To open the webserver

            #elinks <webserver name>

Virtual hosting

            One machine contain more than one webserver is called virtual hosting

.Zone file
            Type followings

           www1.example.com      IN A [172.24.0.1]
            www2.example.com     IN A [172.24.0.1]
httpd.conf

            In the beginning of the file type original webserver name
            At the end of the file type virtualHost www2.example.com

NIS

  For centralized user management

Packages

1. ypserv
2. yptools
3. ypbind

Service to be restarted

# service ypserv restart

To set the NIS domain name

# nisdomainname <Name>

Config file

# vi /etc/sysconfig/network and type the following
NISDomain = RHCE
:wq

Create NIS users

NIS users home disrectory has to be mounted in server

# useradd –d /server/mnt/singh –m singh
# passwd singh
# service ypserv restart

Home directory sharing

            # vi /etc/exports and type the following
           
            /home <Machine IP> (rw,sync)
            :wq

# service portmap restart
# service nfs restart

Create NIS master server

# /usr/lib/yp/ypinit –m
# service yppasswd restart
NIS client configuration

  1. Ping the server
  2. Setup – Authenticate conf – NIS click next
  3. Give the domain name and IP
  4. Service ypbind restart
  5. check the dmain name using “nisdomain” command

Config file

# vi /etc/auto.master goto last line and type
/rhome/etc/auto.misc

#vi /etc/auto.misc and type the following at the end of line

User name  permission       Home directory location

Singh          rw,soft,intr      172.24.0.254:/home/singh
:wq

#service autofs restart

Note: To empty log files # > <file name>
Note : To shutdown after 5 minutes #shutdown –r+5 –to
Note : Mahine IP will stored in following files

/etc/sysconfig/network-scripts/ifcfg-eth0 – In this file change the onboot option as yes
     Note : To bring down NIC card (Still loop back will run)
             
               # ifconfig eth0 down
               # ifconfig eth0:1 down

Virtual IP

            Assigning more than one IP in a NIC is called virtual IP
            # ifconfig eth0:1 10.0.0.3
            # ifconfig eth0:2 192.138.10.1


           




Partition View

# fdisk –l

Label name view

# e2 label /dev/sda1
# e2label /dev/sda2
Note : Mount points are different from label

Permanent mount point

# vi /etc/fstab

Remount the specific partition

# mount –o remount,rw /dev/sda

Tourbleshooting

Run level problem

 # vi /etc/inittab(Like only graphic mode or command mode ) – Go to line number 18
While booting press ‘G’ + give Space ‘S’ => Single user mode
Init 2 – Multi user mode with NFS
Init 3 – Multi user mode with NFS
Init 4 – Usual
Init 7 – Graphic
Init 6 – Reeboot

Greb file troubleshooting
# vi /etc/greb.conf – There is a option like default & timeout
Default – To change default boot O.S.
Timeout – To change the seconds before boot

Note : To view the kernel version use following command
# uname –r
Note : To turn off the send mail option
#chkconfig sendmail off


IF Grub.conf file is corrupted

  1. Boot from 1st CD
  2. Type “linus resuce”
  3. Type chroot /mnt/sysimage (Linux restore the rescue image in /mnt/sysimage)
  4. vi /etc/greb.conf
  5. Do the necessary changes and save and reboot

IF fstab file corrupted

 IF the fstab file is corrupted system will not boot boot same as above given and do the necessary changed in fstab file

# mount –o remount,rw <mount point>

If inittab file corrupted or option changed

      # vi /etc/inittab will show all the init option in the linux if the meaning of init is changed in that file linux wont boot properly.So when you set boot menu

è    Press ‘A’ space type ‘s’ – to boot the system in single user mode and do the necessary changes in initab file

User login problem

      If the user prompt (-s) given improperly then that user unable to login use
# chmod –s /bin/bash <username> - to fix the problem

To lock & unlock the user

      #passwd –l <user name> - To lock the user
      # passwd –u <user name> - To unlock the user

Shadow file corruption

      If the  shadow file is deleted that user will not able to login. Shadow file contain user information.

# vi /etc/shadow – To view the shadow file

Problem in fstab & grub file

  1. Boot using linux 1st CD
  2. Type linus rescue while booting
  3. fdisk –l
  4. #e2 label /dev/sda1 – If the output is boot then it is the boot partition next partition will be /root partition

To mount the root partition

  1. mkdir /nita
  2. mount /dev/sda3 /nita
  3. cd nita – after these steps sysfile will be automatically created inside nita
  4. #cd etc – Now grub.conf file will not available so first correct  vi /nita/etc/fstab
  5. # init 6 – Again boot from CD
  6.  type chroot /mnt/sys/mas2
  7. Now the chroot option in root window is available so we can fix the problem by doing necessary changes in grub.conf file
  8.  Final step is –boot is single user mode change the root password


LVM

Is an extendable partition usually it is a good practice to configure /home directory as a LVM

To set the LVM partition

  1. LV partition
  2. PV
  3. VG
  4. LVM

LV partition creation

To convert LVM partition

  1. Create usual partition
  2. Type option ‘t’ in fdisk –l
  3. 10 – is the partition name
  4. 8e – is exacode for LVM

Physical volume (PV)  creation

# pvcreate <lv partition name> - to create PV
# pvcreate /dev/hda10 /dev/hda11

Increatse the PV size

# pvcreate /dev/hda12 – to add space with existing partition

Volume group

# vgcreate <vgname> - to create vg
# vgextend <vgname>– To extend the vg

# vgcreate <any new vg name> <disk>
# vgcreate /dev/hda11 /dev/hda12

LVM creation

# lvcreate –l or –L+1024 –n <LV1(new LV name)>  <VG1(VG name)> - Once we created LVM  its name will be /dev/vg1/lv1
# mkfs –t ext3 /dev/vg1 /lv1
# mount <LVM> <Mount point>

To increase LVM

 Lvextend – L+1024m –n /dev/lvm/vg1

To findout the names

# pvdisplay – To find PV name
# lvdisplay – To find LV name
# vgdisplay – to find VG name

To remove LVM
  1. lvremove <device name>
  2. vgremove <device name>
  3. pvremove <device name>

Installation


  1. Boot with CD
  2. type “linux askmethod” – for various option (like nfs or remote installation)
  3. nfs servername / IP
  4. package path /var/ftp/pub

RAID

 Minimum 2 hard disk is needed of the same size.Device should looks like
For raid – md0
For floppy – fd0
For Hard disk – had or sda

RAID manage command

            # mdadm

Creating RAID partition

1.      Create same size partition or add 2 same size hard disk
2.      fdisk /dev/had and type t fd  /dev/hda (fd is hexa code for raid)
3.      Create a file system for new partition or hard disk
# mkfs t ext3 /dev/sda3
# mkfs t ext3 /dev/sdb3
4.      # mdadm – - create /dev/md0 – - level=5 – - raid-devices=2 /dev/sda3 /dev/sdb3 – To create Raid
5.      # mkfs –t ext3 /dev/md0
6.      # mount /dev/md0 /home
7.      Create permanent mount
# vi /etc/fstab – inside file
      /dev/md0 /home ext3 defaults 0 0
 To view the Raid details
            # mdadm – - details /dev/md0

Replacing hard disk

            # mdadm -- manage /dev/md0 – - add </dev/new hard disk or partition>


           





Remote login

# ssh <IP>
# rsh <IP>

Swap Post installation

If we upgrade system & we want to add more space in swap

  1. Create new partition
  2. change its hexa code to 82 using ‘t’ in fdisk /dev/hda
  3. To change new partition to swap file system
   # mkswap /dev/sda7
  1. Activate swap partition
    # swap /dev/sda7
  1. Make permanent mount in fstab
          # vi /etc/fstab and type following
                  ----   /dev/sda7 swap swap default 0 0
           :wq

To see the swap details

 # free –m
 # cpuinfo – To see mother board information.
 # vi /proc/cpuinfo – To see mother board information.





Samba server

            Used to share resource between window and linux
Package

  1. samba

Config files

1.      /etc/samba/smb.conf – inside this file

Change worgroup=<name of using wrk group>
Change host allow = <client IP or Nerwork IP>(eg. 172.24.0.0/255.255.0.0)
Change sharing location
      [share name]
                  Path = /home
                  Browsable = yes
                  Read only = yes
                  Writeable = yes
                  Valid.users = <user name> / public =yes

Service to be restarted

            # Service smb restart

To view the shared files

            # test parm



Mailserver

1.      For incoming – we use dovcot
2.      For outgoing – We use sendmail

Packages

1.      dovcot
2.      sendmail

Incomming mails

 #  vi /etc/dovecot.conf – Goto line number 17 and type
   
     Protocols =imap imaps pop3 pop3s
Imaps – Internet message protocol security

Outgoing mails

# vi /etc/mail/sendmail.mc (.mc – means macro file) – Goto line number 116 & type
Dnl # daemon-options(‘port=smtp;addr=127.0.0.1;name=MTA’)dnl
# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Note: dnl – keyword used in macro file to disable the lines
         Mta – mail transfer asent
         .cf – is an configuration files.All the macro file changes stored in .cf files

Service to be activated
# service dovecot restart
# service sendmail restart

Mail ID

 All the mail id will be looks like username@webserver.com (test1@example.com)

Sending mails

            # mail test@webserver.com <enter>

            Sunbject : <Enter any subject>
            ---------------------
          ---------------
 Press dot and enter to finish and send mail.
            # mail test@webserver.com /test.txt <enter> - to send mail with attachment



Read mail

 After logged in just type mail and give the number of mail which you want to read

Come out of mail

 To come out of mail just type ‘quit’

Note: All user mails will be stored in /var/spool/mail/<user name>
            Once mail red it moved to mbox
# vi mbox – to see mbox (mbox stored in users home directory

Forwarding mails

# vi /etc/aliases – From this location we can forward mails
Eg: venu: root,venu

ACL

Access control list – To set the permission for the particular user

ACL for specific user

# set facl –m u:singh:rwx /root/<file name>
# getfacl <file name>

To remove permission

# setfacl –x u:singh /root/<file name>

Sticky bit

# chmod 7777 <file name> - The last 7 is called sticky bit it protect the file from users . They cant delete it

Umask

Defauls usmask will be – 0022
Folder mask permission is – 777(Default folder 777-022 = 755)
File mask permission is – 666 (Default folder 666-022 = 644)

Change the umask value
# umask 222
Note : File and folder permission value set based on umask value

Creating hidden files

# cat > .nita – To create hidden file
# ls –a – To list all the file including hidden files
# cat .nita – To read file
# mkdir .<foldername> - To creatd hidden folder

Firewall

To protect the network from unauthorized network

Config firewall

# iptables – L – To see the firewall status
# iptables – F – To delete rules

Block a PC FTP access

# iptables – A INPUT –P tcp
# iptables – A INOUT –P tcp – -dport 21 –S 172.24.0.0/255.255.0.0 –D 172.24.0.254 – -J DROP
a-      add
             p- protocol
             dport – destination port
             s- source
             d- destination
             j – To apply policy
#iptables –D INPUT 1 – to delete particular rule

Allowing particular network to use FTP

# iptables – A INPUT –P tcp – - dport 21 –S ! 172.24.0.0/255.255.0.0 –d 172.24.0.254 - - J DROP – IF the source is not mentioned it will take as anonymous

# iptables –D INPUT 3
# iptables save







Note :All port details stored in /etc/services file


TCP Rapers

Config file

1.      vi /etc/hosts.deny
2.      vi /etc/hosts.allow

è    If we put the entry in .deny file it means Drop
è    If we put the entry in .allow file it means Allow

# vi /etc/hosts.deny
Goto last line and type

Vsftpd:172.24.0.0/255.255.0.0
Note : In TCP rappers first preference given to allow file

Remote installation

  1. Boot with linux 1st cd
  2. type linux askmethod
  3. Select installation method NFS image
  4. Enable ipv4
  5. In NFS server IP address area give the IP
  6. remaining steps as usual

SSH(Secured  shell )

Package
  1. Openssh

Service to be restarted

            # service sshd restart
            # service shd status

Telnet

Packages

1.      xinet
2.      telnet

Config file

  # vi /etc/xinetd.d/telnet- In that file change the last line “disable=no”
  # service xinet restart


Rlogin

Packages

  1. rsh
  2. xinet

Config file

            # vi /etc/xinet.d/rlogin – Change the last line (i.e. disable=no)

Service to be restarted

            # service xinetd restart

Client side configuration

            # rlogin serverip –L <username> - To login from remote

Xwindow

            Is graphical window

Packages

            # xorg * - More than 200 packages exists

Config file

            # vi /etc/x11/xorg.conf –

Service to be retstarted

            # Service xfs restart

Note : To create xorg file use “system-config-display”


Kernal

 Kernel version information stored in file /etc/grub.conf
/proc – is the kernel directory

Upgrade kernel
           
            # rpm –uvh xen-libs-3.0.3-25.el5.i386.rpm

Squid configuration

Package

            Squid

Config file

            # vi /etc/squid/squid.conf –Set the line number
                        In line number 73 (http 3128) remove the comment ‘#’
                        In line number 738 create a new line and type “cache-mem 64 MB
                        In line number 993 (cache.dir…) remove the comment
                        In line number 2243 (acl nita – - src 172.24.0.0/16) remove the comment
                        In line number 2244
                             Eg1:            http-access allow/deny nita
                   
                             Eg2:            acl linux1 src 10.0.0.1
                                                http-access allow linux1

                            Eg3:             http-access deny all
                        In line number 1353 give the DNS
                            Dns-nameserver 203.145.184.32

Note: squid default port number is 3128


Printer configuration

Types of printer concept

1.      local printer
2.      linux printer
3.      window printer
4.      novell printer
5.      Jet direct printer

            # startx – to start to linux graphical mode
            # system-config-printer – type the above command in graphical mode

Note : Network printer port is 9100

Taking printouts

            # lpr <file name>

Process management

            # ps –ax – to display all the running process
            # ps –ax | wc –l
            # ps –ax | grep tty – To see the process detail in terminal
            # kill -9 <pricess id> - to kill the process (-9 is for immediate kill)

















No comments:

Post a Comment