Ubuntu Server 22.04.3 LTS 中 TFTP + ProxyDHCP 的 dnsmasq 配置

Ubuntu Server 22.04.3 LTS 中 TFTP + ProxyDHCP 的 dnsmasq 配置

我正在尝试配置一个 PXE 设置,其中我的 Ubuntu Server 22.04.3 LTS 将充当 TFTP 服务器 + ProxyDHCP(当前 DHCP 服务器必须保持不变)。我在 Google 上搜索了很多,尝试了很多不同的配置,但都没有成功。让我向您展示当前的 /etc/dnsmasq.conf 内容:

#to disable DNS server
port=0

#enable TFTP server and set its root path
enable-tftp
tftp-root=/free/pxe

#enable ProxyDHCP server. The address 192.168.1.2 corresponds to the subnet in which the ProxyDHCP server will act (I read somewhere that any address inside the IP subnet is valid for this)
#The address 192.168.1.2 is that of my Ubuntu Server.
interface=enp2s0
dhcp-range=192.168.1.2,proxy

#boot configuration files for PXE clients
# boot config for BIOS systems
dhcp-match=set:bios-x86,option:client-arch,0
dhcp-boot=tag:bios-x86,firmware/ipxe.pxe
# boot config for UEFI systems
dhcp-match=set:efi-x86_64,option:client-arch,7
dhcp-match=set:efi-x86_64,option:client-arch,9
dhcp-boot=tag:efi-x86_64,firmware/ipxe.efi

目前,TFTP 服务器不工作(尝试使用我的 Windows 10 作为 TFTP 客户端),并且在尝试 PXE 启动时,出现错误“未收到启动文件名”。

如果需要的话,我可以提供更多信息。

谁能告诉我如何正确配置 dnsmasq 来修复 TFTP 和 ProxyDHCP 功能?

答案1

这是dnsmasq我使用的配置,经过修改以匹配您提供的内容。我将其放入/etc/dnsmasq.d/pxe.conf

# Disable DNS Server
port=0

# Enable TFTP server
enable-tftp
tftp-root=/srv/tftp

# Enable DHCP logging
log-dhcp

# Respond to PXE requests for the specified network;
# run as DHCP proxy
dhcp-range=192.168.1.0,proxy,255.255.255.0

# match all pxe clients
dhcp-match=set:pxe,60,PXEClient
# set tag based on client-arch
dhcp-match=set:bios,option:client-arch,0
dhcp-match=set:efi-x86,option:client-arch,6
dhcp-match=set:efi-x86_64,option:client-arch,7
dhcp-match=set:efi-x86_64,option:client-arch,9
dhcp-match=set:efi-arm32,option:client-arch,10
dhcp-match=set:efi-arm64,option:client-arch,11

# match ipxe, which can help chainload
dhcp-match=set:ipxe,175

# bios
pxe-service=tag:pxe,tag:bios,X86PC,"Network Boot BIOS",ipxe.pxe,192.168.1.2

# uefi
pxe-service=tag:pxe,tag:efi-x86_64,x86-64_EFI,"Network Boot UEFI x86_64",ipxe.efi,192.168.1.2

# chainload ipxe
#pxe-service=tag:bios,tag:!ipxe,X86PC,"iPXE BIOS",ipxe.pxe,192.168.1.2
#pxe-service=tag:efi-x86_64,tag:!ipxe,x86-64_EFI,"iPXE UEFI",ipxe.efi,192.168.1.2
#pxe-service=tag:bios,tag:ipxe,X86PC,"iPXE BIOS script",script.ipxe,192.168.1.2

笔记

  • 我在 Ubuntu 20.04 上使用了此配置(dnsmasq 2.90-0ubuntu0.20.04.1)。
  • 这些dnsmasq日志对于调试非常有用。例如journalctl -b -u dnsmasq.service
  • ipxe当我测试它时,它可以与 ProxyDHCP 一起工作,但如果启用了安全启动,它就无法工作。
  • ipxe可能需要链式加载脚本文件。我添加了一个注释掉的示例。
  • 还有其他选择ipxe,每个都有自己的缺点。例如,上次我测试grub 不支持 ProxyDHCP。但是,Fedora 版本的 grub 已经已修补支持ProxyDHCP。

答案2

在分析了 Andrew 的帖子并阅读了以下文档后archlinux 维基管理员经过自我测试,我找到了最终的解决方案,它适用于 BIOS PXE 和 UEFI PXE。文件内容/etc/dnsmasq.d/pxe.conf

#to disable DNS server
port=0

#enable TFTP server and set its root path
enable-tftp
tftp-root=/free/pxe

# Enable DHCP logging
log-dhcp

#enable ProxyDHCP server. The address 192.168.1.0 corresponds to the subnet in which the ProxyDHCP server will act
dhcp-range=192.168.1.0,proxy,255.255.255.0

# bios
pxe-service=x86PC,"Network Boot BIOS",firmware/ipxe.pxe

# uefi
pxe-service=X86-64_EFI,"Network Boot UEFI x86_64",firmware/ipxe.efi

在这种情况下,关键是使用pxe-service条目而不是dhcp-matchdhcp-boot条目。这些肯定适用于其他情况,这些情况可能因操作系统或其他因素而异。我不知道,但只知道在这种情况下,pxe-service条目工作正常。

如果有人需要知道这一点,X86PC值和X86-64_EFI是客户端系统类型,或者加拿大航空正如本文所提到的男人文章:管理员

另外,在本例中,我没有将 TFTP 服务器地址添加到 pxe-service 条目的末尾,因为 TFTP 服务器与 ProxyDHCP 服务器是同一台主机,显然具有相同的地址。但如果是不同的主机,则必须在 pxe-service 语句的末尾添加 TFTP 服务器的 IP 地址,如 man 文章中所述。

相关内容