Saturday, March 24, 2012

Features Of Redhat Ver. 6



  • Based on 2.6.X kernel
  • Supports graphical and text-based installations, ie Graphical installer is more feature-rich than text-based installer
  • Download available for a trial of 30days from the Redhat site.
  • Installable from:
    * Local media: CDs, DVDs (1-DVD ISO image), USB
    * Network: HTTP, NFS, FTP
    * PXE - Network Installation
  • KVM & Virtualization support
  • Default FS for new installations is EXT4 (All new releases of all varient linux comes up with the EXT4)
  • Disk encryption, including root (/) file system
  • Supported Platforms:
    * x86(32-bit)
    * b. x86_64 (AMD64 & Intel64)
    * IBM Power
    * System z

System Requirements:

  

 1GHz P4 processor - Recommending dual core or higher
 1GB RAM - Recommending 4GB or better
 3GB Storage for - minimum installation
 5GB storage for - full installation



  • Compatibility support for older programs (compat* RPMS)
  • Note: These are libraries to ensure the operation of older programs
  • Note: This ensures that certified applications by redhat will continue to run
  • Anaconda auto-formats disk with:

    '/boot'
    '/' - root
    '/home' (if >= 50GB of storage are available)
    'swap'
  • Anaconda & running system use: NetworkManager to auto-configure networking
    * Uses DHCP by default
    * Requires minimum intervention
  • Anaconda (installer) still supports absolute control over variables
    i.e , network settings may be specified during installation

Saturday, March 17, 2012

Creating a grub password in RHEL



1. Login as root user
2. Give the command grub-md5-crypt
3. Now it will ask for the password you wish to give for the grub
4. Enter the password and confirm the password given.
5. now you will get an encrypted password. Just copy the password by selecting the encrypted password
6. Now give the command vim /etc/grub.conf
7. Press I to edit the file.
8. Just before the title paste:
                     password --md5 <encrypted password>
9. press esc and give ':wq' for write and quit the edit menu.
10.Now reboot the system and try entering into the grub.
11.For entering into the grub it will ask for the password which can be given by just pressing p. This will unlock the grub features.

Which is the optimal strip size in RAID




 Stripe sizes play a very important role in the performance of RAID arrays and thus it is critical to understand the concept of striping before we delve any further into RAID discussion.

As we mentioned before, stripes are blocks of a single file that are broken into smaller pieces. The stripe size, or the size that the data is broken into, is user definable and can range from 1KB to 1024KB or more. The way it works is when data is passed to the RAID controller, it is divided by the stripe size to create 1 or more blocks. These blocks are then distributed among drives in the array, leaving different pieces on different drives.

Like we discussed before, the information can be written faster because it is as if the hard drive is writing a smaller file, although it is really only writing pieces of a large file. At the same time, reading the data is faster because the blocks of data can be read off of all the drives in the array at the same time, so reading back a large file may only require the reading of two smaller files on two different hard drives at the same time.

There is quite a bit of debate surrounding what stripe size is best. Some claim that the smaller the stripe the better, because this ensures that no matter how small the original data is it will be distributed across the drives. Others claim that larger stripes are better since the drive is not always being taxed to write information.

To understand how a RAID card reacts to different stripe sizes, let's use the most drastic cases as examples. We will assume that there are 2 drives setup in a RAID 0 stripe array that has one of two stripe sizes: a 2KB stripe and a 1024KB stripe. To demonstrate how the stripe sizes influence the reading and writing of data, we will use also use two different data sizes to be written and read: a 4KB file and a 8192KB file.

On the first RAID 0 array with a 2KB stripe size, the array is happy to receive the 4KB file. When the RAID controller receives this data, it is divided into two 2KB blocks. Next, one of the 2KB blocks is written to the first disk in the array and the second 2KB blocks is written to the second disk in the array. This, in theory, divides the work that a single hard drive would have to do in half, since the hard drives in the array only have to write a single 2KB file each.

When reading back, the outcome is just as pretty. If the original 4KB file is needed, both hard drives in the array move to and read a single 2KB block to reconstruct the 4KB file. Since each hard drive works independently and simultaneously, the speed of reading the 4KB file back should be the same as reading a single 2KB file back.

This pretty picture changes into a nightmare when we try to write the 8192KB file. In this case, to write the file, the RAID controller must break it into no less than 4096 blocks, each 2KB in size. From here, the RAID card must pass pairs of the blocks to the drives in the array, wait for the drive to write the information, and then send the next 2KB blocks. This process is repeated 4096 times and the extra time required to perform the breakups, send the information in pieces, and move the drive actuator to various places on the disk all add up to an extreme bottleneck.

Reading the information back is just as painful. To recreate the 8192KB file, the RAID controller must gather information from 4096 places on each drive. Once again, moving the hard drive head to the appropriate position 4096 times is quite time consuming.

Now let's move to the same array with a 1024KB stripe size. When writing a 4KB file, the RAID array in this case does essentially nothing. Since 4 is not divisible by 1024 in a whole number, the RAID controller just takes the 4KB file and passes it to one of the drives on the array. The data is not split, or striped, because of the large stripe size and therefore the performance in this instance should be identical to that of a single drive.

Reading back the file results in the same story. Since the data is only stored on one drive in our array, reading back the information from the array is just like reading back the 4KB file from a single disk.

The RAID 0 array with the 1024KB stripe size does better when it comes to the 8192KB file. Here, the 8192KB file is broken into eight blocks of 1024KB in size. When writing the data, both drives in the array receive 4 blocks of the data meaning that each drive only has the task of writing four 1024KB files. This increase the writing performance of the array, since the drives work together to write a small number of blocks. At the same time reading back the file requires four 1024KB files to be read back from each drive. This holds a distinct advantage over reading back a single 8192KB file.

As you can see, the performance of various stripe sizes differ greatly depending on the situation. Just what stripe size should you use?

CONFIGURING SQUID PROXY SERVER IN RED HAT LINUX




Squid is the most popular proxy server in use today. Some of the reasons why squid is so popular are:
1. Squid is not an ordinary proxy server, it is a proxy cum caching server. This means that when a web page is accessed through squid, it caches the web page on the local hard disk. When a request is made for the same web page either by the same client host computer or by any other computer, squid serves the web page from its local hard disk cache. This eliminates repetitive internet access and speeds up client web access.

2. Squid has excellent access control restrictions. For eg, you can restrict only certain computers to access the internet, restrict certain computers to access only certain web sites, restrict certain computers to access the internet only on certain days between certain time periods, restrict access to pornographic web pages etc. Squid can also be integrated with third party content filtering software to provide comprehensive and easily manageable web access restrictions.

3. Squid has extremely good logging capabilities, for eg, you can monitor which IP address has accessed which web site, how well your cache memory is being utilized, etc.

To install and configure squid proxy on our Linux system we need the following rpm:
squid-2.5.STABLE1-2

Edit the file squid.conf

[root@akhisar root]# vi /etc/squid/squid.conf

#Line No. 53
http_port 3128                                                # uncomment this line

#Line No.468
cache_mem 8 MB                                            # uncomment this line

# Line No. 666
cache_dir ufs /var/spool/squid 100 16 256         # uncomment this line

# Line No.673     
cache_access_log /var/log/squid/access.log       # uncomment this line

# Line No.681
cache_log /var/log/squid/cache.log                    # uncomment this line


# ACCESS CONTROLS
#Recommended minimum configuration:

# Line Nos. 1678-1693       # These are the default ACLs configured for our use       
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 563
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443 563  # https, snews
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports



acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT

# Line No.1694 onwards         ( Write your own ACLs from this line onwards)
acl ltc1 src "/etc/allowedips"
acl ltc2 src "/etc/domainrestrictedips"
acl ltc3 dstdomain "/etc/domains"
acl ltc4 src "/etc/timerestrictedips"
acl ltc5 time SMT 12:00-14:00
acl badurls url_regex sex hardcore playboy.com

# Line No.1720
#http_access deny all            # Do not uncomment this line if using ACLs

# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
http_access deny badurls
http_access deny ltc4 ltc5
http_access allow ltc2 ltc3
http_access allow ltc1

# And finally deny all other access to this proxy
http_access allow localhost
http_access deny all

#  TAG: visible_hostname
#       If you want to present a special hostname in error messages, etc,
#       then define this.  Otherwise, the return value of gethostname()
#       will be used. If you have multiple caches in a cluster and
#       get errors about IP-forwarding you must set them to have individual
#       names with this setting.
#
visible_hostname akhisar

`Save the file and Quit'.

Explanation of Configuration directives :

Line No.53
Squid listens for requests on tcp port 3128 by default, you can change this.

Line No.468

      'cache_mem' specifies the ideal amount of memory to be used
        for:
               * In-Transit objects
               * Hot Objects
               * Negative-Cached objects

       Data for these objects are stored in 4 KB blocks.  This
       parameter specifies the ideal upper limit on the total size of
       4 KB blocks allocated.  In-Transit objects take the highest
       priority.


       In-transit objects have priority over the others.  When
       additional space is needed for incoming data, negative-cached
       and hot objects will be released.  In other words, the
       negative-cached and hot objects will fill up any unused space
       not needed for in-transit objects.

        If circumstances require, this limit will be exceeded.
        Specifically, if your incoming request rate requires more than
       'cache_mem' of memory to hold in-transit objects, Squid will
        exceed this limit to satisfy the new requests.

 NOTE: THIS PARAMETER DOES NOT SPECIFY THE MAXIMUM PROCESS SIZE.
       IT ONLY PLACES A LIMIT ON HOW MUCH ADDITIONAL MEMORY SQUID WILL
       USE AS A MEMORY CACHE OF OBJECTS. SQUID USES MEMORY FOR OTHER
       THINGS AS WELL.

Line No.666
This specifies the top level directory squid will use as its cache folder.
`100' specifies the amount of space allocated in MB for this folder (100MB is the default, you can increase this value depending on your usage).
`16' is the number of upper level folders created under the top level cache folder. These upper level folders store the web pages that are more frequently accessed.
`256' is the number of lower level folders created under each of the 16 upper level folders. These lower level folders store the web pages that are less frequently accessed.
The top level folder `/var/spool/squid' is created automatically, the 16 upper level and 256 lower level folders are created only when the squid server service is started for the first time.

Line No.673
The access log file logs every client web request. It is used to monitor which IP address has accessed which web site.

Line No.681
Cache logging file. This is where general information about your cache's behavior goes.

ACCESS CONTROLS :

This section is used to impose access restrictions to Squid Proxy server.
Restrictions are imposed with the help of access controls lists (ACLs) that need to be created by the squid server administrator. Default access lists have been created but for secure access further customization is required.

The syntax used in writing ACLs is as follows :
acl       <label>               <keyword>  <parameter>
Explanation :
Every access control list starts with the word `acl'. Label is just a descriptive name for that acl,it has no technical significance.

The first acl is named `ltc1',it uses the keyword `src'.
The keyword `src' stands for source IP address, i.e. the IP address of the client host computer making a web request via the squid proxy server. Instead of defining IP addresses individually we can write the IP addresses (one below the other) to a file and mention the path to that file on the `acl line'.
Here we have written a few IP addresses to the file `allowedips' created under the /etc subdirectory.

The second `acl',`ltc2' also refers to IP addresses that have been saved to a file `domainrestrictedips' created under /etc.

The third `acl',`ltc3' contains the keyword `dstdomain'. This keyword refers to domain names for eg,www.yahoo.com,www.rediff.com etc. Instead of specifying domain names individually we can write them to a file (one below the other) and mention the path to that file on the `acl line'. Here we have written a few domain names to the file `domains' created under /etc.

The fourth `acl',`ltc4' refers to IP addresses that have been written to a file `timerestrictedips' created under /etc.

The fifth `acl',`ltc5' specifies the keyword `time'. This keyword refers to days of the week and times. Here we have specified the days of the week as Sunday, Monday and Tuesday and the time as 12:00 p.m. to 2:00 p.m.

The sixth `acl', named `badurl', consists of the keyword `url_regex'. This keyword refers to regular expressions. Here we have mentioned a few expressions or phrases like sex, hardcore, playboy.com.

The six `acls' that we have created above are of no use until and unless they have been enforced.


To enforce these rules go to the following section :

# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS

http_access deny badurls

Explanation :
No url mentioning any of the expressions or phrases mentioned in that acl (sex,hardcore,playboy.com) will be allowed access to. In fact even if a search is done through google or any other search engine on any of these expressions, web access will be denied.

http_access deny ltc4 ltc5
Web access will be denied to all host computers having IP addresses contained in the file `/etc/timerestrictedips' on Sunday.Monday and Tuesday between 12:00 p.m. to 2:00 p.m.

http_access allow ltc2 ltc3
The host computers having the IP addresses defined in the file `/etc/domainrestrictedips' will  be allowed access to only the web sites defined in the file /etc/domains.

http_access allow ltc1
All IP addresses mentioned in the file /etc/allowedips will be allowed unrestricted internet access other than access to site urls containing the phrases specified in the `badurls' acl.

# And finally deny all other access to this proxy
Explanation :
http_access allow localhost
Any user who accesses the internet from the squid proxy server itself will not be controlled by the access control lists and will have absolute unrestricted internet access.
This privilege should only be reserved for the squid server administrator.

http_access deny all
Any incoming web request that is not matched by any of the acl rules will be denied.

# TAG : visible_hostname
Specifies the hostname of the squid proxy server as defined in the file `/etc/hosts' or in DNS.

To start the squid proxy server service :
[root@akhisar root]# service squid start


Any change made to the file `/etc/squid/squid.conf' will need the service to be restarted.

[root@akhisar root]# service squid restart

To set the squid service to be permanently on:
[root@akhisar root]# chkconfig squid on

" Do not forget to create your access control files"
1. [root@akhisar root]# vi /etc/allowedips
     192.0.2.179
     192.0.2.176

2. [root@akhisar root]# vi /etc/domainrestrictedips
     192.0.2.167

3. [root@akhisar root]# vi /etc/timerestrictedips
     192.0.2.176

4. [root@akhisar root]# vi /etc/domains
     www.yahoo.com
     www.rediff.com

You can create any files by any name located in any folder, just specify the correct name and path to the files on the `acl' lines.

Note : Make sure that the time restricted ips are have also been defined in the `allowedips' file else those ips will be denied web access.

Any change made in any of these files will require the squid service to be restarted.

Visible_hostname akhisar à  This line needs to be defined, else the squid service will fail to start. Set this parameter to the hostname of your computer as defined in the file /etc/hosts.

To configure authentication for Squid Proxy server :

We can also configure then squid server to request for authentication whenever a user tries to access the internet through squid proxy.

Perform the following configuration in the auth_param section of the squid.conf file.
[root@akhisar root]# vi /etc/squid/squid.conf
                               # TAG: auth_param
                                   
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd
                                   auth_param basic children 5
                                   auth_param basic realm Squid proxy-caching web server
                                   auth_param basic credentials ttl 2 hours

The first line points to the name and location of the external authenticator program used. Here we use the ncsa_auth software located in the /usr/lib/squid folder. We need to input all authorized username and password combinations into the file specified viz. /etc/squid/passwd. This passwd file will not exist by default, it needs to be created. You can create a file by any name under any folder.

[root@akhisar root]# cd /etc/squid
[root@akhisar squid]# touch passwd
Enter the authorized usernames/passwords you require.
[root@akhisar squid]# htpasswd passwd proxyuser
New password:
Re-type new password:
Adding password for user proxyuser

Here we create an authorized user by the name of `proxyuser' and assign him a password. This username/password combination will need to be used by requesting users to authenticate themselves before accessing the internet.

Create an Access Control List for ncsa_auth in the file /etc/squid/squid.conf :

[root@akhisar root]# vi /etc/squid/squid.conf
                               # ACCESS CONTROLS
                                  acl password proxy_auth REQUIRED

                              
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
                                     
http_access allow password

Here the name of the acl we create is `password'. The keyword used is `proxy_auth'. The parameter used is `REQUIRED' which will cause ncsa_auth to accept any valid username/password combination for authentication.

INSTALLING A EXTERNAL MODEM :

To install an external modem :

Connect the modem to a serial port at the back of your computer and power it on.

Execute the following command :

# wvdialconf /etc/wvdial.conf

This starts the modem autodetection procedure,you will see the modem lights blinking and a series of messages will be output on screen stating that the modem is detected and the port on which it has been detected on(if all goes well).

[root@akhisar squid]# wvdialconf /etc/wvdial.conf
Scanning your serial ports for a modem.

Port Scan<*1>: Scanning ttyS0 first, /dev/modem is a link to it.
ttyS0<*1>: ATQ0 V1 E1 -- OK
ttyS0<*1>: ATQ0 V1 E1 Z -- OK
ttyS0<*1>: ATQ0 V1 E1 S0=0 -- OK
ttyS0<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK
ttyS0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK
ttyS0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
ttyS0<*1>: Modem Identifier: ATI -- 33600
ttyS0<*1>: Speed 4800: AT -- OK
ttyS0<*1>: Speed 9600: AT -- OK
ttyS0<*1>: Speed 19200: AT -- OK
ttyS0<*1>: Speed 38400: AT -- OK
ttyS0<*1>: Speed 57600: AT -- OK
ttyS0<*1>: Speed 115200: AT -- OK
ttyS0<*1>: Max speed is 115200; that should be safe.
ttyS0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK


Found a modem on /dev/ttyS0, using link /dev/modem in config.
Modem configuration written to /etc/wvdial.conf.
ttyS0<Info>: Speed 115200; init "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"

Edit the ‘wvdial.conf’ file and make changes to the highlighted sections

[root@akhisar squid]# vi /etc/wvdial.conf
                    [Dialer Defaults]
                    Modem = /dev/modem
                    Baud = 115200
                    Init1 = ATZ
                    Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
                    ISDN = 0
                    Modem Type = Analog Modem
                    Phone = "Your ISP's internet acces number"
                    Username = "Your internet username"
                    Password = "Your internet access password"


To dialup to the internet, execute the following command :

[root@akhisar root]# wvdial








An Apache Web Server is a computer that stores information in html format. 
An organization would normally like to store company related information that should be made available to its employees in a publicly accessible location. One such method of doing this is to put up this information in the form of html web pages so that employees and other related people can browse through it whenever they need to.

An organization that needs to have a presence on the internet needs to put up information about itself in a location that is accessible to the rest of the world. The company thus needs to register a domain name for itself for eg, abc.com, host this domain on a DNS server and setup a web server to host all information about itself in html format. The DNS server performs the task of redirecting requests for abc.com to the designated web server for the company.

There are a number of web server softwares available with the various operating systems for eg, IIS with Windows, Iplanet from Sun Solaris etc. The most popular web server software is however the Apache web server which accounts for almost 90% of the web server installations worldwide. In fact Apache is so popular that there even exists a Windows version of Apache.

The reasons for Apache being so popular are :

1. Being a Linux product it is free and open source.

2. It supports SSL encryption at no extra cost (SSL is the secure sockets layer implementation that creates an encrypted tunnel between the client computer and the web site it is accessing thereby securing all information flowing through that tunnel).

3. Its virtual hosting capabilities. (Virtual hosting is a concept wherein multiple web sites can be hosted on a single web server. This is however a feature of all web server software packages).

To install and configure Apache on our Linux box we need the following rpm :
httpd-2.0.40-21

To configure apache :

Edit the file httpd.conf

[root@akhisar root]# vi /etc/httpd/conf/httpd.conf
                                          
ServerRoot "/etc/httpd"                                                  # Line No.56

# StartServers: number of server processes to start              # Line No 103
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers                   8
MinSpareServers             5
MaxSpareServers          20
MaxClients                  150
MaxRequestsPerChild 1000
</IfModule>                                                                       # Line No.114







# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80

Listen 80                                                                         # Line No.157

# (Apache web server listens on tcp port 80, by default).

# Apache runs as the user apache and group apache for security reasons
User apache                                                                    # Line No.251
Group apache                                                                  # Line No.252

# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#

ServerAdmin root@localhost                                           # Line No.259

# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work.  See also the Use CanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
ServerName localhost:80                                                # Line No.273
# (You should enter the IP address of the web server,hostname,FQDN or just localhost)

# Location of the html web pages for the company web site
DocumentRoot "/var/www/html"                                          # Line No.289


# Line Nos.338 to 343
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all

</Directory>

# Specifies the names that can be used for the index or home page of the web site
DirectoryIndex index.html index.html.var index.htm index.php  # Line No.408
# (By default index.htm and index.php are not included, you will have to add them
#  here if you have index pages with those extensions).

# Line Nos.952 to 972

# Allow server status reports, with the URL of http://servername/server-status
# [Change the ".your-domain.com" (for eg,lansmart.com) to match your domain to enable.
# You can also enter the subnet address of the network from which web requests will be
#  made, for eg, 192.0.2.0/24]
# To access this html page open your web browser and type in the following URL:
# http://www.lansmart.com/server-status. This page will now be inaccessible to everyone with the
# exception of users connecting from the authorized subnet 192.0.2.0.

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from .your-domain.com
</Location>

# Allow remote server configuration reports, with the URL of
#  http://servername/server-info (requires that mod_info.c be loaded).
# Change the ".your-domain.com" (for eg,lansmart.com) to match your domain to en# able. You can also enter your # subnet address here eg,192.0.2.0/24
# To access this web page open up your web browser and type in the following URL
# http://www.lansmart.com/server-info
<Location /server-info>
    SetHandler server-info
    Order deny,allow
    Deny from all
    Allow from your-domain.com
</Location>

# Line No.1009 onwards
### Section 3: Virtual Hosts

NameVirtualHost 192.0.2.172
<VirtualHost 192.0.2.172>
ServerName www.lansmart.com
DocumentRoot /var/www/html/lansmart
</VirtualHost>

NameVirtualHost 192.0.2.173
<VirtualHost 192.0.2.173>
ServerName training.lansmart.com
DocumentRoot /var/www/html/training
</VirtualHost>

NameVirtualHost 192.0.2.171
<VirtualHost 192.0.2.171>
ServerName sales.lansmart.com
DocumentRoot /var/www/html/sales
</VirtualHost>

<VirtualHost 192.0.2.171>
ServerName tech.lansmart.com
DocumentRoot /var/www/html/tech
</VirtualHost>

<Directory "/var/www/html/lansmart">
AuthType Basic
AuthName Lansmart
AuthUserFile /etc/httpd/passwd
require valid-user
</Directory>

# (Virtual Hosting as explained earlier is a means of configuring multiple web sites on a single web server. This saves us the cost of purchasing multiple computers or multiple network cards. Using just one computer and one network card we can host multiple web sites. This is especially made use of by web hosting providers. Virtual Hosting is of two types,

a. Name based hosting
Here, all web sites hosted on the web server use the same IP address.

b. IP based hosting
With IP based hosting, all web sites hosted use a different IP address.

Let us consider a scenario in which our organization `Lansmart Technologies' needs to host two four web sites: www.lansmart.com, training.lansmart.com, sales.lansmart.com and tech.lansmart.com.
The first two sites, www.lansmart.com and training.lansmart.com should be IP based and the other two sites should be name based.

Steps to follow to configure your apache web server for the above scenario:

[ The hostname of our Apache web server is akhisar having an IP address 192.0.2.171 ]
akhisar is also hosting DNS server services for ‘Lansmart’.

Step 1 (For IP based hosting):
Create two virtual cards eth0:0 and eth0:1 having the IP addresses 192.0.2.172 and 192.0.2.173 respectively.

Step 2 : Configure your DNS server to support these hostnames (Forward and reverse lookup)

First configure the index file /etc/named.conf to support the domain lanmsart.com
(Refer to the chapter on DNS Server for this)

Configure the forward lookup file for lansmart.com (Refer to the chapter on DNS)

[root@akhisar root]# vi /var/named/lansmart.forward
                               akhisar       A    192.0.2.171
                               www       A    192.0.2.172
                               training   A    192.0.2.173


(akhisar is the actual hostname of the web server computer having the IP address 192.0.2.171)



Configure the reverse lookup file (Refer to the chapter on DNS)

[root@akhisar root]# vi /var/named/lansmart.rev
                              171        PTR    akhisar.lansmart.com.
                              172        PTR    www.lansmart.com.
                              173        PTR    training.lansmart.com. 

Step 3 (For Name based hosting) :
Configure CNAME records for the hostnames sales.lansmart.com and tech.lansmart.com in the forward lookup file).

[root@akhisar root]# vi /var/named/lansmart.forward

   akhisar      A          192.0.2.171
   sales      CNAME  akhisar.lansmart.com.
   tech       CNAME  akhisar.lansmart.com.


Create the file /etc/resolv.conf with the necessary information on the DNS server and on each Linux DNS client host computer.

Test your DNS configuration with the nslookup and dig commands to make sure that everything is working as it should.

Step 4: Configure Apache Web server
Configure the httpd.conf file as shown above to support the virtual hosts.
Create the necessary folders (in the /var/www/html folder), lansmart, training, sales and tech, to store the html pages for the respective web sites. Create the index.htm and the rest of the html pages in these folders.

A sample index.htm file is shown below:

[root@akhisar root]# vi /var/www/html/lansmart/index.htm
  <html>
  <h1>
   Welcome to Lansmart
  </h1>
  </html>

In the file httpd.conf, the Virtual host sections define the name of the web site and the path to the folder in which the html pages for that site are stored.
Both IP based sites (www.lansmart.com & training.lansmart.com) will have the line `NameVirtualHost <IP Address>' since they are running on different IP addresses. The Name based site sales.lansmart.com will also have the line `NameVirtualHost <IP Address>' since it is running on a different IP address than the IP basedsites. However the site tech.lansmart.com will not have the `NameVirtualHost' line as it is running on the same IP address as sales.lansmart.com, i.e. 192.0.2.171.
(The Virtual host sections are written in XML).


Testing
Connect to the apache web server from a client computer, open up your web browser and test connectivity to all four web sites :
www.lansmart.com
training.lansmart.com
sales.lansmart.com
tech.lansmart.com

‘Web pages for all the four sites should open without any problem’.

Testing Authentication :
The `Directory' section specifies the authentication to be used before being granted access to the site. Here we configure authentication for the site www.lansmart.com. This would require protecting the html pages for this site (stored under /var/www/html/lansmart). AuthType specifies the type of authentication being used, here the keyword `Basic' specifies that username/password authentication is being used. Whenever a request is made for www.lansmart.com an authentication window will open up requiring the user to enter an authorized username/password combination. `AuthName' is the heading that appears at the top of this authorization window. `AuthUserFile' specifies the name and path to the file in which the authorized usernames and password have been stored. We define this file to be `passwd' stored in /etc/httpd.

The keyword `require valid-user' will prevent non-authorized access to the web site www.lansmart.com.

The file `/etc/httpd/passwd' does not exist by default, it will have to be created.

[root@akhisar root]# cd /etc/httpd
[root@akhisar httpd]# touch passwd

Enter the authorized username and password combinations you require :

[root@akhisar httpd]# htpasswd -m passwd webuser
New password:
Re-type new password:
Adding 'password for user webuser

Here we create an authorized user called webuser and assign him a password.
Create additional authorized usernames/passwords if required.

Note : The authorized usernames that we create need not be those of valid users existing on the Linux web server computer. The names can be fictitious unlike our Samba server configuration which requires valid usernames for authentication.

Whenever a user tries to access the web site www.lansmart.com an authentication windows pops up asking for a valid username and password combination.

Here the user needs to enter the authorized username as `webuser' and the password assigned to that user.