Tuesday, September 22, 2015

DNS configuration on RHEL 6.5

How to configure DNS on RHEL 6 Linux 

* Package - bind*

* Daemon - named

* Global conf file - /etc/named.conf , /etc/named.rfc1912.zones,

* Zone conf file - /var/named/named.localhost  &  /var/named/named.loopback

(Note : We can change name of the file - "named.localhost & named.loopback" according to us like - forward.zone & revers.zone as per mentioned name in the "/etc/named.conf  &  /etc/named.rfc1912.zones")

* Port no. - 53
------------------------------------------------------------------

Scenario : 

[A] Primary(Master) DNS Server Details:

>Operating System : CentOS release 6.6 (Final)

>Hostname : server3.deo.com

>IP Address : 192.168.1.100/24
--------------------------------------------

* Configuration of DNS Service 

Step 1. Configure the hostname and network of the system. 

*hostname configuration 

[root@server3 ~]# vim /etc/hosts

192.168.1.100   server3.deo.com         deo.com         [Make the entry of hostname in the system ]

:wq [save the file and quit]

[root@server3 ~]# HOSTNAME    server3.deo.com   [efect the hostname without reboot the system]

* Network configuration 

>IP of the system should be on static mode not on dynamic for that NetworkManager should be stop.

> Stop NetworkManager

[root@server3 ~]# /etc/init.d/NetworkManager  stop

[root@server3 ~]# chkconfig NetworkManager off

[root@server3 ~]# setup

> go to the system services option > unchecked the NetworkManager option > save & quit

>Configure IP of the system. 

[root@server3 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.1.255
HWADDR=00:27:1e:0c:80:7b
IPADDR=192.168.1.10
IPV6INIT=no
IPV6_AUTOCONF=no
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
GATEWAY=192.168.1.1
DNS1=192.168.1.10
TYPE=Ethernet
USERCTL=no

:wq [save and quit]

[root@server3 ~]#service network restart [After all the configuration must restart the network]

Step 2. Install the packages for DNS server though yum command. 

[root@server3 ~]# yum install bind* -y [If we have already installed the dns packages, will get below message]

Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
mondorescue                                                                                                     | 1.3 kB     00:00
Package 32:bind-sdb-9.8.2-0.37.rc1.el6_7.4.i686 already installed and latest version
Package 32:bind-chroot-9.8.2-0.37.rc1.el6_7.4.i686 already installed and latest version
Package 32:bind-devel-9.8.2-0.37.rc1.el6_7.4.i686 already installed and latest version
Package 32:bind-libs-9.8.2-0.37.rc1.el6_7.4.i686 already installed and latest version
Package 32:bind-9.8.2-0.37.rc1.el6_7.4.i686 already installed and latest version
Package 32:bind-utils-9.8.2-0.37.rc1.el6_7.4.i686 already installed and latest version
Package bind-dyndb-ldap-2.3-8.el6.i686 already installed and latest version
Nothing to do
[root@server3 ~]#

Step 3. Configure the Global parameter of DNS in "/etc/named.conf " & "/etc/named.rfc1912.zones"

* Configure - /etc/named.conf  

[root@server3 ~]# vim /etc/named.conf

options {
        listen-on port 53 { 192.168.1.100; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";

        allow-query     {192.168.1.0/24; };

        allow-transfer  {192.168.1.0/24; };

        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";
        managed-keys-directory "/var/named/dynamic";
};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
zone "." IN {                         [copy this four line and past any where in file to configure forward zone]
        type hint;
        file "named.ca";
};
zone "deo.com" IN {          [I have pasted here to configure the forward zone]
        type master;
        file "forward.deo";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

:wq [save & quit]


* Configure - /etc/named.rfc1912.zone 

[root@server3 ~]# vim /etc/named.rfc1912.zones

zone "localhost.localdomain" IN {         [copy this five line and past in file to configure forward zone]
        type master;
        file "named.localhost";
        allow-update { none; };
};

zone "localhost" IN {
        type master;
        file "named.localhost";
        allow-update { none; };
};

zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
        type master;
        file "named.loopback";
        allow-update { none; };
};

zone "1.0.0.127.in-addr.arpa" IN {  [Copy these five line and past in the file to configure revers zone]
        type master;
        file "named.loopback";
        allow-update { none; };
};

zone "0.in-addr.arpa" IN {
        type master;
        file "named.empty";
        allow-update { none; };
};
zone "server3.deo.com" IN {                 [I have pasted here to configure the forward zone]
        type master;
        file "forward.deo";
        allow-update { none; };
};

zone "1.168.192.in-addr.arpa" IN {     [I have pasted here to configure the revers zone]
        type master;
        file "reverse.deo";
        allow-update { none; };
};

: wq  [save & quit]


Step 3. Configure the zones for the DNS service in > /var/named/forward.zone  & /var/named/revers.zone. 

> As per the mentioned file names in the /etc/named.conf for the forward zone is > file "forward.deo"; So we need to create a new file by this name in /var/named/, by default this file is not located in /var/named/ directory.

[root@server3 ~]# cd /var/named/

[root@server3 named]# ls
chroot  data   dynamic  named.ca  named.empty  named.localhost  named.loopback slaves

[root@server3 named]#touch  forward.deo  reverse.deo

[root@server3 named] cp  named.localhost  forward.deo
cp: overwrite `forward.deo'? yes

> As per the mentioned file name in the /etc/named.rfc1912.zone for the revers zone is > file "reverse.deo"; So we need to create a new file by this name in /var/named, by default this file is not located in /var/named/ directory.

[root@server3 named] cp  named.loopback   reverse.deo
cp: overwrite 'reverse.deo'? yes


* Cofigure forward zone file in /var/named/forward.zone 

[root@server3 ~]# cd /var/named/

[root@server3 named]# vim forward.deo

$TTL 1D
@       IN SOA   server3.deo.com. root (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum

                                 IN      NS      deo.com.
deo.com.                   IN      A       192.168.1.100
server3.deo.com      IN      A       192.168.1.100

:wq [Save & Quit]


*Configure revers zone file in /var/named/revers.deo

[root@server3 named]# vim reverse.deo

$TTL 1D
@       IN SOA  1.168.192.in-addr.arpa  root.deo.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum

                  IN   NS         deo.com.
                  IN   PTR      deo.com.
100            IN   PTR      server3.deo.com.

:wq  [Save & Quit]

[root@server3 ~]# service named start [After all the configuration start the dns]

[root@server3 ~]# nslookup server3.deo.com [check that forward lookup service is workig or not]

Server:         192.168.1.100
Address:        192.168.1.100#53

[root@server3 ~]# nslookup 192.168.1.100 [check that revers lookup service is working or not]
Server:         192.168.1.100
Address:        192.168.1.100#53

100.1.168.192.in-addr.arpa      name = server3.deo.com.

[root@server3 ~]# chkconfig names on [on the dns service for permanent]
-------------------------------------------------------------------------------------------------------------------------

Tuesday, September 15, 2015

YouTube Downloader (youtube-dl)

Install YouTube-DL – A Command Line Video Download Tool for Linux

youtube-dl is a Python based small command-line tool that allows to download videos from YouTube.com, Dailymotion, Google Video, Photobucket, Facebook, Yahoo, Metacafe, Depositfiles and few more similar sites. It written in pygtk and requires Python interpreter to run this program, it’s not platform restricted. It should run on any Unix, Windows or in Mac OS X based systems.Recently, youtube-dl added video download support for 17 new websites: brightcove.com, auengine.com,
RingTV, instagram.com, Jukebox, 3sat, CSpan, Statigr.am, traileraddict.com, hotnewhiphop.com, wat.tv, tu.tv, gamespot.com, tudou.com, Wimp.com, archive.org and break.com youtube-dl also allows to choose specific avialable video quality format to download or let the program itself
automatically download higher quality video from the site. It also has supports for user specific playlist downloads,  options to add custom or original title to the downloaded video file. proxy support and many more.

Install Youtube-dl in Linux

*Install YouTube-DL in RHEL/CentOS and Fedora

The youtube-dl program can be installed by enabling epel repository under your systems. Once enabled, you can install using ‘yum‘ package manager tool as shown.

OR we can down load the .rpm package from "www.pkgs.org" website. And then can be installed through rpm command.

for RHEL -6
--------------
http://dl.fedoraproject.org/pub/epel/6/i386/youtube-dl-2015.06.04.1-2.el6.noarch.rpm   [download through 'wget'command]

#rpm -ivh    youtube-dl.rpm

#yum install youtube-dl

*Update YouTube-DL

Youtube-dl itself can be updated to the latest version using the following command.

# youtube-dl -U

* How to Use YouTube-DL to Download Videos.

1. To download a video file, simply run the following command. Where “VIDEO_URL” is the url of
the video that you want to download.

# youtube-dl   http://www.youtube.com/watch?v=vKtwZmhX0lw   [Press Enter to download the video]

2. To download a video in availabe file formats, use option “–all-formats” with the command.

# youtube-dl –all-formats http://www.youtube.com/watch?v=vKtwZmhX0lw.

3. To download a preferred file format, use the option ‘-f’ (video format code). For example, I would like to download flv format, So I use format code as ‘34‘ as shown below.

# youtube-dl -f 34 http://www.youtube.com/watch?v=vKtwZmhX0lw

4. To download a list of video files, create a file and place all the YouTube links that you wish to download.

# youtube-dl -a youtube_links.txt

4. Type the following command in a terminal to list all the avialable options.

# man youtube-dl   [for more information and option]

Terminal multiplexer (TMUX)

TMUX - Multiscreen Terminal

Tmux is a terminal multiplexer, that is a piece of software that allows you access to multiple terminal sessions from a single terminal window. It is extremely useful  when doing maintenance on some server via SSH because it will allow you to simultaneously see the output of multiple terminal commands at the same time without  having to run multiple ssh sessions.

*Installing tmux on Centos 5.x or 6.x

#yum install  tmux

or

*Download from url - http://pkgs.org/centos-5/epel-i386/tmux-1.4-3.el5.1.i386.rpm.html
Binary Package for (32 bit on RHEL5)

* Download from url - http://pkgs.org/centos-5/epel-x86_64/tmux-1.4-3.el5.1.x86_64.rpm.html Binary Package for (64 bit on RHEL5)

# rpm -ivh tmux-1.4-3.el5.1.x86  [Install the package]


Using tmux

* After tmux is installed by following the instructions above start by typing this in the terminal

#tmux

* You will notice that the terminal slightly changes to something

This is essentially a new terminal with the default shell logged in as your current user account. It looks somewhat different from a traditional terminal session in the sense that it shows a green (by
default, but can be changed) status bar with additional information such as the number of active sessions and which is the current session you are working on. The current page that you see on your screen is referred to as a “window” in the tmux context. You can have multiple windows, which operate similarly to having multiple browser tabs open  and furthermore you can split each window into multiple panes and execute commands in each pane.

*In order to interact with tmux you need to first press the control key,  which by default is CTRL-B. After that you can press one of the following  keys for the most basic actions (first press ctrl-b, then release and then  press one of the following):

Key Result

c Create a new window

n Change to next window

p Change to previous window

" Split pane horizontally

% Split pane vertically

, Rename current window

o Move to next pane

> If you choose to rename the current window, you will see the changes reflected in the status bar of tmux in the list of all current windows. That is convenient to keep track of long-running  tasks you are monitoring. When using the “o” shortcut to move between panes keep in mind the order (panes are numbered left-to-right, top-down). For faster navigation you can also use  the keyboard arrows to switch between panes, so if you press CTRL-B and then one of the keyboard arrows the pane in the direction of the arrow will be activated. You can close the current panel,  by typing exit in it, which will cause the other panes in the window to adapt and fill the entire space.  If you dont have any other panes in the window, typing exit will close that window and if it’s the last  window, it will close tmux and return to the session that launched it.

Advanced usage

What happens under the hood is actually a bit more complicated. Tmux runs in a client-server mode, where each time you launch tmux a new sessions is created and the client is attached to that session. This gives you quite a bit of flexibility since you can “detach” the client from a certain session and let it run in background and then later re-attach to it and continue where you left off, having all the windows and panes saved in the same state. In order to detach from the current session hit the control key + d:CTRL-B + D

After you have detached from a session you are returned back in the session that launched tmux.
You can type:

# tmux  list-sessions

and this will give you a list of currently active sessions like the one below. Note that the left most
number is the session ID, which you can use to attach back to that session. This output also gives
some information about the running sessions, such as number of windows, date created, size, etc.

Currently active tmux sessions
Currently active tmux sessions

In order to attach back to a running session, look at the id of that session in the output above and
type (change the 0 to the id of the desired session):

#tmux attach -t 0

and this will bring you back to the same state that you left of, with the exact same window and panes
arrangement.

Scripting in tmux

A really powerfull feature of tmux is that you can write scripts for it. I won’t go into details about that and the man page provides pretty good description of the commands and options you can use.

RPM Package Manager & YUM

RPM Package Manager 

* rpm -(RedHat Package Manager) provide package management

* RPM package can be installed on - RedHat, Centos, Fedora, Suse & Mint

* DEB package can be installed on - Ubuntu, Boss, Debien, kalilinux.

* .tar & .bin is for the both types of OS.

* Package explaination.

Ex : RealPlayer11.1.x86.rpm

1.   RealPlayer > Package name.

2.  11 > Version

3.  .1 > Update

4.  x86  > Architecher.

5.   .rpm  > extention.

the 5 major task performed by rpm are -

1. Query

2. Verify

3. Installation

4. Upgrade

5. Uninstalation


I. QUERY

*Query : - Means consult the local rpm database to determine the package is installed os well as Query packages that have been downloaded locally  or on local media i.e cdrom or dvd.

1. rpm -qa     (dumps all installed packages from rpm database)

option 'a' will display installed packages on the system rpm mantioned database of all installed packages.

2. rpm -qa  |wc -l   ( Provide a count of installed number of packages)

3. rpm -qa  |grep -i package name  (To search a particular package and if you are unsure about exact naem of package the use option - this will  tell if any package will install.)

4. rpm -ql  packagename

5. rpm -qi  packagename   (This will give information about package as its recorded in the local rpm database. Each package is signed by Redhat. Evry package is having
licens, key ID , Size and package, url etc. RPM verify package automatically using GPG, MD5, SHA1 SUMS.)

6. rpm -qf  path of the package  (this will display package membership information for the nano file.)

ex - rpm -qf  /usr/bin/which
       rpm  -qf /bin/grep

7. We can query a package before its install. we can down load a package and query directly

 rpm   -qi http://192.168.1.254/rh5/i386/server/dhcp  (this will give information about the 'dhcp' package which resides on the http repository while  the query of installed package is through local RPM database. The option give info like - Name, Version, Release date, Build date, Size, License, URL, Group,[to which group belong], Summary etc.)

-h (hash) >> This will print hash marks,
-v ( verbose)>> This will print package name.

8.  rpm -qa  --last  (This will give the last installed package informations)

9. rpm  -F  package name  (freshen / Repair the package)


II. VERIFY

:- Verify filesystem contents against installed package in RPM database.

1. #rpm -Va (verify allpackages on the system, returning info only, if there are discreption from the orignal installation.)

-V >> verify a rpm which is on local DB, or remote package on filesystem or remote filesystem such on http accessible location.

-a >> will display installed packages on system.

-f >> verify the package that the file belongs to.

2. #rpm -Va  http

If no. O/P comes it means it pass the test

#echo $?

where  '0'  means no error

#rpm  -Vf    /usr/bin/nano

#seq  100000  > nano

This will temper the nano file, now run -

#rpm  -Vf    /usr/bin/nano

SM5  .... T   /usr/bin/nano

> S (file size) means file size is changed what is in the database local RPM databse.

> M (Mode or permission)  means mode or permission have changed, might be previous its having 755, now may be its have 455.

> 5  (MD5) means MD5 no longer checks out

>T  (Modification time) means modification time is no longer the same what recorded in RPM database

> L  (Sym link) means Symlink error.

> D (Device ) means device problem such as wrong device name, missing device,

> ?  Means RPM is unable to read the file

> U discrepency with user owner

> G  discrepency with Group owner

> C  Configuration file

Note: If test fails, one of the following will be returned.

#ech $?

> 1  (This means file is having issue, So we can verify any file by prm if its changed.)

#rpm  -ql  nano

This will display contents of nano package or display all included files which also include any directory created by the package.

* The options for rpm divided into 3 different sections

1. Query options (with -q) :-

> c - Lists all config files

> d - Lists all documentation files.

> i - Display information about the package

> l  - list the files in a package

2. Verify options (with -V) : -

> a - Queries all packages.

> f -  Display information about the specified file.

3. Install/upgrade/Remove options :

> -e - Remove a given package.

> -i  - Install a given package.

> -h - show hash progress when installing.

> -U  - Upgrades a given package.

> -V - Provides Verbose output.


* To download nao package from web from command line , we can use  wget commad: -

#wget  http://www.nano-editor.rog/dist/v2.2/RPMS/nano.rpm

*Even if you need to grab a remote RPM package, we can still use wget utility.

#rpm  -qc  rsyslog (To find all config files)

#rpm -qd  rsyslog (To find documentation files for a given package.)

#rpm -ql   rsyslog (Provide a listing of a files that come with the package)

#rpm -qR  rsyslog (Find out wheather a package has any dependencies)

* You don't want to go thorugh the trouble of uninstalling the package first only to reinstall it. You can use the "--replacepkgs" option :-

#rpm - ivh  --replacepkgs  rsyslog

* While quering use option  '-q' if you know exact name of the package but if hou don't know exact name you get no result, so don't use only  '-q' option while quering use  '-qi' , '-ql', '-qa', or '-qf'

III. Install

:- It does not overwrites previous packages.

Note: use this metthode to install a new version of the kernel.

#rpm -ivh dhcp-3.0.5-7.el5.i386.rpm

#rpm -qi  dhcp

#rpm -ql  dhcp (Display files in the packages)

#rpm  -qa  |grep -i  rsyslog

#echo $?

> If comes 1 then packge not installed.

#which   rsyslog

#rpm   -qf   /usr/bin/rsyslog

IV. UPGRADE

:- It  installs or overwrites existing packages.

#rpm   -Uvh  dhcp-3.0.5-7.el5.i386.rpm

*Freshen :- (update an existing packages)

Note: Freshen will not install package if it does not exits locally.

#rpm -Fvh    (Fresh the current version of the package)

rpm  -F  >> only installs the new package if earlier version exists, the old versionwill removed.


V. REMOVAL

#rpm  -ev  rsyslog (remove the package)

Note: - Removal process considers dependencies and will complain if the removal will break or more package. To resolve this use  "--nodeps" option.

#rpm -ev  --nodeps  rsyslog


Note :  Bydefault the gpg-eky that use to sign the packages have not been imported to the rpm database, we need to import key, that's why we saw no-key  when package installed.

* Import Redhat RPM-GPG-key to confirm package signatures: -

#rpm --import  http://192.168.75.100/linux/Misc/RHEL6/RPM-GPG-KEY-redhat-release

> Now if we install any package it will not show no key in O/p.

> To check key -

#rpm  -qa    gpg-pubkey*

> This will show wheather key is installed or not.

#rpm -qi  gpg-pubkey*

                                            YUM CONFIGURATION
                                ************************************
:- The yum command has access to repositories where tons of packages are kept and can install, pugrade or remove them  automatically. Yum alos take care of resolving and installing any dependencies.

* Yum is an xml file. It resolve the dependancy. It is a front panal of RPM.

*YUM > Yellow-dog  Updage Modifir.

* There is two type of YUM - yum-server & yum-client.

* Configuration file - /etc/yum.repos.d/
-----------------------------------------------------------------
Syntax : yum  [options]  command

> Options :

-c  > Specifies the location of the config file.

-y  > Indicates to always answer yes to prompts

-v  > Provide verbose O/p

> Commands :

clean > removes cached data

erase > Removes a package from the system.

grouplist > Displays availbale package groups.

groupinstall > Installs the packages within a group.

info >  Display information about a package.

install > Install a package on the system.

search > Enable you to search for a package.

update > Update a package.

* Now we will see that how to configure a software  repository through  "yum" and Install & Uninstall software.

> In the RedHat DVD there is a directory by the name of Package. The all rpm can be find in this directory given by RedHat. There is a file in 'Package' directory by the name of  "RPM-G86-KEY-redhat-release". The all rpm in the pakcage directory is singned  by RedHat and for the Signature Verification this file is being used.

> Yum provides us  secure pakcage management feature, means the software will be installed only if there "key RPM-GPG-KEY" is match with the key file. This is a way to ensure your software before completely install in your system that this package/software has been not  modifyed and its completely geniune before install the software.

Steps to create YUM.

1. first of all we will insert the DVD of RHEL in the system and mount in to the system on any mounting point.

#mount /dev/cdrw  /mnt

#cd /mnt

#ls

2. Copy all the file/dir from mount point of DVD into /var/ftp/pub

#cp  -avr    *    /var/ftp/pub

* Where - a - all

v - verbose

r  -Recursive  (Recursive, we use because all the directory & sub directory and all the content of  these file/dir copy on target.)

3. creat a configuration file in "/etc/repos.d/" by any name but extention must be  ".repo"

4. To Configue "YUM" the global configuration file of yum is > "/etc/yum.conf"

#cat  /etc/yum.conf

* In this file '/etc/yum.conf' there is a main section on the top,
------------------------------------------------------------------------------

To see what particular versions are available to you via yum you can use the

"--showduplicates switch."

$ yum --showduplicates list httpd | expand

Loaded plugins: fastestmirror, langpacks, refresh-packagekit

Loading mirror speeds from cached hostfile

 * fedora: mirror.steadfast.net
 * rpmfusion-free: csc.mcs.sdsmt.edu
 * rpmfusion-free-updates: csc.mcs.sdsmt.edu
 * rpmfusion-nonfree: csc.mcs.sdsmt.edu
 * rpmfusion-nonfree-updates: csc.mcs.sdsmt.edu
 * updates: mirror.steadfast.net

Available Packages
httpd.x86_64                        2.4.6-6.fc20                         fedora
httpd.x86_64                        2.4.10-1.fc20                        updates

As far as installing a particular version? You can append the version info to the name of the package like so:

EX- $ sudo yum install -

For example in this case if I wanted to install the older version, 2.4.6-6 I'd do the following:

$ sudo yum install httpd-2.4.6-6

You can also include the release info when specifying a package. In this case since I'm dealing with Fedora 20 (F20) the release info would be "fc20", and the architecture info too.

$ sudo yum install httpd-2.4.6-6.fc20

$ sudo yum install httpd-2.4.6-6.fc20.x86_64
repoquery

If you're ever unsure that you're constructing the arguments right you can consult with repoquery too.

$ repoquery --show-duplicates httpd-2.4*

httpd-0:2.4.6-6.fc20.x86_64
httpd-0:2.4.10-1.fc20.x86_64
downloading & installing

You can also use one of the following options to download a particular RPM from the web, and then use yum to install it.

$ yum --downloadonly

-or-

$ yumdownloader

And then install it like so:

$ sudo yum localinstall

What if I want to download everything that package X requires?

$ yumdownloader --resolve

Example

$ yumdownloader --resolve vim-X11

Loaded plugins: langpacks, presto, refresh-packagekit
Adding en_US to language list
--> Running transaction check
---> Package vim-X11.x86_64 2:7.3.315-1.fc14 set to be reinstalled
--> Finished Dependency Resolution
vim-X11-7.3.315-1.fc14.x86_64.rpm                              | 1.1 MB     00:01
Notice it's doing a dependency check, and then downloading the missing pieces. See my answer that covers it in more details here: How to download a file from repo, and install it later w/o internet connection?.

Get yum to install a specific package version

*There are two ways to download a package without installing it.One is using the "downloadonly" plugin for yum, the other is using "yumdownloader" utility.

Downloadonly plugin for yum
-------------------------------------
1.Install the package including "downloadonly" plugin:

(RHEL5)

# yum install yum-downloadonly

(RHEL6)

# yum install yum-plugin-downloadonly

2.Run yum command with "--downloadonly" option as follows:

# yum install --downloadonly --downloaddir=

3.Confirm the RPM files are available in the specified download directory.

Note:

•Before using the plugin, check /etc/yum/pluginconf.d/downloadonly.conf to confirm that this plugin is "enabled=1"

•This is applicable for "yum install/yum update" and not for "yum groupinstall". Use "yum groupinfo" to identify packages within a specific group.

•If only the package name is specified, the latest available package is downloaded (such as sshd). Otherwise, you can specify the full package name and version (such as httpd-2.2.3-22.el5).

•If you do not use the --downloaddir option, files are saved by default in /var/cache/yum/ in rhel-{arch}-channel/packages

•If desired, you can download multiple packages on the same command.

•You still need to re-download the repodata if the repodata expires before you re-use the cache. By default it takes two hours to expire.

Yumdownloader

If downloading a installed package, "yumdownloader" is useful.

1.Install the yum-utils package:

# yum install yum-utils

2.Run the command followed by the desired package:

# yumdownloader

Note:
•The package is saved in the current working directly by default; use the --destdir option to specify an alternate location.

•Be sure to add --resolve if you need to download dependencies

Description of DNS-Server


Introduction to DNS Records

> The Domain Name System (DNS) is the Internet’s address book. DNS directs web traffic to your Linode and email to your inbox by mapping memorable domain names like example.com to IP addresses like 12.34.56.78 or 0123:4567:89ab:cdef:0123:4567:89ab:cdef. This guide introduces basic DNS concepts and the different types of DNS records.

> How DNS Works ? 

Before adding any DNS records, you should learn the basics of DNS. You’ll start by dissecting a domain name, and then you’ll learn about the mechanics of DNS resolution, including name servers, zone files, and individual DNS records.

>Domain Names

Domain names are best understood by reading from right to left. The broadest domain classification is on the right, and become more specific as you move to the left. In the examples below, the top-level domain, or TLD, is .com.

1. example.com
2. mail.hello.example.com

Every term to the left of the TLD and separated by a period is considered a more specific subdomain, although conventionally, first-level subdomains plus their TLDs (example.com) are referred to as “domains.” Moving to the left, hello and mail are the second- and third-level subdomains, respectively. Typically, subdomains are used to uniquely identify specific machines or services, but this is left up to the domain owner.

> Name Servers

Choosing and specifying name servers is an essential part of domain ownership. If you don’t, the Internet won’t know where to find your DNS information, and your domain won’t resolve. Name servers host a domain’s DNS information in a text file called the zone file. They’re are also known as Servers of Authority (SOAs). You can host your DNS information on name servers in one of several locations:

* Linode (recommended)
* Your registrar
* Your own DNS server
* Third-party DNS hosting

Using Linode’s free name servers is the easiest approach, because Linode provides a default zone file with all the right IP addresses for your website and email. For basic DNS setups and many advanced ones, Linode’s name servers will work beautifully. However, you can also look into the options offered by your registrar and third-party DNS hosts, or host your own DNS if you want to take control of as much of the DNS process as possible.

You’ll specify name servers on your domain registrar’s website. They’ll take care of publishing that information to the higher-level name servers. You’ll want to specify at least two name servers. That way, if one of them is down, the next one can continue to serve your DNS information.

DNS Records and Zone Files

The next aspect of DNS management is specifying DNS records, which actually match domain names to IP addresses. The DNS records are then automatically bundled up into a zone file, which is what allows the Internet to look up the correct IP address for your domain. If you decide to use Linode’s name servers, our DNS Manager will help you create a default zone file. It contains records similar to the following:

1. ; example.com [448369]
2. $TTL 86400
3. @   IN  SOA ns1.linode.com. admin.example.com. 2013062147 14400 14400 1209600 86400
4. @       NS  ns1.linode.com.
5. @       NS  ns2.linode.com.
6. @       NS  ns3.linode.com.
7. @       NS  ns4.linode.com.
8. @       NS  ns5.linode.com.
9. @           MX  10  mail.example.com.
10. @           A   12.34.56.78
11. mail        A   12.34.56.78
12. www      A   12.34.56.78

Every domain’s zone file contains the admin’s email address, the name servers, and the DNS records. Of course, you are not limited to these default entries. You can create a variety of DNS records for as many different subdomains as you wish. To learn how to add individual DNS records using the DNS Manager, read this article.

DNS Resolution

So how does DNS actually work? First, the domain name needs to get translated into your Linode’s IP address. DNS matches human-friendly domain names like example.com to computer-friendly IP addresses like 12.34.56.78. This happens in a special text file called a zone file, which lists domains and their corresponding IP addresses (and a few other things). A zone file is a lot like a phone book that matches names with street addresses.

Here’s how the DNS lookup process works:

1.You type a domain name like example.com in to the address bar.
2.Your computer connects to the Internet through an Internet Service Provider (ISP).
3.The ISP’s DNS resolver queries a root nameserver for the proper TLD nameserver. In other words, it asks the root nameserver, “Where can I find the nameserver for .com domains?”
4. The root nameserver responds with the IP address for the .com nameserver.
5. The ISP’s DNS resolver visits the .com nameserver, using the IP address it got from the root nameserver. It asks the .com nameserver, “Where can I find the nameserver for example.com?”
6. The .com nameserver responds with the IP address for the example.com nameserver.
7. The ISP’s DNS resolver visits your domain’s nameserver and reads the zone file.
8. The zone file shows which IP address goes with the domain.
9. Now that the ISP has the IP address for example.com, it connects you to your Linode.
10.Apache handles everything after that, ensuring that the correct files and folders get displayed in your visitor’s browser.



The scenario described above is what happens if the ISP has no current information about the requested domain. In actuality, ISPs cache a lot of DNS information after they’ve looked it up the first time. This results in faster lookups and less strain on DNS servers. Usually caching is a good thing, but it can be a problem if you’ve recently made a change to your DNS information, like when you move to Linode from a different hosting provider. In those cases, you’ll want to pay attention to your zone file’s time to live (TTL) so that your DNS change happens as quickly as possible.

Types of DNS Records

A and AAAA

An A record matches up a domain (or subdomain) to an IP address. In other words, it points your domain name to your Linode’s IP address, which allows web traffic to reach your Linode. This is the core functionality of DNS. A typical A record looks like the following:

1. example.com     A       12.34.56.78

You can also make A records for subdomains you want to direct to your server:

1. hello.example.com       A       12.34.56.78

You can point different subdomains to different IP addresses.

If you want to point every subdomain of example.com to your Linode’s IP, you can use an asterisk (***) as your subdomain:

1 *.example.com   A       12.34.56.78

An AAAA record is just like an A record, but for IPv6 IP addresses. A typical AAAA record looks like the following:

1 example.com     AAAA        0123:4567:89ab:cdef:0123:4567:89ab:cdef

AXFR

An AXFR record is a type of DNS record used for DNS replication, although there are also more modern ways to do DNS replication. AXFR records are not used in ordinary zone files. Rather, they are used on a slave DNS server to replicate the zone file from a master DNS server. For an example of how to configure Linode’s nameservers as slave DNS servers using AXFR, visit this guide about configuring DNS on cPanel.

CNAME

A CNAME record or Canonical Name record matches up a domain (or subdomain) to a different domain. With a CNAME record, DNS lookups use the target domain’s DNS resolution as the alias’s resolution. Here’s an example:

1 alias.com       CNAME   example.com.
2 example.com     A       12.34.56.78

With this setup, when alias.com is requested, the initial DNS lookup will find the CNAME entry with the target of example.com. A new DNS lookup will be started for example.com, which will find the IP address 12.34.56.78. Finally, visitors to alias.com will be directed to 12.34.56.78.

CNAME records exist so that domains can have aliases. You should not use a CNAME record for a domain that gets email, because some mail servers handle mail oddly for domains with CNAME records. Likewise, MX records cannot reference CNAME-defined hostnames. Also, the target domain for a CNAME record should have a normal A-record resolution. Chaining or looping CNAME records is not recommended.

In some cases, a CNAME record can be an effective way to redirect traffic from one domain to another while keeping the same URL. However, keep in mind that a CNAME record does not function the same way as a URL redirect. A CNAME record directs web traffic for a particular domain to the target domain’s IP address. Once the visitor reaches that IP address, the local Apache (or other web server) configuration will determine how the domain is handled. If that domain is not configured on the server, the server will simply display its default web page (if any). This may or may not be the web page for the target domain in the CNAME record, depending on how the server is configured.

DKIM

A DKIM record or domain keys identified mail record displays the public key for authenticating messages that have been signed with the DKIM protocol. This practice increases the capability to check mail authenticity. A typical DKIM record looks like the following:

1 selector1._domainkey.example.com        TXT     k=rsa;p=J8eTBu224i086iK

DKIM records are implemented as text records. The record must be created for a subdomain, which has a unique selector for that key, then a period (.), and then _domainkey.example.com. The type is TXT, and the value includes the type of key, followed by the actual key.

MX

An MX record or mail exchange record sets the mail delivery destination for a domain (or subdomain). A typical MX record looks like the following:

1 example.com         MX      10  mail.example.com.
2 mail.example.com    A           12.34.56.78

The above records direct mail for example.com to the mail.example.com server. The target domain (mail.example.com above) needs to have its own A record that resolves to your Linode. Ideally, an MX record should point to a domain that is also the hostname for its server.

Your MX records don’t necessarily have to point to your Linode. If you’re using a third-party mail service, like Google Apps, you should use the MX records they provide.

Priority is another component of MX records. This is the number written between the record type and the target server (10 in the example above). Priority allows you to designate a fallback server (or servers) for mail for a particular domain. Lower numbers have a higher priority. Here’s an example of a domain that has two fallback mail servers:

1 example.com         MX      10  mail_1.example.com
2 example.com         MX      20  mail_2.example.com
3 example.com         MX      30  mail_3.example.com

In this example, if mail_1.example.com is down, mail will be delivered to mail_2.example.com. If mail_2.example.com is also down, mail will be delivered to mail_3.example.com.

NS

NS records or name server records set the nameservers for a domain (or subdomain). The primary nameserver records for your domain are set both at your registrar and in your zone file. Typical nameserver records (you need at least two) look like this:

1 example.com     NS      ns1.linode.com.
2 example.com     NS      ns2.linode.com.
3 example.com     NS      ns3.linode.com.
4 example.com     NS      ns4.linode.com.
5 example.com     NS      ns5.linode.com.

The nameservers you designate at your registrar then carry the zone file for your domain.

You can also set up different nameservers for any of your subdomains. Subdomain NS records get configured in your primary domain’s zone file. For example, if you’re using Linode’s nameservers, you could configure separate NS records in your Linode zone file for the subdomain mail.example.com as shown below:

1 mail.example.com    NS      ns1.nameserver.com
2 mail.example.com    NS      ns2.nameserver.com

Primary nameservers get configured at your registrar; secondary subdomain nameservers get configured in the primary domain’s zone file. The order of NS records does not matter; DNS requests are sent randomly to the different servers, and if one host fails to respond, another one will be queried.

PTR

A PTR record or pointer record matches up an IP address to a domain (or subdomain), allowing reverse DNS queries to function. It performs the opposite service an A record does, in that it allows you to look up the domain associated with a particular IP address, instead of vice versa.

PTR records are usually set with your hosting provider. They are not part of your domain’s zone file. This means that you’ll always set reverse DNS for your Linodes in the Linode Manager, even if your nameservers are elsewhere. Likewise, if you have servers somewhere else but are using Linode’s nameservers, you will still have to set up your PTR records with your hosting provider.

As a prerequisite for adding a PTR record, you need to create a valid, live A or AAAA record that points the desired domain to that IP. If you want an IPv4 PTR record, point the domain (or subdomain) to your Linode’s IPv4 address. If you want an IPv6 PTR record, point the domain to your Linode’s IPv6 address. Beyond that, IPv4 and IPv6 PTR records work the same way.

For instructions on setting up reverse DNS on your Linode, see our Reverse DNS guide.

It’s possible to have different IPs (including both IPv4 and IPv6 addresses) that have the same domain set for reverse DNS. To do this, you will have to configure multiple A or AAAA records for that domain that point to the various IPs.

SOA

An SOA record or Start of Authority record labels a zone file with the name of the host where it was originally created. Next, it lists the contact email address for the person responsible for the domain. There are also various numbers, which we’ll get into in detail in a moment. First, here’s a typical SOA record:

1 @   IN  SOA ns1.linode.com. admin.example.com. 2013062147 14400 14400 1209600 86400

The administrative email address is written with a period (.) instead of an at symbol (<@>).
Here’s what the numbers mean:

Serial number: The revision number for this domain’s zone file. It changes when the file gets updated.

Refresh time: The amount of time (in seconds) a secondary DNS server will keep the zone file before it checks for changes.

Retry time: The amount of time a secondary DNS server will wait before retrying a failed zone file transfer.

Expire time: The amount of time a secondary DNS server will wait before expiring its current zone file copy if it cannot update itself.

Minimum TTL: The minimum amount of time other servers should keep data cached from this zone file.

The single nameserver mentioned in the SOA record is considered the primary master for the purposes of Dynamic DNS and is the server where zone file changes get made before they are propagated to all other nameservers.

SPF

An SPF record or Sender Policy Framework record lists the designated mail servers for a domain (or subdomain). It helps establish the legitimacy of your mail server and reduces the chances of spoofing, which occurs when someone fakes the headers on an email to make it look like it’s coming from your domain, even though the message did not originate from your Linode. Spammers sometimes try to do this to get around spam filters. An SPF record for your domain tells other receiving mail servers which outgoing server(s) are valid sources of email, so they can reject spoofed email from your domain that has originated from unauthorized servers. A very basic SPF record looks like the following:

1 example.com   TXT     "v=spf1 a ~all"

In your SPF record, you should list all the mail servers from which you send mail, and then exclude all the others. Your SPF record will have a domain or subdomain, type (which is TXT, or SPF if your name server supports it), and text (which starts with “v=spf1” and contains the SPF record settings).

If your Linode is the only mail server you use, you should be able to use the example record above. With this SPF record, the receiving server will check the IP addresses of both the sending server and the IP address of example.com. If the IPs match, the check passes. If not, the check will “soft fail” (i.e., the message will be marked but will not automatically be rejected for failing the SPF check).

Make sure your SPF records are not too strict. If you accidentally exclude a legitimate mail server, its messages could get marked as spam. We strongly recommend visiting openspf.org to learn how SPF records work and how to construct one that works for your setup. Their examples are also helpful.

SRV

An SRV record or service record matches up a specific service that runs on your domain (or subdomain) to a target domain. This allows you to direct traffic for specific services, like instant messaging, to another server. A typical SRV record looks like the following:

1 _service._protocol.example.com  SRV     10      0       5060    service.example.com

Here’s a breakdown of the elements in an SRV record:

Service: The name of the service must be preceded by an underscore (_) and followed by a period (.). The service could be something like _xmpp.

Protocol: The name of the protocol must be proceeded by an underscore (_) and followed by a period (.). The protocol could be something like _tcp.

Domain: The name of the domain that will receive the original traffic for this service.

Priority: The first number (10 in the example above) allows you to set the priority for the target server. You can set different targets with different priorities, which allows you to have a fallback server (or servers) for that service. Lower numbers have a higher priority.

Weight: If two records have the same priority, weight is used instead.

Port: The TCP or UDP port on which the service runs.

Target: The target domain or subdomain. This domain must have an A or AAAA record that resolves to an IP address.

An example use of SRV records would be to set up Federated VoIP.

TXT

A TXT record or text record provides information about the domain in question to other resources on the Internet. It’s a flexible type of DNS record that can serve many different purposes depending on the specific contents. One common use of the TXT record is to create an SPF record on nameservers that don’t natively support SPF. Another use is to create a DKIM record for mail signing.

VNC SERVER

VNC SERVER CONFIGURATION

package  - vnc-server

service - vncserver

config file - /etc/sysconfig/vncserver

port no. - 5801, 5802
----------------------------------------------------

Configuration of VNC-SERVER on RHEL-5

> Install the packag of vnc

#yum install vnc-server

> Configure the configuration file (/etc/sysconfig/vncservers) edit the line.

Ex : - # VNCSERVERS="2:myusername"

VNCSERVERS="2:root 3:ram"         [Per user display no. :2 :3 :4 etc can be any thing]

VNCSERVERARGS[2]="-geometry 800x600" [The display size of the user 2,3,4]

VNCSERVERARGS[3]="-geometry 800x600"

: wq (save the file)

> creat a local user  "tom "

#adduser tom

#passwd tom
XXX
XXX [This is the local password of user tom.]

> Creat password to access the vnc server by running below command.

#su - tom

#vncserver

Password : xxxx
: xxxx [Vnc password]

> Same for root user

#su - root
#vncserver

Password : xxxx
: xxxx

> While running command 'vncserver' to generate the vnc login password , apart of this command also generate a 'gnome' environment for the user.

Ex: - "Xauth : creating new authority file /home/ram/.Xauthority"

> After that 'vncserver' command also creat a scripting file under user home directory , under
.VNC/xstartup, which run while accessing remotly from the vncviewer to take a gnome enviro-
nment.

Ex:- "Creating default startup script /home/ram/.vnc/xstartup"

> Configure the scripting file /home/ram/.vnc/xstartup

#vim  /home/ram/.vnc/xstartup

> Uncomment the following two lines for normal desktop:

# unset SESSION_MANAGER  [delet # singh]

# exec /etc/X11/xinit/xinitrc [delet # singh]

:wq [save the file after uncomentig these two line]

history command with Date & Time


> How to show date and time in your history command using environment  variable HISTTIMEFORMAT

commands > history

It usually happens with me that I am trying out a cli based tool or learnt some new trick, it works fine then, but later I can hardly recall what I did . In such cases, all I remember is either a part of the command or the time while I was doing it. I always wondered if we could get more out of the history command - days, time etc. After searching a little, I found that it is actually possible and could be done pretty easily.

Its all in the genius of Bash . All you have to do is set the environment variable, HISTTIMEFORMAT, appropriately. Lets take an example where I just want to so the timestamp.

[shredder12]$ export  HISTTIMEFORMAT="%T "

[shredder12]$ history

 568  13:53:01 clear
 569  13:53:03 top
 570  13:53:07 sudo fdisk -l
 571  13:53:16 free -m
 572  13:53:17 cd
 573  13:53:18 ls
 574  13:53:22 cd Downloads/

Similary, for date you can use the following parameters

%d for Day
 %m for Month
 %y for Year

So, if you want both date and time stamp

[shredder12]$ export HISTTIMEFORMAT="%d/%m/%y %T "

[shredder12]$ history

568  25/10/10 13:53:01 clear
 569  25/10/10 13:53:03 top
 570  25/10/10 13:53:07 sudo fdisk -l
 571  25/10/10 13:53:16 free -m
 572  25/10/10 13:53:17 cd
 573  25/10/10 13:53:18 ls
 574  25/10/10 13:53:22 cd Downloads/

Please note that, for a permanent setting you will have to append the "export" line in ~/.bashrc file.

Great tip. For better sort-ability, I used year/month/day:
export HISTTIMEFORMAT="%y/%m/%d %T "

Colorful Linux Terminal

Lolcat – A Command Line Tool to Output Rainbow Of Colors in Linux Terminal

> For those who believe that Linux Command Line is boring and there isn’t any fun, then you’re wrong here are the articles on Linux, that shows how funny and naughty is Linux..

>Here in this article, I will be discussing about a small utility called “lolcat” – Which produce rainbow of colors in  terminal.

>What is lolcat?

> Lolcat is an utility for Linux, BSD and OSX which concatenates like similar to cat command and adds rainbow  coloring to it. Lolcat is primarily used for rainbow coloring of text in Linux Terminal.
Installation of Lolcat in Linux

1.  Lolcat utility is available in the repository of lots of Linux distributions, but the available version bit older. Alternatively you can download and install latest version of lolcat from git repository.

>Lolcat is a ruby gem hence it is essential to have latest version of RUBY installed on your system.

#yum install ruby*

#yum install  rubygem*

> Once ruby package has been installed, make sure to verify the version of ruby installed.

# ruby --version

2.  Next download and install the most recent version of lolcat from the git repository using following commands.

a. # wget    https://github.com/busyloop/lolcat/archive/master.zip

b. # unzip master.zip

c. # cd lolcat-master/bin

d. # gem install lolcat

> Once lolcat is installed, you can check the version.

# lolcat --version

Usage of Lolcat

3. Before starting usage of lolcat, make sure to know the available options and help using following command.

# lolcat -h

4. Next, pipeline lolcat with commands say ps, date and cal as:

Ex. #Command  | lolcat

# ps    | lolcat
# date | lolcat
# cal | lolcat
# netstat -ant |lolcat
# ss a- |lolcat

5. 3. Use lolcat to display codes of a script file as:

# lolcat  service.sh

6. Pipeline lolcat with figlet command. Figlet is a utility which displays large characters made up of ordinary screen characters. We can pipeline the output of figlet with lolcat to make the output colorful as:

# echo I * Tecmint | lolcat

# figlet I Love Tecmint | lolcat

Note: Not to mention that * is an unicode character and to install figlet you have to yum and apt to get the required  packages as:

# yum install figlet

7. Animate a text in rainbow of colors, as:

$ echo I * Tecmit | lolcat -a -d 500

> Where -a =  --animate, -a:   Enable psychedelics
> Where -d = --duration, -d :   Animation duration (default: 12)
> Where -s =  --speed, -s :   Animation speed (default: 20.0)

Ex :  # echo SHANKAR DEO | lolcat -a -d  500 -s  50

>Here the option -a is for Animation and -d is for duration. In the above example duration count is 500.

8. Read a man page (say man ls) in rainbow of colors as:

 # man ls   | lolcat

Note: You can use lolcat with any other command in pipeline and get colored output in terminal.

9. You may create alias for the most frequently used commands to get command output in rainbow of colors. You can alias ‘ls -l‘ command which is used for long list the contents of directory as below.

# alias lolls="ls -l | lolcat"
# lolls

> You may create alias for any command as suggested above. To create permanent alias, you have to add the relevant code (above code for ls -l alias) to ~/.bashrc file and also make sure to logout and login back for the changes to be taken into effect.

10.Command: Cowsay

An ASCII cow in terminal that will say what ever you want. Install Cowsay

root@tecmint:~# apt-get install cowsay (for Debian based OS)
root@tecmint:~# yum install cowsay (for Red Hat based OS)

# cowsay I Love nix

## cowsay I Love nix |lolcat   (for color full cow)

11. Command: cmatrix

You might have seen Hollywood movie ‘matrix‘ and would be fascinated with power, Neo was provided with, to see anything and everything in matrix or you might think of an animation that looks alike Hacker‘s desktop.

Install cmatrix
**************
# yum install cmatrix

#cmatrix

----------------------------------------------------------------------------------------------------------------------

How to Compile a Program in Linux


> Source code is a computer program in human readable form. However, the machine
cannot execute source code. The code must be compiled into machine code before it is
use. On Linux, the "make" build system is the most common one, and this how-to
works for almost all Linux source code packages.

Steps

1. Download the source code for the program or driver from the Internet or other media.
It will most likely be in the form of a "tarball" and have a file extension of .tar, .tar.bz2,
or .tar.gz. Sometimes a .zip file will be used instead however.

2. Unpack the downloaded code:-

 A. for .zip files use - "unzip     your file"
 B. for .tgz or .tar.gz use - "tar -zxvf    yourfile"
 C. for .bz2 use " -  tar -jxvf     yourfile"

a. How untar a  "tar.xz" file ?

Ex : -
#yum install xz
(say Y to the prompt)

#unxz gcc-4.6-20110916.tar.xz
#tar -xvf gcc-4.6-20110916.tar
#xz gcc-4.6-20110916.tar  (gain to zip the tar file)

 or extract your files graphically.

3. In the terminal, move into the newly extracted directory (cd dirName).

4. Run the command "./configure" to configure the source code automatically. Arguments such as " --prefix=" can be used to control the install location. This checks that you have the right libraries and versions

5. Once configured, run "make" which does the actual compiling (this can take anything from a few seconds to many hours).An executable for the program will be created in the bin directory inside
the source code directory.

6. To install the program- run "make install".

7. You have compiled and installed the program source code.

Linux Networking

Linux Networking 

> IP Address
>Subnet Mask
>Gateway
>DNS

eth0       Link encap:Ethernet  HWaddr 00:0C:29:AB:A3:CA
          inet addr:192.168.222.131  Bcast:192.168.222.255  Mask:255.255.255.0

> Packet Type is - Link encap:Ethernet > MAC add. or Physical Address - HWaddr 00:0C:29:AB:A3:CA  > size > 48 Bit. = (24 Bit Vender add. + 24 Bit IANA )

> This work on Layer 2 of OSI model. > Layer 2 also called a data link layer > devices work on layer 2 > Switch, MAC.

> Switch create a MAC Table that is also called  - ARP Table (Address Resulation Protocal Table) to transfer the data directally from source to destination
without brodcasting to all.

>In IP subneting the Network Address and Broadcast Adress is not usable.

192.168.0.0 [Network Address]
192.168.0.1
2
3
4
254
192.168.0.255 [Brodcast Address]

> Network Add of any Subneting is called the name of the that particular Network.

> And Broadcast Address helps to convey the massege to all the ip. If we send any data on the broadcast add, its send that data on all IP.

> IPv4 : 32 Bit Add. > 2^8 > 256 > 0 to 255 = 256 Total IP > But usable only 254. > Also we write-/8 -A, /16 - B, /24 - C Subnet > called CIDR.

> IPv6 : 128 Bit Add.

> Loop back / Localhost/localhost.localdomain  IP > 127.0.0.1

> While pinging the loopback add. we check that our system is network capable or not . if its ping that means or NIC is working fine.

> Q. When we configure same ip on the two system its conflict. But the loop back add is same on all system but still its not conflict. Why ?

> Ans : Loop back add never conflict because, its does not have any broadcast add. Loop back add never broadcast its ip, so no one can
knows about its ip and it does not conflict with other system. We know about any ip while broadcasting, when some network broadcast
their ip then only other system can know its ip  etc.

lo       Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host

> Q.  On a single NIC how many IP we can configure ?

> Ans - On a single NIC all subnet can be configure.

> To creat a virtual NIC we can run these command

[root@server3 ~]# ifconfig eth0:1 192.168.1.5 netmask 255.255.255.0
[root@server3 ~]# ifconfig eth0:2 192.168.1.6 netmask 255.255.255.0
[root@server3 ~]# ifconfig eth0:3 192.168.1.7 netmask 255.255.255.0
[root@server3 ~]# ifconfig eth0:4 192.168.1.8 netmask 255.255.255.0

[Note : But these all are temprory, when we will start the network service or restart the system all the vir. NIC will disconnect automatically. ]

> How we can make it parmanent ?

> Ans : There is two way to make it permanent

1. Run the command > setup > Network Configuration > Device Configuration > New Device  > and creat the new NIC

2. Go to the directory > [root@server3 ~]#cd /etc/sysconfig/network-script/

> cp ifcfg-eth0  eth0:1
> cp ifcfg-eth0  eth0:2
> cp ifcfg-eth0  eth0:3
> cp ifcfg-eth0  eth0:4 [like this we can creat multiple of virtual NIC card]

> Now one by one go into the all new created virtual NIC  and make the below changes -

DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="00:0C:29:AB:A3:CA"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"

1. Change the Device name > DEVICE="eth0"  > DEVICE="eth0:1"

2. If NIC is configured on static then also change the IPADDR & NETMASK after changing the device name.

[Note : The main thing is to be notice in NIC configuration is it's writing style > All the words in the left side is in Capital later and all the right side words is in small later , so do keep in your mind while making any changes in the  NIC configuration file.]

3. After these configuration do not forget to restart the network > [root@server3 ~]# service network restart

*Provide range of IP Address::
-------------------------------------
[root@server3 ~]#vim /etc/sysconfig/network-scripts/ifcfg-eth0-range1

IPADDR_START=192.168.1.1
IPADDR_END=192.168.1.200
CLONENUM_START=10

:wq [Save the file]

[root@server3 ~]# service network restart

Q. CLONENUM_START ?

> CLONENUM_START value specifies starting identifier of alias that will be applied to eth1 interface, in
above example the first 192.168.1.1 will be assigned to eth1:10 alias. The last IP of the range 192.168.1.200
will be applied to eth:210 sub-interface. This is totally easy approach.

* Ifconfig :
------------
This command is number one command in the alphabet of Linux networking. It configures
network interfaces. It features include
• Turning certain network interface on and off.
• Changing interface IP address.
• Changing netmask, MTU and other network parameters of the interface.
• Putting interface into promiscuous mode.

* Promiscuous mode ?
-----------------------------
1) In a network, promiscuous mode allows a network device to intercept and read each
network packet that arrives in its entirety. This mode of operation is sometimes given to a
network snoop server that captures and saves all packets for analysis (for example, for
monitoring network usage).
----------------------------------------------------------------------------------------------------------------------
Q. How to configure Static Ethernet network connection in Linux ?

> go to the file "/etc/sysconfig/network-scripts/ifcfg-eth0" and change the
configurations - IP, Netmask, DNS, GATEWAY,

[root@server1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

> After installing CentOS we want to configure IP address. CentOS is mostly used as Server.
So we want to give it a static IP address. By default CentOS interface is configured to  receive IP from DHCP server. Here We will see how to configure static IP address in  CentOS system.

> Configure Static IP Address in CentOS

The following steps will show the configurations of static IP address in CentOS machine.

1.Files needed for network configuration are under /etc/sysconfig/network-scripts. So open the file with VIM, VI, or nano etc,

2.We will see default configuration like this,

DEVICE=eth0
HWADDR=00:27:0e:0c:70:9b
TYPE=Ethernet
UUID=25a7bad9-616a-48a0-ace5-52aa0af9fdb7
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=dhcp

3.Now change the configuration to this,

# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.1.255
HWADDR=00:27:0e:0c:70:9b
IPADDR=192.168.1.10
IPV6INIT=no
IPV6_AUTOCONF=no
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
GATEWAY=192.168.1.1
DNS2=4.2.2.2
DNS1=8.8.8.8
TYPE=Ethernet
USERCTL=no
[root@server1 ~]#

4. Then save the file,  with :wq 

5. Now restart the network services by issuing the command,

[root@server1 ~]#service network restart

6. To verify the IP address issue the following command

[root@server1 ~]# ifconfig

You will then see following information,

eth0      Link encap:Ethernet  HWaddr 00:27:0E:0C:70:9B
          inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::227:eff:fe0c:709b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3568 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3025 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1167465 (1.1 MiB)  TX bytes:746010 (728.5 KiB)
          Interrupt:50 Base address:0xe000


7. After configuring IP address now let’s configure DNS. Name server or DNS information
is stored in different file. The location is, "/etc/recolv.conf. "using editor to configure DNS
information,

[root@server1 ~]# vim /etc/resolv.conf

; generated by /sbin/dhclient-script
nameserver 192.168.1.10
nameserver 8.8.8.8

:wq  (save the file )

The name server IP address can be different depending on your network scenario.
Now save the file and exit. We can test the configuration by issuing ping command.

[root@server1 ~]# ping www.google.com

PING www.google.com (216.58.220.4) 56(84) bytes of data.
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=1 ttl=55 time=31.0 ms
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=2 ttl=55 time=30.9 ms
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=3 ttl=55 time=32.0 ms

If you get the reply, you have successfully configured the IP address and DNS information.


8. After configuring DNS Name Server now we will configure "GATEWAY" from file location "/etc/sysconfig/network".

[root@server1 ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
GATEWAY=192.168.1.1
HOSTNAME=server1.deo.com
[root@server1 ~]#

:wq (save the file before exit)

9. After configuring GATEWAY we will configure the host name from file location "/etc/hosts"

[root@server1 ~]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
192.168.1.10    server1.deo.com    server1

:wq  (save the file )

> After all the configuration once again restart the network

[root@server1 ~]# service network restart
----------------------------------------------------------------------------------------------------------------------
eth0-Configuration on Linux 

Q. How to configure Static Ethernet network connection in Linux ?

* go to the file "/etc/sysconfig/network-scripts/ifcfg-eth0" and change the
configurations - IP, Netmask, DNS, GATEWAY,

[root@server1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

*After installing CentOS we want to configure IP address. CentOS is mostly used as Server.
So we want to give it a static IP address. By default CentOS interface is configured to
receive IP from DHCP server. Here We will see how to configure static IP address in
CentOS system.

* Configure Static IP Address in CentOS

The following steps will show the configurations of static IP address in CentOS machine.

1.Files needed for network configuration are under /etc/sysconfig/network-scripts. So open the file with VIM, VI, or nano etc,

2.We will see default configuration like this,

DEVICE=eth0
HWADDR=00:27:0e:0c:70:9b
TYPE=Ethernet
UUID=25a7bad9-616a-48a0-ace5-52aa0af9fdb7
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=dhcp

3.Now change the configuration to this,

# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.1.255
HWADDR=00:27:0e:0c:70:9b
IPADDR=192.168.1.10
IPV6INIT=no
IPV6_AUTOCONF=no
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
GATEWAY=192.168.1.1
DNS2=4.2.2.2
DNS1=8.8.8.8
TYPE=Ethernet
USERCTL=no
[root@server1 ~]#

4. Then save the file,  with :wq

5. Now restart the network services by issuing the command,

[root@server1 ~]#service network restart

6. To verify the IP address issue the following command

[root@server1 ~]# ifconfig

You will then see following information,

eth0      Link encap:Ethernet  HWaddr 00:27:0E:0C:70:9B
          inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::227:eff:fe0c:709b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3568 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3025 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1167465 (1.1 MiB)  TX bytes:746010 (728.5 KiB)
          Interrupt:50 Base address:0xe000


7. After configuring IP address now let’s configure DNS. Name server or DNS information
is stored in different file. The location is, "/etc/recolv.conf. "using editor to configure DNS
information,

[root@server1 ~]# vim /etc/resolv.conf

; generated by /sbin/dhclient-script
nameserver 192.168.1.10
nameserver 8.8.8.8

:wq  (save the file )

The name server IP address can be different depending on your network scenario.
Now save the file and exit. We can test the configuration by issuing ping command.

[root@server1 ~]# ping www.google.com

PING www.google.com (216.58.220.4) 56(84) bytes of data.
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=1 ttl=55 time=31.0 ms
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=2 ttl=55 time=30.9 ms
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=3 ttl=55 time=32.0 ms

If you get the reply, you have successfully configured the IP address and DNS information.


8. After configuring DNS Name Server now we will configure "GATEWAY" from file location "/etc/sysconfig/network".

[root@server1 ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
GATEWAY=192.168.1.1
HOSTNAME=server1.deo.com
[root@server1 ~]#

:wq (save the file before exit)

9. After configuring GATEWAY we will configure the host name from file location "/etc/hosts"

[root@server1 ~]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
192.168.1.10    server1.deo.com    server1

:wq  (save the file )

* After all the configuration once again restart the network

[root@server1 ~]# service network restart
----------------------------------------------------------------------------------------------------------------------

CentOS Linux: Add Static Routing

> We can use any one of the following command line utility to add, delete, display, or manipulate the Linux kernel routing table on CentOS and friends:

1.ip command  -  A CentOS Linux command line tool to print / manipulate routing, devices, policy routing and tunnels.

2.route command - Older command line utility to show or manipulate the Linux kernel routing table. I suggest that you use ip command instead of route command. This command exists for historical and compatibility reasons only.

We need to edit the following configuration files for static route configuration :

1./etc/sysconfig/network - Edit this file to set default gateway IP address.

2./etc/sysconfig/network-scripts/route-ethX - Edit this file to set additional static gateway IP address.

> CentOS: Displaying current routing table

Type any one of the following command:

 # netstat -nr

 # route -n

 # ip route list

 #ip route show

[Warning: It is important that you configure routing correctly over ssh based session; otherwise, you will be locked out due to wrong network configuration.]

> CentOS Linux add a default gateway.

In this example, route all traffic via 192.168.1.254 gateway connected via eth0 network interface. The following command will set a default gateway for both internal and external network (if any):

# route  add  default  gw  192.168.1.254  eth0

OR

# ip route add 192.168.1.0/24 dev eth0

Q. How do I make routing changes persistent across CentOS Linux server reboots?

> To set default gateway edit /etc/sysconfig/network as follows:

 # cat /etc/sysconfig/network

Sample configuration file:

NETWORKING=yes
## server name ##
HOSTNAME=server1.cyberciti.biz
## Default route ##
GATEWAY=192.168.1.254
NETWORKING_IPV6=yes
IPV6_AUTOCONF=no

>Save and close the file. Restart the networking service on CentOS Linux, type:

 # service network restart

 # ip route list

>We can add additional static route for eth0 by editing "/etc/sysconfig/network-scripts/route-eth0"  file as follows:

10.0.0.0/8 via 10.10.29.65

>The above config sets static routing for network 10.0.0.0/8 via 10.9.38.65 router.

> Debian / Ubuntu Linux persistence static routing configuration

Edit /etc/network/interfaces file, enter:

 # vi /etc/network/interfaces

 Append the following in eth0 section:

#up route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254

#down route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254

> Save and close the file.

* Generic method to add persistent static routing on Linux

The following method works with almost all Linux distributions.

Edit /etc/rc.d/rc.local or /etc/rc.local, enter

 # vi /etc/rc.local

 Append the following line:

/sbin/ip route add 192.168.1.0/24 dev eth0

>Save and close the file.
-------------------------------------------------------------------------------------------------------