iPXE discussion forum

Full Version: Transfer boot file base on client's MAC
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there,

I see this script on the homepage:

Code:
if exists user-class and option user-class = "iPXE" {
      filename "http://my.web.server/real_boot_script.php";
  } else {
      filename "undionly.kpxe";
  }

Can you show me how to make the script "real_boot_script.php" change the filename based on client's MAC ?

For example, a client with MAC aa-bb-cc-dd-ee-ff requests the DHCP. I want DHCP to transfer the boot script aa-bb-cc-dd-ee-ff.php to it. If this file is not existed, the default.php will be chose.
This is how I do it with an iPXE script instead of having to declare it all in the DHCP server. https://gist.github.com/robinsmidsrod/2234639

Check boot.ipxe which optionally loads an override script for a specific machine (based on hostname, ip, uuid, mac or nic driver) and boot/testvm.ipxe which is a customization based on the hostname assigned to the machine.
(2014-03-07 08:51)vielktus Wrote: [ -> ]Can you show me how to make the script "real_boot_script.php" change the filename based on client's MAC ?

You can include ${mac} within the DHCP filename, e.g.:

Code:
filename "http://my.web.server/boot.php?mac=${mac}";

Alternatively, you can use an iPXE script. This gives you the option to fall back to an alternative script if the one you want doesn't exist. For example:

Code:
#!ipxe
chain http://my.web.server/${mac:hexhyp}.php || chain http://my.web.server/default.php

(Note the use of the ":hexhyp" settings type to obtain the MAC address with hyphen separators rather than colons, since colons are generally not valid in filenames.)

Michael
The "mac:hexhyp" and "github" saved my day.
Thank you so much mcb30 and robin.
Reference URL's