From nobody Sat Sep 17 16:35:26 2022 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MVGlG3v0lz2l1t8 for ; Sat, 17 Sep 2022 16:35:38 +0000 (UTC) (envelope-from mad@madpilot.net) Received: from mail.madpilot.net (vogon.madpilot.net [159.69.1.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4MVGlF37pZz3W88 for ; Sat, 17 Sep 2022 16:35:37 +0000 (UTC) (envelope-from mad@madpilot.net) Received: from mail (mail [192.168.254.3]) by mail.madpilot.net (Postfix) with ESMTP id 4MVGl61yWJz6fYm; Sat, 17 Sep 2022 18:35:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=madpilot.net; h= content-transfer-encoding:content-type:content-type:in-reply-to :from:from:content-language:references:subject:subject:date:date :message-id:received; s=bjowvop61wgh; t=1663432527; x= 1665246928; bh=gaRLuHmzY+VYkqjoPBPBjiNql8Nn/4qIALjsehk7tfA=; b=K ccgrV9O6v7OJwlGJtCsH3B+FaRDXQoJsL/9LwipoAE5FSdqz8Bl18EF5iaSxZgV0 boWbSXkyJXKR0y7Mq49hgD/psOCiE+G+JOXEJrMqHaxRWwW2+hN1DUJkPGNTy4JV OR5+k+y8Ydj08sKv0eyNa1Ay+Zqog4NPui9lrTyqIFiJHi2qfa2BXjzj96uUdwDJ NK+sbzNHoY1BFk5A4Pard/+TYrfQozTeeUozwY5inUZs67m15ZZPNva8kQpGag0+ ppNjl45ODg2RoLxXpiiWfIL/4rrLpieX2/XcaRltGpMNYYX5j9qzOLgwM2Z4TrwS loDP/td84qu9LbIDx1FZQ== Received: from mail.madpilot.net ([192.168.254.3]) by mail (mail.madpilot.net [192.168.254.3]) (amavisd-new, port 10026) with ESMTP id X9A66iasDVYL; Sat, 17 Sep 2022 18:35:27 +0200 (CEST) Message-ID: Date: Sat, 17 Sep 2022 18:35:26 +0200 Subject: Re: Dynamic hostname in rc.conf (for bhyve VMs) To: Tomoaki AOKI Cc: freebsd-hackers@freebsd.org References: <20220911022259.a51af1f585f24af6bfb6d4e4@dec.sakura.ne.jp> Content-Language: en-US From: Guido Falsi In-Reply-To: <20220911022259.a51af1f585f24af6bfb6d4e4@dec.sakura.ne.jp> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4MVGlF37pZz3W88 X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=madpilot.net header.s=bjowvop61wgh header.b="K ccgrV9"; dmarc=pass (policy=quarantine) header.from=madpilot.net; spf=pass (mx1.freebsd.org: domain of mad@madpilot.net designates 159.69.1.99 as permitted sender) smtp.mailfrom=mad@madpilot.net X-Spamd-Result: default: False [-1.57 / 15.00]; MISSING_MIME_VERSION(2.00)[]; NEURAL_HAM_SHORT(-0.99)[-0.986]; NEURAL_HAM_LONG(-0.94)[-0.939]; NEURAL_HAM_MEDIUM(-0.65)[-0.646]; DMARC_POLICY_ALLOW(-0.50)[madpilot.net,quarantine]; R_SPF_ALLOW(-0.20)[+mx]; R_DKIM_ALLOW(-0.20)[madpilot.net:s=bjowvop61wgh]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[madpilot.net:+]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; TO_DN_SOME(0.00)[]; ASN(0.00)[asn:24940, ipnet:159.69.0.0/16, country:DE]; RCVD_COUNT_THREE(0.00)[3]; MID_RHS_MATCH_FROM(0.00)[] X-ThisMailContainsUnwantedMimeParts: N List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org On 10/09/22 19:22, Tomoaki AOKI wrote: > On Sat, 10 Sep 2022 10:52:01 +0200 > Guido Falsi wrote: > >> 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 >> > > IIUC, and if you obtain IP addresses of each VMs via DHCP, > just keeping hostname on rc.conf would be suffice. > > /etc/rc.d/hostname has a functionality to get hostname by > hostname=`/bin/kenv dhcp.host-name`, meaning hostname is set using > what DHCP server supplied, if NOT in a jail. > > See the script for details. > Hi! Sorry for the delay in replying. Thanks for your suggestion of using kenv, I completely overlooked that! It was the missing piece for me. In fact my basic idea almost works perfectly once I use kenv to read variables passed by bhyveload. Only problem is that the vm configuration file used bu vm-bhyve is not a shell script but treated as a key pair. So i can't do logic in there. I ended up creating a very simple local patch to vm-bhyve here that does what I need: https://github.com/madpilot78/vm-bhyve/tree/bhyveload_pass_vm_hostname I think I will propose the patch upstream too, maybe with some cleanup. So thanks again! -- Guido Falsi