From nobody Sat Sep 10 17:22:59 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 4MQ07N22Z5z4bX2B for ; Sat, 10 Sep 2022 17:23:12 +0000 (UTC) (envelope-from junchoon@dec.sakura.ne.jp) Received: from www121.sakura.ne.jp (www121.sakura.ne.jp [153.125.133.21]) (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 4MQ07L4THJz3VhX for ; Sat, 10 Sep 2022 17:23:09 +0000 (UTC) (envelope-from junchoon@dec.sakura.ne.jp) Received: from kalamity.joker.local (123-1-88-210.area1b.commufa.jp [123.1.88.210]) (authenticated bits=0) by www121.sakura.ne.jp (8.16.1/8.16.1/[SAKURA-WEB]/20201212) with ESMTPA id 28AHMx4U083797; Sun, 11 Sep 2022 02:23:00 +0900 (JST) (envelope-from junchoon@dec.sakura.ne.jp) Date: Sun, 11 Sep 2022 02:22:59 +0900 From: Tomoaki AOKI To: Guido Falsi Cc: freebsd-hackers@freebsd.org Subject: Re: Dynamic hostname in rc.conf (for bhyve VMs) Message-Id: <20220911022259.a51af1f585f24af6bfb6d4e4@dec.sakura.ne.jp> In-Reply-To: References: Organization: Junchoon corps X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; amd64-portbld-freebsd13.0) 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 Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4MQ07L4THJz3VhX X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of junchoon@dec.sakura.ne.jp has no SPF policy when checking 153.125.133.21) smtp.mailfrom=junchoon@dec.sakura.ne.jp X-Spamd-Result: default: False [-1.59 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; AUTH_NA(1.00)[]; NEURAL_HAM_SHORT(-0.99)[-0.992]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; R_SPF_NA(0.00)[no SPF record]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; RCVD_TLS_LAST(0.00)[]; R_DKIM_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; ASN(0.00)[asn:7684, ipnet:153.125.128.0/18, country:JP]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_SOME(0.00)[]; HAS_ORG_HEADER(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; DMARC_NA(0.00)[sakura.ne.jp]; TO_DN_SOME(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-ThisMailContainsUnwantedMimeParts: N 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. -- Tomoaki AOKI