How to Setup a PXE (Preboot Execution Environment) Server in Linux Using Dnsmasq

Why Use a PXE Server?

Installing an operating system via USB drives is fine for one or two computers, but if you need to provision 50 new workstations, it becomes a logistical nightmare. A Preboot Execution Environment (PXE) server allows client computers with empty hard drives to boot directly from the network. They pull a minimal boot image (like Syslinux or GRUB) from the server over TFTP, which then automatically launches an automated OS installation over the network.

Step 1: Install Dnsmasq and Syslinux

While you can configure a separate DHCP and TFTP server, Dnsmasq combines both services into one lightweight, incredibly easy-to-configure package. You will also need the syslinux package to provide the actual network bootloader files.

On Ubuntu/Debian:

sudo apt update

sudo apt install dnsmasq syslinux pxelinux -y

Step 2: Create the TFTP Directory Structure

You must create a directory to hold all the boot files and operating system images that the clients will download. It is standard practice to place this in the /srv directory:

sudo mkdir -p /srv/tftpboot/pxelinux.cfg

Next, copy the necessary Syslinux bootloader files (which were installed in Step 1) into your new TFTP directory:

sudo cp /usr/lib/PXELINUX/pxelinux.0 /srv/tftpboot/

sudo cp /usr/lib/syslinux/modules/bios/ldlinux.c32 /srv/tftpboot/

Step 3: Configure Dnsmasq for PXE

The Dnsmasq configuration file dictates how the server responds to DHCP requests. Open the file in your text editor:

sudo nano /etc/dnsmasq.conf

Append the following configuration to the bottom of the file (adjust the IP range to match your specific network):


interface=eth0
dhcp-range=192.168.1.100,192.168.1.200,12h
enable-tftp
tftp-root=/srv/tftpboot
dhcp-boot=pxelinux.0

This tells Dnsmasq to act as a DHCP server, hand out IPs in that range, enable the TFTP server pointing to your directory, and instruct clients to boot the pxelinux.0 file.

Step 4: Create the PXE Boot Menu

When a client boots pxelinux.0, it immediately looks for a configuration file to tell it what operating systems are available. Create the default menu file:

sudo nano /srv/tftpboot/pxelinux.cfg/default

Add a basic entry pointing to an Ubuntu installer (you must place the vmlinuz and initrd files in an ubuntu subfolder later):


DEFAULT install
LABEL install
KERNEL ubuntu/vmlinuz
APPEND initrd=ubuntu/initrd root=/dev/ram0

Step 5: Start the Service and Boot a Client

Restart the Dnsmasq service to apply your new configuration:

sudo systemctl restart dnsmasq

Power on a client machine on the same network. Enter its BIOS/UEFI settings, change the primary boot device to Network (PXE), and reboot. You will see the machine successfully acquire an IP address and instantly load your PXE boot menu over the network!

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.