From owner-freebsd-questions@FreeBSD.ORG Thu Mar 18 13:37:42 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2F35A106566B for ; Thu, 18 Mar 2010 13:37:42 +0000 (UTC) (envelope-from m.seaman@infracaninophile.co.uk) Received: from smtp.infracaninophile.co.uk (gate6.infracaninophile.co.uk [IPv6:2001:8b0:151:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id AAEC98FC1D for ; Thu, 18 Mar 2010 13:37:41 +0000 (UTC) Received: from seedling.black-earth.co.uk (seedling.black-earth.co.uk [81.187.76.163]) (authenticated bits=0) by smtp.infracaninophile.co.uk (8.14.4/8.14.4) with ESMTP id o2IDbboB034419 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Thu, 18 Mar 2010 13:37:37 GMT (envelope-from m.seaman@infracaninophile.co.uk) Message-ID: <4BA22CA1.7050705@infracaninophile.co.uk> Date: Thu, 18 Mar 2010 13:37:37 +0000 From: Matthew Seaman Organization: Infracaninophile User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-GB; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: freebsd-questions@freebsd.org References: <7B9397B189EB6E46A5EE7B4C8A4BB7CB3B27DFDA@MBX03.exg5.exghost.com> <4BA1E51F.20304@infracaninophile.co.uk> <4BA1EFF8.7030907@infracaninophile.co.uk> <7B9397B189EB6E46A5EE7B4C8A4BB7CB3B27E0E5@MBX03.exg5.exghost.com> In-Reply-To: <7B9397B189EB6E46A5EE7B4C8A4BB7CB3B27E0E5@MBX03.exg5.exghost.com> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: clamav-milter 0.95.3 at happy-idiot-talk.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_ADSP_ALL, SPF_FAIL autolearn=no version=3.3.0 X-Spam-Checker-Version: SpamAssassin 3.3.0 (2010-01-18) on happy-idiot-talk.infracaninophile.co.uk Subject: Re: Generating a random hostname X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Mar 2010 13:37:42 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 18/03/2010 11:57:56, Peter Steele wrote: >> Thinking about this some more, a good trick would be to generate a >> hostname from the MAC address of the host, since that is guaranteed >> to be unique. > > In fact, this is what we are currently using. Unfortunately I guess I > wasn't entirely clear. I was looking for a facility that actually > *assigns* a random hostname, similar to what's provided in Windows. > Generating the string itself obviously can be done in any number of > ways, but once you have the string, there are at least of couple of > files where this name needs to be inserted (/etc/hosts, > /etc/rc.conf). When you create a master image in Windows, you can > have it automatically assign a random hostname the first time the > cloned image is booted. That's what I was looking for. My guess is > that I'm going to have to update these files manually, running a > script for example via rc.conf that disables itself after the first > time the system boots. Ahah! Why didn't you say so? That's pretty simple really. Once you've generated the hostname, just use hostname(1) to make it the live name of the machine. This would have to be done with a small shell script, yes. Probably the easiest way to do that is a small RC script set to run just before /etc/rc.d/hostname, and that stole^Wborrowed most of the logic from that script about kenv and DHCP names, and hostname already being set. The core actions that script has to do are: if [ -z ${hostname} ] ; then hostname=$( generate_hostname ) /bin/hostname "${hostname}.example.com" echo hostname=\"${hostname}.example.com\" >> /etc/rc.conf fi Once hostname is set in /etc/rc.conf, this script will do nothing, and the regular /etc/rc.d/hostname script will operate normally. Setting the hostname with /bin/hostname is all that is specifically necessary for the local machine. It doesn't really need to be added to /etc/hosts, although that's not a bad idea. An alternative might be to run everything using DHCP and get the DHCP server to generate names and dish them out to the clients. Of course, it would be good to add the new hostname to some sort of networked database, like the DNS or NIS or LDAP so that other hosts can know how to get to it, but that's a different problem. Cheers, Matthew - -- Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.14 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkuiLKEACgkQ8Mjk52CukIz1HgCeNa1kZhojxvBYNKWmYixoSGFv e+gAnj4WEHRjzghZ0fmt2xTv1FvaAWGQ =DUDg -----END PGP SIGNATURE-----