Skip to content

Instantly share code, notes, and snippets.

@dorentus
Created February 8, 2014 06:03
Show Gist options
  • Save dorentus/8877320 to your computer and use it in GitHub Desktop.
Save dorentus/8877320 to your computer and use it in GitHub Desktop.
/etc/network/if-up.d/auto-hostname
#!/bin/sh
set -e
fqdn=$(dig -x `/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'` +noall +answer | grep PTR | awk '{print $5}')
fqdn=${fqdn%.}
if [ -z $fqdn ]; then
exit 0
fi
HOSTNAME_FILE='/etc/hostname'
echo "$fqdn" > $HOSTNAME_FILE
/bin/hostname -F "$HOSTNAME_FILE"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment