Change hostname from DNS server

Sometimes, your want to change your hostname, more precisely you want your hostname actually reflecting your DNS change.

I won't talk when such a situation happen, but it could happen. So here is how I manage it. This above script runs under Ubuntu, but it should also runs under any distro which use NetworkManager.

Drop this file into /etc/NetworkManager/dispatcher.d

Basically, it perform a DNS request, then compare the result to the hostname already defined. If the hostname has changed, the script update the network system files.