Setting up a Linux computer to act as a DHCP and PXE server

Unlike DNS, at least with BIND. Setting up a Linux machine to act as a DHCP server is a really simple process. Just like with DNS, running your own DHCP server using a Linux machine gives you even more control over your network. One thing that I really like about running my own DHCP server is the ability to assign static IP addresses to clients based on their NIC’s mac address. Another benefit of running my own DHCP server is the ability to easy install Linux systems via PXE.

 

For my network, I used Debian Squeeze as the host OS and ISC’s DHCP as the DHCP server software.

 

Installation:

apt-get install isc-dhcp-server tftpd-hpa

 

PXE Boot configuration:
mkdir -p /srv/tftp/
chown .nogroup /srv/tftp/
mkdir /srv/tftp/pxelinux.cfg
cd /srv/tftp

Download the Debian netbook files:

wget //ftp.us.debian.org/debian/dists/squeeze/main/installer-amd64/current/images/netboot/netboot.tar.gz
tar -xvf netboot.tar.gz

With the netboot files, I only used the pxelinux.0 and vesamenu.c32. pxelinux.0 is needed for the actual PXE boot, and vesamenu.c32  is used to list the menu of any system that will be available via PXE boot (optional).

(Debian PXE boot environment setup)

mkdir -p /srv/tftp/debian/squeeze/amd64
cd /srv/tftp/debian/squeeze/amd64
wget http://ftp.us.debian.org/debian/dists/squeeze/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz
wget http://ftp.us.debian.org/debian/dists/squeeze/main/installer-amd64/current/images/netboot/debian-installer/amd64/linux

(CentOS PXE boot environment setup)

mkdir -p /srv/tftp/centos/6.3
cd /srv/tftp/centos/6.3
wget http://mirrors.usc.edu/pub/linux/distributions/centos/6.3/os/x86_64/images/pxeboot/vmlinuz
wget http://mirrors.usc.edu/pub/linux/distributions/centos/6.3/os/x86_64/images/pxeboot/initrd.img

 

Create the following file, /srv/tftp/pxelinux.cfg/default :

DEFAULT vesamenu.c32

LABEL squeeze_amd64_install
kernel debian/squeeze/amd64/linux
append vga=normal initrd=debian/squeeze/amd64/initrd.gz —
LABEL squeeze_amd64_linux
kernel debian/squeeze/amd64/linux
append vga=normal initrd=debian/squeeze/amd64/initrd.gz —

LABEL squeeze_amd64_expert
kernel debian/squeeze/amd64/linux
append priority=low vga=normal initrd=debian/squeeze/amd64/initrd.gz —

LABEL squeeze_amd64_rescue
kernel debian/squeeze/amd64/linux
append vga=normal initrd=debian/squeeze/amd64/initrd.gz rescue/enable=true —

LABEL centos_amd64_install
kernel centos/6.3/vmlinuz
append initrd=centos/pxe/initrd.img

PROMPT 1
TIMEOUT 0

 

TFTP configuration:
Edit file /etc/default/tftpd-hpa:

RUN_DAEMON="yes"
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure"

Restart tftpd: /etc/init.d/tftpd-hpa restart

 

Example DHCP Configuration:

(Assumes 192.168.1.1 is the gatewway and 192.168.1.2 is the dhcp server)

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.120 192.168.1.254;
filename "pxelinux.0";
next-server 192.168.1.2;
option routers 192.168.1.1;
}

 

Example fixed address assignment:

host ubuntuvm01 {
hardware ethernet 08:00:27:11:5f:b8;
fixed-address 192.168.1.119;
}

 

pxe

pxe_gui

Leave a Reply

Your email address will not be published. Required fields are marked *