Linux for Radio Astronomy

How to rename an Ubuntu computer

You can rename your Ubuntu PC (i.e. change the hostname) in a few simple steps. Here’s how, depending on your Ubuntu version and whether you want to do it temporarily or permanently:


🧭 Check your current hostname

Open a terminal and run:

hostnamectl

This shows something like:

Static hostname: oldname
Pretty hostname: (none)
Transient hostname: oldname

🧱 To permanently rename your Ubuntu PC

Use the hostnamectl command:

sudo hostnamectl set-hostname newname

Replace newname with your desired hostname (no spaces, use hyphens if needed, e.g. lichfield-observatory).


🔄 Update the hosts file

Edit /etc/hosts so your local loopback points to the new hostname:

sudo nano /etc/hosts

Change the line that looks like:

127.0.1.1    oldname

to:

127.0.1.1    newname

Save and exit (Ctrl+O, Enter, Ctrl+X).


♻️ Apply the change

You can either reboot:

sudo reboot

Or reload the hostname service:

sudo systemctl restart systemd-logind.service

✅ Verify

After reboot or restart, check again:

hostnamectl

You should see your new name listed.


Would you like me to show how to do this through the GUI (Settings) as well, if you’re using Ubuntu Desktop?

Certainly 👍 — here’s how to rename your Ubuntu PC using the graphical interface (GUI) on Ubuntu Desktop:


🖥️ For Ubuntu 22.04, 24.04, or later

  1. Open Settings
    • Click the system menu in the top-right corner of your screen (where the power and network icons are).
    • Choose ⚙️ Settings.
  2. Go to “About”
    • In the left sidebar, scroll down and click About (at the bottom).
  3. Find the Device Name
    • You’ll see a section labeled Device Name — this is your current hostname.
  4. Click the Device Name
    • A text box appears; type your new name.
      (Use lowercase letters, numbers, and hyphens only — no spaces or special characters.)
  5. Press Enter or click Rename.
    • Ubuntu saves the new hostname immediately.
  6. Reboot your computer to make sure all services pick up the new name.

🧾 Example

If it currently says:

Device Name: ubuntu-desktop

Change it to:

Device Name: lichfield-observatory

After reboot, you can confirm it worked by opening a terminal and running:

hostname

It should now show:

lichfield-observatory

Would you like me to include how to rename it remotely (e.g. via SSH) if the machine doesn’t have a GUI or you manage it headlessly?

Perfect — here’s how to rename an Ubuntu system remotely via SSH, safely and permanently.


🛰️ Step 1. Connect to your Ubuntu machine

From another computer, open a terminal and SSH in:

ssh username@ip_address

Example:

ssh andrew@192.168.1.42

🧱 Step 2. Check the current hostname

Once connected:

hostnamectl

Example output:

Static hostname: oldname
Pretty hostname: (none)
Transient hostname: oldname

⚙️ Step 3. Set the new hostname

Run:

sudo hostnamectl set-hostname newname

Example:

sudo hostnamectl set-hostname lichfield-observatory

(No spaces; use hyphens if you like.)


🧾 Step 4. Update /etc/hosts

Still in the SSH session:

sudo nano /etc/hosts

Look for this line:

127.0.1.1    oldname

Change it to:

127.0.1.1    newname

Save and exit (Ctrl+O, Enter, Ctrl+X).


🔄 Step 5. Apply the change

You can either:

sudo reboot

or, if you want to avoid rebooting:

sudo systemctl restart systemd-logind.service

Your SSH session may disconnect if you reboot — that’s normal.


✅ Step 6. Verify

After reconnecting:

hostnamectl

You should see:

Static hostname: lichfield-observatory

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.