Skip to main content
PXE Linux

PXELinux using Proxy DHCP

By October 30, 2017September 12th, 2022No Comments

PXELinux using Proxy DHCPIn this blog we look at PXELinux using Proxy DHCP. PXELinux is a network boot server and can be used as a replacement to boot CDs or USB. Devices boot from the network and the PXELinux server provides the bootstrap files. Often this is used to deploy new installations of Linux when a system boots. In the next blog we look at deploying Ubuntu Server with PXE. The PXELinux server will often use its own DHCP Server, but often you have an existing DHCP server and the PXELinux server, then , just needs to send a few extra DHCP options. This is achieved by setting up PXELinux using Proxy DHCP. For the demonstration we are using Ubuntu 16.04 Server.

Install Required Packages for PXELinux using Proxy DHCP

We will install the package dnsmasq as this provides DNS, DHCP, DHCP Proxy and TFTP services with the single package and single service. This is very much designed with PXELinux in mind as we want DHCP and TFTP or as we will use TFTP with Proxy DHCP. Along with this we want the package pxelinux and its sister package syslinux. Pxelinux provides network boot and syslinux provides boot mechanisms from hard disk, iso file systems and USB drives. The package systenlix provides a lot of the shared files that we need for booting to any medium.

$ sudo apt-get update
$ sudo apt-get install pxelinux syslinux dnsmasq

By default the dnsmasq service will be running and is configured as a DNS Server by default. We do not need the DNS server and we will disable this later.

Create the DNSMASQ Configuration

As our first step we will rename the dnsmasq configuration file, /etc/dnsmasq.conf

$ sudo mv dnsmasq.conf dnsmasq.conf.orig

We can then use the editor of choice to create a new configuration:

$ sudo vim /etc/dnsmasq.conf

port=0
log-dhcp
dhcp-range=192.168.56.0,proxy
dhcp-boot=pxelinux.0
pxe-service=x86PC,'Network Boot',pxelinux
enable-tftp
tftp-root=/tftpboot

Make sure that you setup the correct IP address for the network that you want Proxy DHCP to work with. You must have an interface configured on this network range.

  • port=0 : Disables the DNS Service
  • log-dhcp=192.168.56.0,proxy : Log DHCP traffic
  • dhcp-range : The network range that we want to listen to DHCP requests on. The proxy options ensures we only send DHCP options and not the main IP address and mask. This is used so we can interoperate with and existing DHCP Server on the network
  • dhcp-boot=pxelinux.0: Set the DHCP Option for the boot filename used as the network bootstrap file
  • pxe-service=x86PC,’Network Boot’,pxelinux : Here we set the 2nd DHCP Option we deliver to DHCP clients and specify this is for our bios based systems, x86PC, a boot message and the name of the bootstrap file omitting the .0 from the end of the name.
  • enable-tftp : We need the TFTP server to deliver files after the bootstrap files has been delivered by PXELinux using Proxy DHCP.
  • tftp-root=/tftpboot : We set the path to the root directory that will be used by the TFTP Server

Fix the /etc/resolv.conf

When DNSMASQ was installed the resolv.conf will point to the localhost for DNS name resolution. This will be fine if we leave the DNS Server running but we want to disable it, as we have set with the port=0 setting in the dnsmasq.conf. To ensure that when using PXELinux with Proxy DHCP we do not need DNS we must reconfigure DNSMASQ to ignore the local interface. This is set in the file /etc/default/dnsmasq. And we need to add a line to this file:

$ sudo vim /etc/default/dnsmasq

#Add this as the last line
DNSMASQ_EXCEPT=lo
Create the TFTP Root

We can create the TFTP Server root directory and a subdirectory that we will need:

$ sudo mkdir -p /tftpboot/pxelinux.cfg

We can now restart the services. Restarting the networking service will ensure that the resolv.conf is rewritten as well:

$ sudo systemctl restart dnsmasq.service networking.service

Populate the TFTP Root

We now need to make sure the the bootstrap file that the DHCP options refer to is present. We will also need some other files from the system Linux package. We will add these all to the /tftpboot directory we have recently created.

sudo cp /usr/lib/PXELINUX/pxelinux.0 /tftpboot/
sudo cp /usr/lib/syslinux/modules/bios/{menu,ldlinux,libmenu,libutil}.c32 /tftpboot/
ls -l /tftpboot/
total 240
-rw-r--r-- 1 root root 116492 Oct 29 13:15 ldlinux.c32
-rw-r--r-- 1 root root  24196 Oct 29 13:15 libmenu.c32
-rw-r--r-- 1 root root  23700 Oct 29 13:15 libutil.c32
-rw-r--r-- 1 root root  26208 Oct 29 13:15 menu.c32
-rw-r--r-- 1 root root  42788 Oct 29 13:14 pxelinux.0
drwxr-xr-x 2 root root   4096 Oct 29 13:18 pxelinux.cfg

Create the PXELinux Configuration

When using PXELinux using Proxy DHCP the boot process will look for configurations for the client MAC address it IP address. If a specific file is not found then it can fall back to the default configuration. We will use the default configuration for all the clients at this stage and create a configuration files /tftpboot/pxelinux.cfg/default

$ sudo vim /tftpboot/pxelinux.cfg/default

default menu.c32
prompt 0
menu title Boot Menu
  label localboot
    menu label Boot Local Disk
    localboot 0

We load the menu program first and display the title. We have just one menu item that boots to the local disk. There will be more on installing Linux with these menus in another blog.

All we need to do is boot from a device on the network and test that NetBoot is working for that client. The video shows the process from start to finish.