On Tue, Feb 28, 2012 at 12:08 AM, Jason Heeris <jason.hee...@gmail.com> wrote: > On 28 February 2012 13:40, Tom H <tomh0...@gmail.com> wrote: >> Everywhere that I've worked the hostnames have had something to >> indicate its purpose and its location. > > I don't think this reasoning can be applied here though. There will be > dozens of identical devices plugged into the network, and hundreds in > total (but not all plugged in at the same time). They can't all have > the same name, and the IP address is useless as an identifier since > the physical location could change daily until it goes out the door. > >> The "mv /etc/rc.local.final /etc/rc.local" would be the last line in >> the first-boot's "/etc/rc.local" so that your "/dev/random" hostname >> stuff only runs once. I've just tried it and it was OK. > > Oh, right, that makes sense now.
I think all you may need to do is put this in /etc/rc.local (and avoid any sort of moving files around or having some sort of "first-boot" snafu): /bin/echo dt$(/sbin/ifconfig eth0 | head -1 | awk -F: '{print $4$5$6}') > /etc/hostname /etc/init.d/hostname.sh start That will create a hostname of dt + the last 6 characters of the MAC address of eth0, dump that into /etc/hostname, and then "start" the hostname.sh "service" which simply sets the hostname. You can read what it does in /etc/init.d/hostname.sh. On my system, this gives a hostname of dt7281d9 which I picked sort of at random. Since you're testing things I picked a prefix of dt for "device test" and then the 6 (presumably unique) characters from the MAC address. This gives you an 8 character hostname. If you want something with less of the MAC address in there, change the awk statement and prefix: echo test$(/sbin/ifconfig eth0 | head -1 | awk -F: '{print $5$6}') > /etc/hostname service hostname.sh start This one will give you, on my system, test81d9. You can use whatever scheme you like and you never need change it. You can just leave that in place and it will have no effect after the first run (just remove the lines if you'd like to manually set a hostname). At first boot, the system will have whatever hostname was set in the installer up until /etc/rc.local runs, at which point the hostname will change to your chosen scheme, and will stay that way until those lines are removed from /etc/rc.local and you set something else in /etc/hostname, or you change the Ethernet hardware. -- Chris -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/caoevnyutkpkg0yzdno1e7t_wc7r1_re5rifvcmw7ewfhfn4...@mail.gmail.com