Skip to content

Instantly share code, notes, and snippets.

@swagfin
Created March 25, 2025 15:38
Show Gist options
  • Save swagfin/7a548ae887086e1b86c993cec63e41c0 to your computer and use it in GitHub Desktop.
Save swagfin/7a548ae887086e1b86c993cec63e41c0 to your computer and use it in GitHub Desktop.
Updating Ubuntu Hostname After Cloning a Disk

Updating Ubuntu Hostname After Cloning a Disk

Step 1: Change the Hostname

Update the hostname using the hostnamectl command:

sudo hostnamectl set-hostname NEW_HOSTNAME

Step 2: Update /etc/hostname

Edit the file manually:

sudo nano /etc/hostname

Replace the existing hostname with NEW_HOSTNAME, then save (CTRL + X, then Y, then ENTER).

Step 3: Update /etc/hosts

Edit the /etc/hosts file:

sudo nano /etc/hosts

Replace any instances of the old hostname with NEW_HOSTNAME. Ensure the file contains:

127.0.0.1   localhost
127.0.1.1   NEW_HOSTNAME

Save and exit.

After completing these steps, the system will use the new hostname upon reboot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment