[ipxe-devel] help ipxe script
Christian Nilsson
nikize at gmail.com
Tue Apr 26 16:41:26 UTC 2016
On Tue, Apr 26, 2016 at 4:45 AM, deepfreeze <zulinfi at 163.com> wrote:
> hi,
> ipxe
> I have a trouble
> in the ipxe script , I would get a val is the fourth segment value of ip
> address, when dhcp , the client ip is 192.168.1.88, can I get the "88" to
> set the hostname val is "pc-88"?
>
> 你好,
> 原谅我的蹩脚英文.
> 我想问的是如何在ipxe 的脚本文件中, 动态得到ip地址段的最后一节数值赋值给工作端hostname变量, 比如 192.168.1.88
> ,最终hostname 是 pc-88 192.168.1.89 ,最终hostname 是 pc-89.
>
>
Hi,
There is no client side functions to cut variables in ipxe script.
The most commonly used method is to send ip to a server side script
that then returns a script that does the work.
Here is a quickly hacked example: (with no concideration to ipv6 or security)
getiphostname.php:
<?php
$ip = $_GET["ip"];
header("Content-Type: text/plain");
echo "#!ipxe\n";
echo "set hostname pc-".substr($ip, strrpos($ip, ".") + 1)."\n";
?>
call this with:
chain http://server/path/getiphostname.php?ip=${ip}
and hostname will be set to pc-(last octet of ipv4)
An alternative to this if you are using dhcp, is to have the dhcp
server define and send hostname if ipxe is the dhcp client.
/Christian
More information about the ipxe-devel
mailing list