#!/bin/sh IP=$(hostname -I | awk '{print $1}') HOSTNAME=$(getent hosts | grep $IP | awk '{print $2}') if [ -n "$HOSTNAME" ]; then hostnamectl set-hostname "$HOSTNAME" echo "Hostname set to $HOSTNAME" else echo "Hostname not found for IP $IP" fi