Skip to content

Instantly share code, notes, and snippets.

@fegue
Created March 17, 2022 21:57
Show Gist options
  • Save fegue/d1e0c1228fff9909758e4a55040a201c to your computer and use it in GitHub Desktop.
Save fegue/d1e0c1228fff9909758e4a55040a201c to your computer and use it in GitHub Desktop.
Set hostname on raspberry pi
#!/bin/sh
if test $# -eq 0
then
echo "No name on command line."
exit 1
fi
echo $1
NAME=$1
echo $NAME
echo $NAME | sudo tee /etc/hostname
sudo sed -i -e 's/^.*hostname-setter.*$//g' /etc/hosts
echo "127.0.1.1 " $NAME " ### Set by hostname-setter" | sudo tee -a /etc/hosts
sudo service hostname.sh stop
sudo service hostname.sh start
echo "Hostname set. Log out to see it on the command line"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment