Create IPv4 hex filenames suitable for PXELINUX
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Create IPv4 hex filenames suitable for PXELINUX

The PXE network booting system distributed by the Syslinux Project is widely used for installing operating systems on networks of all sizes. It's used in conjunction with DHCP and TFTP servers.

The DHCP server will tell the client system where to look for the TFTP server from which boot files can be loaded. First, the client's PXE stub will download the bootloader image (typically named pxelinux.0 or gpxelinux.0) from the TFTP server. Once the client executes the bootloader, it will then search for its configuration file.

The PXELINUX bootloader will look for a succession of files. You should read the official documentation to get the full story, but the short version is that their filenames are based on

  1. Client UUID (not always present)
  2. Client Ethernet MAC (prefixed by ARP type, typically 01)
  3. IPv4 address in uppercase hexadecimal (on a widening scope)
  4. A file named 'default'

The part that usually trips me up is converting an IPv4 address to hex. So I hacked up the script in this repository to assist me.


Invoking the script to do useful work requires a fully qualified domain name or a full IPv4 address:

  pxehex [-h]
  pxehex [-a] [-v] FQDN
  pxehex [-a] [-v] IPv4 address

When passed a FQDN or IPv4 address with no other arguments, the script will return an 8-character hexadecimal string that PXELINUX will associate with that address.

[bash ~]$ pxehex

With the -v option, you'll also get a comment the IP address in question.

[bash ~]$ pxehex -v
6883B274 #

Finally, the -a option will produce all of the address-based filenames for which PXELINUX will search for your address/hostname. Adding -v will clarify the scope for each filename.

[bash ~]$ pxehex -a -v
0A64C837 #
0A64C83  #
0A64C8   #
0A64C    #
0A64     #
0A6      #
0A       #
0        #


TFTP layout

Here's a possible layout of a TFTP server's root directory. (This is from a CentOS system. Other distributions may have a root other than /var/lib/tftpboot.) The images directory contains kernels and ramdisks. The pxelinux.cfg directory contains the boot configuration files for PXELINUX.

├── images
│   ├── centos
│   │   ├── 6
│   │   │   ├── i386
│   │   │   └── x86_64
│   │   └── 7
│   │       └── x86_64
│   ├── memtest
│   └── ubuntu
│       ├── trusty
│       │   └── amd64
│       └── xenial
│           └── amd64
└── pxelinux.cfg

Single host file

Let's say you want to provision a new CentOS 7 machine with an IPv4 address of

First, use the pxehex script to figure out the filename to use for your new host's address.

[bash ~]$ pxehex

Then create a boot configuration file:


Here is a simple example; it merely boots to the CentOS GUI installer, using the repository mirror at Portland State University.

KERNEL images/centos/7/x86_64/vmlinuz
APPEND initrd=images/centos/7/x86_64/initrd.img inst.repo=

At this point, if your DHCP server and TFTP server are configured correctly, you ought to be able to PXE boot your new host directly to the CentOS installer.


I've only tested the script using bash. It may fail when run using other shells. It may rely on other command-line utilities, depending on the options you invoke:

  • dig is required if you pass a hostname to the script;
  • seq is required to use the -a option;
  • ipcalc is required to use the -a and -v options together.

The script currently works with the ipcalc found in the Red Hat initscripts package and with Krischan Jodies' version installed on Debian-family systems or via MacPorts.