Created
January 31, 2015 22:12
-
-
Save cnbeining/320989020549da6b9285 to your computer and use it in GitHub Desktop.
Change hostname
This file contains 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
#!/bin/bash | |
#Assign existing hostname to $hostn | |
hostn=$(cat /etc/hostname) | |
#Display existing hostname | |
echo "Existing hostname is $hostn" | |
#Ask for new hostname $newhost | |
echo "Enter new hostname: " | |
read newhost | |
#change hostname in /etc/hosts & /etc/hostname | |
sudo sed -i "s/$hostn/$newhost/g" /etc/hosts | |
sudo sed -i "s/$hostn/$newhost/g" /etc/hostname | |
#display new hostname | |
echo "Your new hostname is $newhost" | |
#Press a key to reboot | |
read -s -n 1 -p "Press any key to reboot" | |
sudo reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment