Dynamic hostname in rc.conf (for bhyve VMs)

From: Guido Falsi <mad_at_madpilot.net>
Date: Sat, 10 Sep 2022 08:52:01 UTC
Hi,

Since rc.conf is just a shell script I'd like to be able to set hostname 
dynamically.

This is bhyve related because what I'd like to do is pass an hostname to 
VMs via the -e option to bhyveload(8), and then read it in rc.conf, 
maybe via sysctl to set the hostname accordingly.

By the way I'm using vm-bhyve [1] to manage my VMs. its configuration 
files are also shell scripts, so I was planning to hack some simple 
logic there, host side, to derive the hostname from filesystem (useful 
for cloned VMs).

Could not find any example or documentation about any step of this.

Is this even possible with current tools? I'm open to hacky solutions to 
start with, then maybe refine them.


I'm trying to do this because I'm using a local dnsmasq that exposes DNS 
with the hostnames provided by VMs, but clones get the same naem as the 
machien they're cloned from and mask those in this small internal DNS. 
If each clone could provide it's different name it would be much better.


Thanks in advance for any help/suggestions.


[1] https://github.com/churchers/vm-bhyve

-- 
Guido Falsi <mad@madpilot.net>