TFTP and PXE¶
This page lets a computer boot from the network. Ninlil serves the boot file over TFTP (the Trivial File Transfer Protocol, RFC 1350), and a DHCP scope tells the computer which file to fetch and where to fetch it from. The README section is the complete reference.
PXE (Preboot Execution Environment) works in two parts. The computer asks DHCP for an address and
for the name and place of a boot file, then fetches the file over TFTP. The TFTP server is
read-only. It serves the files below one root directory, in binary (octet) mode, in 512-byte
blocks. It is off by default and listens on UDP port 69.
Before you start¶
- A running Ninlil, a signed-in API token and a DHCPv4 scope for the network of the computers that
boot. DHCPv4 scopes, reservations and leases shows both.
<token>and<scope-id>are the values from that page; the commands use the Quick start's HTTPS port18443. - A user that holds
dhcpsettings:writeanddhcpscopes:write. The bootstrap administrator holds every permission. -
A directory with the boot files, readable by the user that runs Ninlil. This page uses
/srv/tftpand a fileboot.binin it. Check them:ls -l /srv/tftp-rw-r--r-- 1 root root 1300 Oct 30 19:24 boot.bin(Your owner, size and date differ.) 4. Port
69is below1024: run Ninlil as root or grantCAP_NET_BIND_SERVICE(see Ports). To try the server without privileges, setNINLIL_DHCP_SERVER_TFTP_PORTto a high port. A PXE computer always asks port69, so use a high port for a test only. 5.curlwith TFTP support, to test the server. Check the protocol list fortftp:curl --version | grep -o tftptftp
The examples call the API on 127.0.0.1 with curl -k, which skips the certificate check.
That is safe only on the machine that runs Ninlil; see Self-signed certificate.
Serve the boot files¶
-
Set the root directory and turn the server on. The settings take effect at the next start:
curl -k -X PATCH https://127.0.0.1:18443/api/dhcp-settings/tftp -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"enable":true,"rootDirectory":"/srv/tftp"}'{"note":"Written to the configuration file. This setting is read once, at startup, so a restart is required before this change takes effect."}The variables are
NINLIL_DHCP_SERVER_TFTP_ENABLEandNINLIL_DHCP_SERVER_TFTP_ROOT_DIRECTORY(see ENVIRONMENT.md). In the console: Presets & Settings, DHCP, the TFTP Server card. Restart Ninlil. The DHCP Services page starts and stops the server without a restart, once a root directory is saved. 2. Read the log. It shows the port the server bound:The TFTP server started and is now bound to UDP port 69.
Point a scope at the boot file¶
-
Tell the computers which file to fetch.
bootFileNameis the name the computer requests, as the TFTP server sees it (relative to the root directory).nextServerAddressis the address of the TFTP server. Without it, Ninlil sends its Server Identifier address:curl -k -X PATCH https://127.0.0.1:18443/api/dhcp-scopes/<scope-id> -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"bootFileName":"boot.bin","nextServerAddress":"192.168.50.2"}'The answer is
204with no body. In the console: DHCP Scopes, edit the scope, PXE boot file name and Next server (TFTP) address. 2. Optional: send a different boot file to computers of one kind. A tag rule can set option67(the boot file name, text) for a vendor class. This rule matches vendor classes that start withPXEClient:Arch:00007(read what your computers send in a packet capture), and697078652E656669isipxe.efi:curl -k https://127.0.0.1:18443/api/dhcp-tag-rules -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"name":"uefi pxe","vendorClassIdentifierMatch":"PXEClient:Arch:00007","vendorClassIdentifierMatchMode":"Prefix","priority":10}' curl -k https://127.0.0.1:18443/api/dhcp-tag-rules/<rule-id>/options -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"optionTag":67,"valueHex":"697078652E656669"}'The first answer holds the rule's
id, which the second command calls<rule-id>. In the console: DHCP Tag Rules.
Check that it worked¶
-
Fetch the file from another machine, with the address of the TFTP server:
curl -s tftp://192.168.50.2/boot.bin -o boot.bin -w '%{size_download}\n'1300The number is the size of the file in bytes. 2. Ask for a file that does not exist.
curlexits with code68(TFTP: file not found):curl -s tftp://192.168.50.2/missing.bin -o /dev/null -w 'curl exit %{exitcode}\n'curl exit 68 -
Read the scope back. A PXE computer receives these two values in the DHCP reply:
curl -k https://127.0.0.1:18443/api/dhcp-scopes/<scope-id> -H 'Authorization: Bearer <token>'{"id":"<scope-id>","name":"lan", ... ,"bootFileName":"boot.bin","nextServerAddress":"192.168.50.2","kind":"AddressAssignment","delegatedPrefixLength":null} -
Check that the server runs. The
Tftpentry shows"isRunning":true:curl -k https://127.0.0.1:18443/api/dhcp-services -H 'Authorization: Bearer <token>'[ ... ,{"kind":"Tftp","enabled":true,"isRunning":true}]
How the server behaves¶
- It serves one directory. A file name may use
/or\between directories (Windows PXE clients send\), and a leading/or\means the root directory. A name that leaves the root with.., and a symbolic link whose target or any step on the way lies outside the root, get an Access Violation error. The root directory itself may be a link. - Read requests, binary mode. A write request gets the error
This TFTP server is read-only.Anetasciiormailrequest getsOnly octet (binary) transfer mode is supported.TFTP options such asblksize(RFC 2347) are ignored, so every transfer uses 512-byte blocks. - Limits. At most
NINLIL_DHCP_SERVER_TFTP_MAX_CONCURRENT_TRANSFERStransfers run at once (50), and at most four of them belong to one client address. A request over a limit is dropped without a reply, because an error packet sent to a forged address would be reflected traffic. Ninlil logs one Warning a minute that counts such drops. An unacknowledged block is sent again afterNINLIL_DHCP_SERVER_TFTP_RETRANSMIT_TIMEOUT(2 seconds), up toNINLIL_DHCP_SERVER_TFTP_MAX_RETRANSMISSIONStimes (5). - Ninlil does not check the boot file name. The scope sends
bootFileNamewhether or not the file exists in the root directory. - DHCP carries the boot file in two places. The scope's boot file name goes into the
filefield of every reply, and into option67when the device lists option67in its Parameter Request List. A tag rule that sets option67changes the option, not thefilefield. The next server address goes intosiaddr, and into option66as text when the device lists it. A custom option or tag-rule option66must be text; use option150for a binary address. - A scope allows 128 bytes of boot file name. This is the size of the
filefield in RFC 2131.
When something goes wrong¶
curlexits with68. The file is missing, or the name does not match. The server's error text is'<name>' does not exist.- The server answers
The requested path is outside this server's configured root directory.The name uses.., or a link leads out of the root. Put the file below the root. - Nothing answers. The log must show
The TFTP server started and is now bound to UDP port 69.If it showsThe TFTP server is enabled but no DhcpServer:Tftp:RootDirectory is configured; it will not bind a socket.or... root directory '<path>' does not exist; it will not bind a socket., fix the root directory and restart. Ninlil keeps running. - The log has
The TFTP server could not bind its socket: Permission deniedorAddress already in use. The process may not open port69, or another program holds it. Ninlil logs one Error, reportsTFTPwith the reason in thedhcpServicescheck ofGET /status, and keeps running. Fix the cause, then start the server again withPOST /api/dhcp-services/Tftp/start.
Next steps¶
- DHCPv4 scopes, reservations and leases: scopes, reservations and options.
- Ports: the ports Ninlil opens.
- README: TFTP and PXE: the complete reference.