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 Router Setup Guide and Tutorial Howto With Commands and Examples
  • Linux Bash Script To List All Connected IPs and their network name
  • Cisco Switches How To Get Of Port Line Status Console Messages
  • Cisco DHCP Snooping Relay Setup Information
  • Cisco Switch Setup Guide Command List
  • Cisco 2960 Switch Reset To Factory Defaults
  • How To Boot Cisco CUCM UCSInstall 8.6, 10, 11 and 12 on KVM/Proxmox
  • VBOX VirtualBox How To Import Raw .img Disk File
  • Windows Server 2012, 2016, 2019 How To Install and Missing Disabled Telnet Client
  • proxmox vm networking breaks when you restart your network on the hostnode
  • Linux ln symlink how to update existing symbolic link
  • Ubuntu 18.04 / Linux Mint 19.1 Cannot Type or Login - solution
  • LUKS Hard Drive Encryption on Linux Mint Ubuntu Debian etc how to mount encrypted hard drive
  • How to use nmap locate other machines/computers/servers on your network using nmap
  • Linux Mint 18.2 Create Config File To Start Application Upon Login
  • Dell Wyse Thin Client BIOS Access Key
  • sudoers file in /etc warning about comments/includes!
  • Centos 7 Reallocate logical volume space to another
  • lvm how to reduce volume size
  • letsencrypt certbot error "Unable to find a virtual host listening on port 80 which is currently needed for Certbot to prove to the CA that you control your domain. Please add a virtual host for port 80."