How-to randomize your hostname on boot (nix)

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
nix (debianesque distro (check below for feedback))
bash + rc.local for invocation


Don’t use it for daemons and daemon-like (service-like) scripts. Lookup the subject of custom daemons if it interests you.


# 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
# add ipv6 loopback if you use it
DEFL="       localhost"

# if too short, add some len
if [ $PMHR -lt '4' ]

# 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


# has some stuff.... skip

exit 0
Optional log output

<date> <time> Changed from kSVv8pG to cOFCzw6HvkB


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.


This is cool. Maybe I’ll try to port this to OS X just to mess with network logging at Starbucks, etc.

1 Like

I don’t know what you mean by “messing”, but it all comes down to your IP (or the MAC in a LAN). Oaktree or oaktits as a hostname won’t really mess with anything.


I don’t know if you’re aware, but I believe the access points rely on Mac Addresses for identification rather than hostname. Technically no two Mac addresses should exist, but two hostnames certainly could since it’s often user configured.

1 Like

@airth and @pry0cc: I mean “mess” as in leave a screwy-looking trail if/when someone is checking for it.

This topic was automatically closed after 30 days. New replies are no longer allowed.