Skip to content

Instantly share code, notes, and snippets.

@fabiosoft
Created February 10, 2014 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiosoft/8923713 to your computer and use it in GitHub Desktop.
Save fabiosoft/8923713 to your computer and use it in GitHub Desktop.
Change Hostname for Raspberry Pi Raspbian Wheezy OS. Fabio Nisci
#!/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