如何在 Debian Jessie 启动时使用脚本设置主机名?

如何在 Debian Jessie 启动时使用脚本设置主机名?

我有一个使用 PXE 启动的 Debian Jessie 安装,我需要使用脚本在启动时设置主机名。

我在之前的 Debian 版本中使用了 /etc/init.d/hostname.sh,但它似乎没有在启动时执行。可能是因为 systemd。

答案1

检查您是否授予了脚本的执行权

#chmod +x hostname.sh

为什么不使用 DHCP 选项 12?

https://www.rfc-editor.org/rfc/rfc1533

3.14. Host Name Option
   This option specifies the name of the client.  The name may or may
   not be qualified with the local domain name (see section 3.17 for the
   preferred way to retrieve the domain name).  See RFC 1035 for
   character set restrictions.

   The code for this option is 12, and its minimum length is 1.

    Code   Len                 Host Name
   +-----+-----+-----+-----+-----+-----+-----+-----+--
   |  12 |  n  |  h1 |  h2 |  h3 |  h4 |  h5 |  h6 |  ...
   +-----+-----+-----+-----+-----+-----+-----+-----+--

編輯_1

您还可以在“append”行中添加 deb-conf 变量“hostname”作为内核参数,即

 append  initrd=xxx/www/zzz.img  hostname=myhostname ....

相关内容