Created
February 10, 2014 20:37
-
-
Save fabiosoft/8923713 to your computer and use it in GitHub Desktop.
Change Hostname for Raspberry Pi Raspbian Wheezy OS. Fabio Nisci
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 | |
echo "Change Hostname Permanently" | |
echo "Script by Fabio Nisci 2014" | |
echo "Enjoy." | |
# Only root can! | |
if [[ $EUID -ne 0 ]]; then | |
echo "Run this script as ROOT o SUDO" 1>&2 | |
exit 1 | |
fi | |
#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 | |
sed -i "s/$hostn/$newhost/g" /etc/hosts | |
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 "For Permanently change it, I need to reboot. Press any key when you are ready..." | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment