Last active
July 1, 2020 22:06
-
-
Save ScatteredRay/866880084e868bb725da574db3e4523d to your computer and use it in GitHub Desktop.
Systemd unique hostname
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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