Setup PXE Boot using Centos and dhcpd, tftp and syslinux

This is something I often setup for clients because it's very helpful for people in datacenters, this allows custom OS installs on demand, you can customize it more by using kickstart etc.. but here's a base I use before customizing more:

This little script below will install everything you need to get booting by PXE Linux.

It also assumes you set a local IP (be sure not to overwrite your existing IP) on eth0:0 (note the :0) as and it takes a simple iptables command to NAT/Masquerade everything so the NAT clients can get to the public internet (you could also use public IPs if they are available but I prefer not to do this).

yum -y install tftp-server syslinux dhcp

#note the /tftpboot directory this will be the base directory we work from
#this will contain syslinux files and our boot images

mkdir -p /tftpboot/images
#copy syslinux to /tftpboot
cp /usr/share/syslinux/pxelinux.0 /tftpboot
cp /usr/share/syslinux/menu.c32 /tftpboot
cp /usr/share/syslinux/memdisk /tftpboot
cp /usr/share/syslinux/mboot.c32 /tftpboot
cp /usr/share/syslinux/chain.c32 /tftpboot

#create Centos 6 basedir and others like this
#copy the /pxeboot from the mirror of Centos:
mkdir -p /tftpboot/images/centos/6.3/x64
cd /tftpboot/images/centos/6.3/x64

#set /etc/dhcpd.conf for booting:
cat <<'EOF' > /etc/dhcpd.conf
allow booting;
allow bootp;
option option-128 code 128 = string;
option option-129 code 129 = text;
filename "/pxelinux.0";
#to make dhcpd happy or it won't start

ddns-update-style none;

#next, my one and only subnet

subnet netmask {
 option routers;
 option domain-name-servers;

mkdir -p /tftpboot/pxelinux.cfg/

cat << 'EOF' > /tftpboot/pxelinux.cfg/default
default menu.c32
prompt 5
timeout 300

LABEL Centos6.3x64
 MENU Label 6364
 kernel ../images/centos/6.3/x64/vmlinuz
 append initrd=../images/centos/6.3/x64/initrd.img

#enable tftp

#important for tftp set the server_args to /tftpboot or it will look in the wrong spot
#you'll get errors like PXE-T01: File not found
#PXE-E3B: TFTP Error - File not found
#set the following in /etc/xinet.d/tftp
        server_args             = -s /tftpboot

chkconfig tftp on
#restart dhcp server
service dhcpd restart
#start xinetd
service xinetd start

#set eth0:0 IP to
#set iptables masquerade
iptables -t nat -A POSTROUTING -m iprange --src-range -j MASQUERADE

# the issue is that in Centos 6 the config is located in /etc/dhcp/dhcpd.conf and NOT /etc/dhcpd.conf (this one is ignored and useless)!
#Dec 18 00:34:38 fs12home dhcpd: Not configured to listen on any interfaces!


pxe, centos, dhcpd, tftp, syslinux, datacenters, allows, custom, os, installs, customize, kickstart, etc, customizing, install, booting, linux, assumes, ip, overwrite, existing, eth, iptables, nat, masquerade, ips, yum, server, dhcp, tftpboot, directory, contain, images, mkdir, cp, usr, pxelinux, memdisk, mboot, basedir, pxeboot, wget, http, org, _, initrd, img, vmlinuz, conf, eof, bootp, text, filename, quot, authoritative, ddns, update, subnet, netmask, routers, domain, servers, cfg, default, prompt, timeout, label, kernel, append, enable, server_args, ll, errors, xinet, chkconfig, restart, xinetd, postrouting, iprange, src, config, located, ignored, dec, fs, configured, interfaces,

Latest Articles

  • ssh Too many authentication failures not prompting for password
  • LightDM Mint Ubuntu Debian won't start errors Nvidia Graphics
  • WARNING: Unable to determine the path to install the libglvnd EGL vendor library config files. Check that you have pkg-config and the libglvnd development libraries installed, or specify a path with --glvnd-egl-config-path. Linux Ubuntu Mint Debian E
  • How To Upgrade Linux Mint 18.2 to 18.3 to 19.x and 20.x
  • MP3s Won't Play / ID3 Version 2.4 Issues in Cars and Other MP3 Players/CDs/DVDs Solution
  • LXC Containers LXD How to Install and Configure Tutorial Ubuntu Debian Mint
  • GlusterFS HowTo Tutorial For Distributed Storage in Docker, Kubernetes, LXC, KVM, Proxmox
  • Ubuntu Mint audio output not working pulseaudio "pulseaudio[13710]: [pulseaudio] sink-input.c: Failed to create sink input: too many inputs per sink."
  • How To Shrink Dynamically Allocated VM QEMU KVM VMware Disk Image File
  • How To Enable Linux Swapfile Instead of Partition Ubuntu Mint Debian Centos
  • 404 Not Found [IP: 80] apt update Debian 11 Bullseye Solution The repository ' bullseye/updates Release' does not have a Release file.
  • WARNING: Can't download daily.cvd from freshclam clamav error solution
  • (firefox:9562): LIBDBUSMENU-GLIB-WARNING **: Unable to get session bus: Failed to execute child process "dbus-launch" (No such file or directory) Solution
  • Debian Mint Ubuntu Which Package Provides missing top, ps and w Solution
  • Vbox Virtualbox DNS NAT Network Mode NOT working
  • Docker Tutorial HowTo Install Docker, Use and Create Docker Container Images Clustering Swarm Mode Monitoring Service Hosting Provider
  • Zoom Password Error 'That passcode was incorrect' - Solution Wrong Passcode Wrong Meeting Name
  • How To Startup and Open Remote/Local Folder/Directory in Ubuntu Linux Mint automatically upon login
  • How To Reset Windows Server Password 2019, 2022, 7, 8, 10, 11 Recovery and Removal Guide Using Linux Ubuntu Mint Debian
  • How To Create OpenVPN Server for Secure Remote Corporate Access in Linux Debian/Mint/Ubuntu with client public key authentication