Date: Thu, 18 Mar 2010 13:37:37 +0000 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: freebsd-questions@freebsd.org Subject: Re: Generating a random hostname Message-ID: <4BA22CA1.7050705@infracaninophile.co.uk> In-Reply-To: <7B9397B189EB6E46A5EE7B4C8A4BB7CB3B27E0E5@MBX03.exg5.exghost.com> References: <7B9397B189EB6E46A5EE7B4C8A4BB7CB3B27DFDA@MBX03.exg5.exghost.com> <4BA1E51F.20304@infracaninophile.co.uk> <4BA1EFF8.7030907@infracaninophile.co.uk> <7B9397B189EB6E46A5EE7B4C8A4BB7CB3B27E0E5@MBX03.exg5.exghost.com>
next in thread | previous in thread | raw e-mail | index | archive | help
-----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-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4BA22CA1.7050705>