Skip to content

Instantly share code, notes, and snippets.

@ScatteredRay
Last active July 1, 2020 22:06
Show Gist options
  • Save ScatteredRay/866880084e868bb725da574db3e4523d to your computer and use it in GitHub Desktop.
Save ScatteredRay/866880084e868bb725da574db3e4523d to your computer and use it in GitHub Desktop.
Systemd unique hostname
[Unit]
Description=Generate Unique Hostname
DefaultDependencies=no
Wants=local-fs.target swap.target network-pre.target
After=local-fs.target swap.target
Before=network-pre.target
ConditionPathExists=!/etc/hostname
ConditionPathExists=!/boot/hostname
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c 'echo "rpi-$$(head /dev/urandom | tr -dc 0-9A-Z | head -c 6)" > /etc/hostname && /bin/hostname -F /etc/hostname'
TimeoutSec=30s
[Install]
WantedBy=network.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment