Skip to content

Instantly share code, notes, and snippets.

@cfeduke
Created January 7, 2014 15:45
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 cfeduke/8301279 to your computer and use it in GitHub Desktop.
Save cfeduke/8301279 to your computer and use it in GitHub Desktop.
Adds hostname to /etc/hosts (place in /etc/rc.local).
#!/bin/bash
HOSTNAME=`hostname`
ETC_HOSTS=/etc/hosts
if ! grep $HOSTNAME $ETC_HOSTS > /dev/null ; then
if grep "127.0.0.1" $ETC_HOSTS > /dev/null ; then
sed -i "s/127\.0\.0\.1.*$/& $HOSTNAME/" $ETC_HOSTS
else
echo "127.0.0.1 localhost $HOSTNAME" >> $ETC_HOSTS
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment