Usability of a hostname is a relative thing; from generic ones, which seldom hold any meaning, to production ones, which can even tell you a physical location of a server. But all hostnames have one thing in common: they get logged.
Around the site you’ll find various topics on why you should care 'bout anonymity, so I won’t repeat such points here.
Viability of random hostnames
Some can argue that a random hostname is like a ‘fist to the eye’ - that it’s bound to get noticed.
And they would be right.
But always try to guess ‘who is on the other side’.
A standard user could not even know what a hostname is, or if he/she sees it: “it’s just some computer gibberish”.
An admin could think that it’s a malformed string in a log, or not even see it among other stuff he/she looks at.
And all the possible scenarios in between…
On the plus side, you’ll have one more random identifier. You can circumvent hostname blacklisting (still happens). IMHO, in various use cases which can be found around this site, a random hostname is better than a static one. In the end, the choice is yours =)
Logical steps:
boot > invoke script > script changes hostname (optional: log change) > resume boot > login
Inventory:
nix (debianesque distro (check below for feedback))
bash + rc.local for invocation
rc.local
Don’t use it for daemons and daemon-like (service-like) scripts. Lookup the subject of custom daemons if it interests you.
namechanger.sh
#!/bin/bash
# old hostname
# if -a (alias) is blank, you can use it without a
# switch, or with -s (short)
ALDN=$(hostname -a)
# number of chars in new hostname from hour
PMHR=$(date +%-I)
# path to log
LGFL="/some/dir/logs/namechanger.log"
HSFL="/etc/hosts"
# add ipv6 loopback if you use it
DEFL="127.0.0.1 localhost"
# if too short, add some len
if [ $PMHR -lt '4' ]
then
PMHR=$((PMHR+3))
fi
# pull a random alnum str from with spec len from urandom
NWDN=$(cat /dev/urandom | tr -dc [:alnum:] | head -c$PMHR)
# push to hosts, incl. defaults
echo "$DEFL $NWDN" > $HSFL
# log if you want/need
NOW=$(date +%y-%m-%d' '%H:%M:%S)
echo "$NOW Changed from $ALDN to $NWDN" >> $LGFL
# service-type set
hostnamectl set-hostname $NWDN
# restart networking
service networking stop
sleep 1
service networking start
# whitelist with X serv
xhost +$NWDN
exit
/etc/rc.local
# has some stuff.... skip
/some/dir/namechanger.sh
exit 0
Optional log output
<date> <time> Changed from kSVv8pG to cOFCzw6HvkB
Feedback
I hope that this snippet will prove useful to you, and I appreciate any feedback u give, especially if you test it / adapt it for a RHELoesque distro.