create a file name nextboot.sh
#!/bin/bash
basename="nextboot"
uuid=$(cat /proc/sys/kernel/random/uuid)
echo $uuid
echo "renaming $HOSTNAME to $basename-$uuid"
sudo sed -i "s/$HOSTNAME/$basename-$uuid/" /etc/hosts /etc/hostname
sudo rm $0
sudo reboot
chmod +x nextboot.sh
sudo cp nextboot.sh /opt
sudo vim /etc/rc.local
add the following before exit 0
. make sure the path to your program is right.
if test -f "/opt/nextboot.sh"; then
/opt/nextboot.sh
fi