Tuesday, 14 June 2016

How to Install And Configure PXE Server And Client On CentOS 6.5

About PXE Server

PXE Server, stands for preboot execution environment, is used to enable a network computer to boot only from a network interface card.

This method will be very helpful, if a System Administrator wants to install many systems which doesn’t have a CD/DVD device on the network.

PXE environment needs a DHCP server that distributes the IP addresses to the client systems, and a TFTP server that downloads the installation files to the PXE clients.

DHCP is used to find PXE servers and TFTP is used to download files to PXE client. These files are then stored into the client computer RAM memory and executed. PXE protocol client then boots independently of hard disks or operating systems.

PXE server will run on the same server as DHCP server.
You don’t need any CD/DVD or USB bootable drives to install client systems. Just, copy the ISO images on the PXE server and start installing your Linux clients via network using PXE server.

Requirements :-

DHCP Server
SELinux disabled on PXE server.
IP tables stopped on PXE server.
Network Card with PXE Option ROM (client). Client computers support booting over the network. You should check each computer's BIOS for this option.
You must a assign a static IP address to your DHCP server’s network interface card.
Install and Configure PXE Server!

1. Install the following packages for setting up PXE environment.
Install All Necessary Packages using yum :-
# yum install httpd xinetd syslinux tftp-server -y

2. Configure PXE Server

    Stop the firewall service.

    # service iptables stop

    Disable Selinux.
    # vim /etc/sysconfig/selinux

    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #     enforcing - SELinux security policy is enforced.
    #     permissive - SELinux prints warnings instead of enforcing.
    #     disabled - No SELinux policy is loaded.
    # SELINUXTYPE= can take one of these two values:
    #     targeted - Targeted processes are protected,
    #     mls - Multi Level Security protection.
    Now a reboot is required for selinux settings to  take effect.
    # reboot

    Copy the following TFTP configuration files to the /var/lib/tftpboot/ directory.

    # cd /usr/share/syslinux/
    # cp pxelinux.0 menu.c32 memdisk mboot.c32 chain.c32 /var/lib/tftpboot/
    # ll /var/lib/tftpboot/

    Edit file /etc/xinetd.d/tftp

    # vim /etc/xinetd.d/tftp
    Enable TFTP server. To d0 this, change “disable=yes” to “no”.

    # default: off
    # description: The tftp server serves files using the trivial file transfer
    # protocol.  The tftp protocol is often used to boot diskless
    # workstations, download configuration files to network-aware printers,
    # and to start the installation process for some operating systems.
    service tftp
             socket_type             = dgram
             protocol                   = udp
             wait                         = yes
             user                         = root
             server                      = /usr/sbin/in.tftpd
             server_args             = -s /var/lib/tftpboot
               isable                   = no
             per_source             = 11
             cps                         = 100 2
            flags                        = IPv4

    Next, create a directory to store CentOS installation ISO image. and mount the image to that     directory as shown below. I have CentOS 6.5 64bit ISO image on my /opt/mnt/Centos     directory.

    # mkdir /var/lib/tftpboot/Centos6_x86_64
    # ll /var/lib/tftpboot/Centos6_x86_64
    # mount -o loop /opt/CENTOS/CentOS-6.5-x86_64-bin-DVD1.iso /var/lib/tftpboot/Centos6_x86_64/
 # ll /var/lib/tftpboot/Centos6_x86_64/
    total 682
    -r--r--r-- 2 root root     14 Nov 29  2013 CentOS_BuildTag
    dr-xr-xr-x 3 root root   2048 Nov 29  2013 EFI
    -r--r--r-- 2 root root    212 Nov 28  2013 EULA
    -r--r--r-- 2 root root  18009 Nov 28  2013 GPL
    dr-xr-xr-x 3 root root   2048 Nov 29  2013 images
    dr-xr-xr-x 2 root root   2048 Nov 29  2013 isolinux
    dr-xr-xr-x 2 root root 655360 Nov 29  2013 Packages
    -r--r--r-- 2 root root   1354 Nov 28  2013 RELEASE-NOTES-en-US.html
    dr-xr-xr-x 2 root root   4096 Nov 29  2013 repodata
    -r--r--r-- 2 root root   1706 Nov 28  2013 RPM-GPG-KEY-CentOS-6
    -r--r--r-- 2 root root   1730 Nov 28  2013 RPM-GPG-KEY-CentOS-Debug-6
    -r--r--r-- 2 root root   1730 Nov 28  2013 RPM-GPG-KEY-CentOS-Security-6
    -r--r--r-- 2 root root   1734 Nov 28  2013 RPM-GPG-KEY-CentOS-Testing-6
    -r--r--r-- 1 root root   3380 Nov 29  2013 TRANS.TB

    Now, Create a apache configuration file for PXE server under /etc/httpd/conf.d/ directory:
    # vim /etc/httpd/conf.d/pxeboot.conf
    Add the following lines:

    Alias /Centos6_x86_64 /var/lib/tftpboot/Centos6_x86_64
    <Directory /var/lib/tftpboot/Centos6_x86_64>
    Options Indexes FollowSymLinks
    Order Deny,Allow
    Deny from all
    Allow from
    Save and close the file.

     Restart the httpd services

    # service httpd restart
    Stopping httpd:                                          [  OK  ]
    Starting httpd:                                            [  OK  ]

    Then, create a configuration directory for PXE server:
    # mkdir /var/lib/tftpboot/pxelinux.cfg

    Create a PXE server configuration file"default" under "/var/lib/tftpboot/pxelinux.cfg" and add     the below entry

    # vim /var/lib/tftpboot/pxelinux.cfg/default
    default menu.c32
    prompt 0
    timeout 300
    ONTIMEOUT local
    menu title ########## PXE Boot Menu ##########
    label 1
    menu label ^1) Install CentOS 6 x86_64 Edition
    kernel Centos6_x86_64/images/pxeboot/vmlinuz
    append initrd=centos6_x86_64/images/pxeboot/initrd.img             method=      Centos6_x86_64 devfs=nomount
    label 2
    menu label ^2) Boot from local drive localboot

     KERNEL - defines the location from where the PXELINUX bootloader will load.
     APPEND - defines the location for PXE initrd image file to load.

    Restart the relevant services.
    # service xinetd restart
    Stopping xinetd:                                           [  OK  ]
    Starting xinetd:                                           [  OK  ]

3. Now Install and Configure DHCP Server.
DHCP stands for Dynamic Host Configuration Protocol. DHCP is a standardized network     protocol used on Internet Protocol networks for dynamically distributing network configuration     parameters, such as IP addresses for interfaces and services. DHCP Server can be any server     (Linux or Windows) that is used to distribute IP addresses automatically to the clients in the     network. Since, DHCP Server assigns IP addresses automatically to all systems, a system or     Network administrator need not to assign IP addresses manually to every single machine in the     network. DHCP is opt for system or Network administrator who is managing thousands of     systems.

    A note of warning: Do not use two or more DHCP servers at the same time in your network.         The client systems might not be able to get IP addresses from the multiple DHCP servers and it     leads to IP address conflict issue. If your Router or Switch has DHCP feature enabled by     default, you need to turn it off too.
    You should Install and configure DHCP server on your PXE server. To install and configure     DHCP server, refer the following steps :-

    # yum install dhcp
 In CentOS 6.x systems, we have to assign which interface you want your DHCP server to run     on in /etc/sysconfig/dhcpd file. In my case, I have only one Interface on my system (eth0), so I     assigned eth0.
    Edit file /etc/sysconfig/dhcpd

    # vim /etc/sysconfig/dhcpd

    Assign the network interface:   

    Save and close the file.

    Now, edit dhcpd.conf file,

    # vim /etc/dhcp/dhcpd.conf

    Make the changes as shown below.
    option domain-name "setlabs.in";
    option domain-name-servers secondary.setlabs.org;
    default-lease-time 600;
    max-lease-time 7200;
    subnet netmask {
    range dynamic-bootp;
    option broadcast-address;
    option routers;

      allow booting;
           allow bootp;
       filename "pxelinux.0";

    Save and close the file.

{ Note :-
Set the domain name to setlabs.in and domain-name servers to secondary.setlabs.in.
If this DHCP server is the official DHCP server for the local network, add the following line: authoritative;
Define the sunbet, range of ip addresses, domain and domain name servers as shown :
    subnet netmask {
    range dynamic-bootp;
    option broadcast-address;
    option routers;
      allow booting;
           allow bootp;
    This declaration allows BOOTP clients to get dynamic addresses.
If you want to assign a fixed IP address to your client, you should enter it’s MAC id and the IP address in the following directive. For example, I want to assign a fixed IP address to my centos client, hence I modified the following directive as shown below.
    host centos-client {
     hardware ethernet 00:22:64:4f:e9:3a;

In your dhcp server make sure you add these lines.
       filename "pxelinux.0";
    as these define the address of your tftp server and the file to look for after getting the IP Address     from dhcp server.

    Now, restart the dhcp server.
    # service dhcpd start
    Starting dhcpd:                                            [  OK  ]

4. Restart all the services to complete the configuration.
    # service xinetd restart
    # service httpd restart
    # service dhcpd restart

    Make sure the services start after reboot
    # chkconfig httpd on
    # chkconfig xinetd on
    # chkconfig dhcpd on

5. PXE Client Configuration
The client may be any system that has network boot enabled option (PXE boot). You can enable this option in your Bios settings.Boot a machine and select the option of Network Boot from Bios. You should see Pxe Menu screen.

1 comment:

  1. Mesmerized article written on this blog with other relevant information. It is straight to the point that how we can improve our skills as well as how we can be represented to a new stream of professionalism.