Last active
August 29, 2015 14:08
-
-
Save voxxit/4891917f9ac0bcb90620 to your computer and use it in GitHub Desktop.
Script to change hostname on Ubuntu >= 13.04
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 | |
# | |
# Example: | |
# | |
# \curl -fsSL http://srv.im/change-hostname.sh | sudo bash /dev/stdin hostname.example.com | |
_hostname="$1" | |
_dnsline="127.0.1.1\t$1" | |
hostnamectl set-hostname ${_hostname} | |
if grep -q 127.0.1.1 /etc/hosts | |
then | |
sed -i "s/127.0.1.1.*/${_dnsline}/g" /etc/hosts | |
else | |
echo -e ${_dnsline} >> /etc/hosts | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment