forked from server/user-documentation
Adding a section on PXE Boot configuration in dnsmasq
This content is migrated from dnsmasq-pxeboot.adoc. My goal here is to have a single dnsmasq doc that provides example of various dnsmasq functions (DHCP, DNS, TFTP etc). I have started reworking the content from dnsmasq-pxeboot, because this largely looked like a set of notes rather than step-by-step instructions on configuring dnsmasq. My test lab is configured using libvirt and some of the initial setup is AI-assisted, so I am including attribution. Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a120278c8b
commit
4eb37faa05
1 changed files with 143 additions and 10 deletions
|
|
@ -1,5 +1,5 @@
|
|||
= Setting up dnsmasq - a lightweight DHCP, DNS, and TFTP server
|
||||
Peter Boy; Emmmanuel Seyman, Rowan Puttergill
|
||||
Peter Boy; Emmmanuel Seyman, Jan Kuparinen; Rowan Puttergill
|
||||
:page-authors: {author}, {author_2}
|
||||
:revnumber: F35-F44
|
||||
:revdate: 2026-07-01
|
||||
|
|
@ -141,16 +141,17 @@ bogus-priv
|
|||
# Automatically add <domain> to simple names in a hosts-file.
|
||||
expand-hosts
|
||||
|
||||
# interfaces to listen on
|
||||
interface=lo
|
||||
interface=<ENPxyz>
|
||||
# in case of a bridge don't use the attached server virtual ethernet interface here!
|
||||
# interfaces to listen on
|
||||
interface=lo
|
||||
interface=<ENPxyz>
|
||||
# in case of a bridge don't use the attached server virtual ethernet interface here!
|
||||
|
||||
# Upstream public net DNS server (max.three)
|
||||
no-poll
|
||||
server=<uuu.vv.xx.yy>
|
||||
server=<www.vv.xx.zz>
|
||||
server=<2001:www:xxx:yyy::zz>
|
||||
# Upstream public net DNS server (max.three)
|
||||
no-poll
|
||||
server=<uuu.vv.xx.yy>
|
||||
server=<www.vv.xx.zz>
|
||||
server=<2001:www:xxx:yyy::zz>
|
||||
EOF
|
||||
----
|
||||
+
|
||||
Provide an empty host file
|
||||
|
|
@ -410,3 +411,135 @@ $ sudo nslookup {NAME}
|
|||
$ sudo nslookup {NAME}.example.lan
|
||||
----
|
||||
|
||||
|
||||
== Configuring dnsmasq as a PXE service
|
||||
|
||||
Dnsmasq can be configured to act as a PXE service, by enabling the TFTP server and setting some dhcp-boot directives. In this example, the configuration is extended to provide a PXE service to enable network boot and to configure a Fedora installation over the network.
|
||||
|
||||
See: https://apuntesderootblog.wordpress.com/2020/09/04/pxe-server-in-fedora-with-dnsmasq/[PXE server in Fedora with dnsmasq]
|
||||
|
||||
1. Add a configuration entry to enable the TFTP service in within dnsmasq and to direct DHCP clients to the correct boot loader on the TFTP server:
|
||||
+
|
||||
[source, console]
|
||||
----
|
||||
$ sudo tee /etc/NetworkManager/dnsmasq.d/10-TFTP-example-lan.conf << 'EOF'
|
||||
# Enable TFTP server
|
||||
enable-tftp
|
||||
# dnsmasq serves files from this directory
|
||||
tftp-root=/var/lib/tftpboot
|
||||
|
||||
# Tell DHCP clients where to find the TFTP server and which file to load
|
||||
# Note that legacy BIOS clients use the syslinux boot files, while UEFI clients use
|
||||
# a TFTP Grub EFI binary instead.
|
||||
# We use a dhcp match directive to identify the client-arch in the DHCP request. See RFC 4578 2.1.
|
||||
# BIOS clients have a client-arch=0.
|
||||
# UEFI x86_64 clients have a client-arch=7|9.
|
||||
|
||||
# BIOS clients
|
||||
dhcp-match=set:bios,option:client-arch,0
|
||||
# dhcp-boot=<tag>,<filename>[,<server-name>,<server-ip>]
|
||||
dhcp-boot=tag:bios,pxelinux.0,,10.10.10.1
|
||||
|
||||
# UEFI x86_64 clients
|
||||
dhcp-match=set:efi-x86_64,option:client-arch,7
|
||||
dhcp-match=set:efi-x86_64,option:client-arch,9
|
||||
# dhcp-boot=<tag>,<filename>[,<server-name>,<server-ip>]
|
||||
dhcp-boot=tag:efi-x86_64,grub/grubx64.efi,,10.10.10.1
|
||||
|
||||
EOF
|
||||
----
|
||||
+Since systems using legacy BIOS firmware behave differently to systems using UEFI to handle PXE boot, we use DHCP matching to tag the request for the appropriate client architecture and then provide different DHCP boot instructions depending on the tag. The DHCP boot instructions describe the filename to serve for the given tag, and the server IP where the file can be found. The server IP should be changed to match the IP address of the interface connected to the local network on the dnsmasq host.
|
||||
|
||||
2. Enable access to the TFTP service (UDP port 69) in your firewall. If you're running firewalld, you can do this by running the following commands:
|
||||
+
|
||||
[source, console]
|
||||
----
|
||||
$ sudo firewall-cmd --zone=FedoraServer --permanent --add-service=tftp
|
||||
$ sudo firewall-cmd --reload
|
||||
----
|
||||
|
||||
|
||||
Edit /etc/dnsmasq.conf and configure entries for PXE clients and other systems on the network, for example:
|
||||
|
||||
interface=eth1
|
||||
dhcp-range=10.0.0.101,10.0.0.200,6h
|
||||
dhcp-host=80:00:27:c6:a1:16,10.0.0.253,svr1,infinite
|
||||
dhcp-boot=pxelinux/pxelinux.0
|
||||
enable-tftp
|
||||
tftp-root=/var/lib/tftpboot
|
||||
|
||||
The lines in the sample configuration file do the following:
|
||||
|
||||
interface=eth1
|
||||
|
||||
Listen for incoming client requests on interface eth1 only.
|
||||
dhcp-range=10.0.0.101,10.0.0.200,6h
|
||||
|
||||
Reserve a pool of generally available IP addresses in the range 10.0.0.101 through 10.0.0.200 on the 10.0.0/24 subnet with a six-hour lease.
|
||||
Note
|
||||
|
||||
A dhcp-range setting is required to enable the DHCP service provided by dnsmasq. If you want to configure static addresses but not an address pool, specify a static network address and the keywords static and infinite, for example:
|
||||
|
||||
dhcp-range=10.0.0.253,static,infinite
|
||||
|
||||
dhcp-host=80:00:27:c6:a1:16,10.0.0.253,svr1,infinite
|
||||
|
||||
Reserve the IP address 10.0.0.253 with infinite lease time for svr1, which is identified by the MAC address 08:00:27:c6:a1:16.
|
||||
dhcp-boot=pxelinux/pxelinux.0
|
||||
|
||||
Specify the location of the boot-loader file required by PXE clients. This example supports BIOS-based PXE clients. An entry that supports UEFI-based clients might take the following form:
|
||||
|
||||
dhcp-boot=efi/BOOTX64.efi
|
||||
|
||||
If you want to use a separate TFTP server instead of dnsmasq, specify its IP address after the boot-loader path, for example:
|
||||
|
||||
dhcp-boot=pxelinux/pxelinux.0,10.0.0.11
|
||||
|
||||
enable-tftp
|
||||
|
||||
Enable the TFTP service provided by dnsmasq.
|
||||
tftp-root=/var/lib/tftpboot
|
||||
|
||||
Specify the root directory for files served by TFTP. To prevent clients from accessing any file on the host, dnsmasq rejects requests that specify .. as a path element.
|
||||
|
||||
If you configure dnsmasq to provide the TFTP service:
|
||||
|
||||
Create the TFTP server directories, for example:
|
||||
|
||||
# mkdir -p /var/lib/tftpboot/pxelinux/pxelinux.cfg
|
||||
|
||||
Copy the installation kernel and ram-disk image files to the TFTP server directory hierarchy, for example:
|
||||
|
||||
# wget http://10.0.0.11/OSimage/OL6.6/isolinux/vmlinuz \
|
||||
-O /var/lib/tftpboot/pxelinux/vmlinuz
|
||||
# wget http://10.0.0.11/OSimage/OL6.6/isolinux/initrd.img \
|
||||
-O /var/lib/tftpboot/pxelinux/initrd.img
|
||||
|
||||
This example uses HTTP to obtain the files from an installation server.
|
||||
|
||||
If you want to support BIOS-based PXE clients, install the syslinux package and copy the pxelinux.0 boot loader to the TFTP server directory hierarchy.
|
||||
|
||||
# yum install syslinux
|
||||
# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/pxelinux/pxelinux.0
|
||||
|
||||
If you want to support UEFI-based PXE clients, copy the BOOTX64.efi boot loader and splash image files to the TFTP server directory hierarchy, for example:
|
||||
|
||||
# wget http://10.0.0.11/OSimage/OL6.6/EFI/BOOT/BOOTX64.efi \
|
||||
-O /var/lib/tftpboot/efi/BOOTX64.efi
|
||||
# wget http://10.0.0.11/OSimage/OL6.6/EFI/BOOT/splash.xpm.gz \
|
||||
-O /var/lib/tftpboot/efi/splash.xpm.gz
|
||||
|
||||
Create the default boot loader configuration file, for example efi/efidefault or pxelinux/pxelinux.cfg/default.
|
||||
|
||||
For more information, see Section 1.4.9, “About Boot-Loader Configuration Files”.
|
||||
|
||||
[line-through]#If SELinux is enabled in enforcing mode on your system, use the semanage command to define the default file type of the TFTP server directory hierarchy as tftpdir_t and then use the restorecon command to apply the file type to the entire directory hierarchy, for example:#
|
||||
|
||||
[line-through]#/usr/sbin/semanage fcontext -a -t tftpdir_t "/var/lib/tftpboot(/.*)?"
|
||||
#/sbin/restorecon -R -v /var/lib/tftpboot#
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
If you make any changes to /etc/dnsmasq.conf, restart the dnsmasq service. You do not need to restart the service if you change the content of boot loader configuration files.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue