Skip to content

Instantly share code, notes, and snippets.

@carlosvargasvip
Last active August 2, 2016 18:03
Show Gist options
  • Save carlosvargasvip/d95cf8634ab0aa12965f9362648178e2 to your computer and use it in GitHub Desktop.
Save carlosvargasvip/d95cf8634ab0aa12965f9362648178e2 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Author: Carlos Vargas (ContainerKing.Ninja)
# Filename: /etc/dhcp/dhclient.d/hostname
# Purpose: Used by dhclient-script to set the hostname of the system
# to match the DNS information for the host as provided by
# DHCP.
#
hostname=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1 | awk -F'.' '{print $1"-"$2"-"$3"-"$4}')
echo $hostname > /etc/hostname
hostname $hostname
echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment