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 192.168.1.10 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
wget http://mirror.centos.org/centos-6/6.3/os/x86_64/images/pxeboot/initrd.img
wget http://mirror.centos.org/centos-6/6.3/os/x86_64/images/pxeboot/vmlinuz

#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

#next-server 192.168.1.10;
authoritative;
ddns-update-style none;

#next, my one and only subnet

subnet 192.168.1.0 netmask 255.255.255.0 {
 range 192.168.1.50 192.168.1.254;
 option routers 192.168.1.10;
 option domain-name-servers 208.67.222.222;
}
EOF


#
mkdir -p /tftpboot/pxelinux.cfg/

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

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

#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 192.168.1.10
#set iptables masquerade
iptables -t nat -A POSTROUTING -m iprange --src-range 192.168.1.11-192.168.1.254 -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!


Tags:

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

  • Cisco CME How To Enable ACD hunt groups
  • How to install gns3 on Linux Ubuntu Mint
  • How to convert audio for Asterisk .wav format
  • Using Cisco CME Router with Asterisk as a dial-peer
  • Cisco CME How To Configure SIP Trunk VOIP
  • Virtualbox host Only Network Error Failed to save host network interface parameter - Cannot change gateway IP of host only network
  • Cisco CME and C7200 Router Testing and Learning Environment on Ubuntu 20+ Setup Tutorial Guide
  • Abusive IP ranges blacklist
  • How to Install Any OS on a Physical Drive from Windows Using VMware Workstation (Linux, Windows, BSD)
  • CDN Cloudflare how to set and preserve the real IP of the client without modifying application code on Apache
  • CentOS 7 fix Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was 14: curl#6 -
  • Ubuntu Debian How To Install Recommended Packages Automatically
  • How to set Linux Ubuntu Redhat Debian Command Line http https socks proxy for yum apt
  • How to resize a pdf without losing much quality in Linux Mint Ubuntu Debian Redhat Solution
  • qemu: could not load PC BIOS 'bios-256k.bin' solution
  • Proxmox How To Custom Partition During Install
  • Hyper-V Linux VM Boots to Black Screen, Storage, NIC Not Found Issues
  • Ubuntu Mint How to Fix Missing/Broken /dev and /dev/pts which causes terminal to immediately close exit and not work
  • How high can a Xeon CPU get?
  • bash fix PATH environment variable "command not found" solution