Saturday, April 22, 2017

Automated OS Installation PXE server using iPXE - Part 2 - DHCP server

DHCP Server Configuration:

DHCP server setup is part of  PXE server setup. We need to configure DHCP server in such a way that it will fulfill our requirements. I have taken templates from robinsmidrod's portal. The scripts in that portal are beautifully configured hence reduces of efforts to configure them from scratch. 

We use multiple scripts in for DHCP configuration. The first file is as mentioned below.

/etc/dhcp/dhcpd.conf and content of the file is:

ddns-update-style none;
deny bootp;     #default
authoritative;
include "/etc/dhcp/ipxe-option-space.conf";

# GREEN 
subnet 172.20.0.0 netmask 255.255.0.0 {
        range 172.20.10.11 172.20.100.254;
        option subnet-mask 255.255.0.0;
        option routers 172.20.10.10;

        default-lease-time 3600;
        max-lease-time 4800;

    include "/etc/dhcp/ipxe-green.conf";
}

In this file you can edit the dhcp range and other details as per your requirements. The other files we are going to create are already mentioned in the dhcpd.conf file. The second file is /etc/dhcp/ipxe-option-space.conf file. Please find the contents of the file below.

# Declare the iPXE/gPXE/Etherboot option space
option space ipxe;
option ipxe-encap-opts code 175 = encapsulate ipxe;

# iPXE options, can be set in DHCP response packet
option ipxe.priority         code   1 = signed integer 8;
option ipxe.keep-san         code   8 = unsigned integer 8;
option ipxe.skip-san-boot    code   9 = unsigned integer 8;
option ipxe.syslogs          code  85 = string;
option ipxe.cert             code  91 = string;
option ipxe.privkey          code  92 = string;
option ipxe.crosscert        code  93 = string;
option ipxe.no-pxedhcp       code 176 = unsigned integer 8;
option ipxe.bus-id           code 177 = string;
option ipxe.bios-drive       code 189 = unsigned integer 8;
option ipxe.username         code 190 = string;
option ipxe.password         code 191 = string;
option ipxe.reverse-username code 192 = string;
option ipxe.reverse-password code 193 = string;
option ipxe.version          code 235 = string;
option iscsi-initiator-iqn   code 203 = string;

# iPXE feature flags, set in DHCP request packet
option ipxe.pxeext    code 16 = unsigned integer 8;
option ipxe.iscsi     code 17 = unsigned integer 8;
option ipxe.aoe       code 18 = unsigned integer 8;
option ipxe.http      code 19 = unsigned integer 8;
option ipxe.https     code 20 = unsigned integer 8;
option ipxe.tftp      code 21 = unsigned integer 8;
option ipxe.ftp       code 22 = unsigned integer 8;
option ipxe.dns       code 23 = unsigned integer 8;
option ipxe.bzimage   code 24 = unsigned integer 8;
option ipxe.multiboot code 25 = unsigned integer 8;
option ipxe.slam      code 26 = unsigned integer 8;
option ipxe.srp       code 27 = unsigned integer 8;
option ipxe.nbi       code 32 = unsigned integer 8;
option ipxe.pxe       code 33 = unsigned integer 8;
option ipxe.elf       code 34 = unsigned integer 8;
option ipxe.comboot   code 35 = unsigned integer 8;
option ipxe.efi       code 36 = unsigned integer 8;
option ipxe.fcoe      code 37 = unsigned integer 8;
option ipxe.vlan      code 38 = unsigned integer 8;
option ipxe.menu      code 39 = unsigned integer 8;
option ipxe.sdi       code 40 = unsigned integer 8;
option ipxe.nfs       code 41 = unsigned integer 8;

# Other useful general options
# http://www.ietf.org/assignments/dhcpv6-parameters/dhcpv6-parameters.txt

option arch code 93 = unsigned integer 16;

This file mainly concentrates on declaring the ipxe options. The last file in dhcp folder is /etc/dhcp/ipxe-green.conf and contents are mentioned below.

allow bootp;
allow booting;
next-server 172.20.10.10; # core.smidsrod.lan

# Disable ProxyDHCP, we're in control of the primary DHCP server
option ipxe.no-pxedhcp 1;


if not exists ipxe.bus-id {
next-server 172.20.10.10;
#filename "undionly.kpxe";
     if option arch = 00:06 {
         filename "grub/ipxe-x86.efi";
     } elsif option arch = 00:07 {
         #filename "grub/ipxe-x64.efi";
filename "grub/ipxe.efi"; 
#filename "grub/snponly.efi";  
     } elsif option arch = 00:00 {
         filename "undionly.kpxe";
}
}
else {
next-server 172.20.10.10;
filename "ipxe/boot.ipxe"; #Provide configuration file path

}

These 3 files reside in /etc/dhcp folder. Configure your static ip (next-server ip)  based on the dhcp range and restart the server. You should be able to start your dhcp server without any issues.

If you find any issues while starting the DHCP service, check in /var/log/messages and resolve the issue.

We have configured dhcp server with this and check the next post to configure ipxe server.