If you’ve ever set up a Linux distribution like Ubuntu, you may have noticed the installer prompts you to enter a name for your machine. Commonly called the hostname, it’s the name that identifies your Linux system every time you connect to another device over a network or Bluetooth connection.
After reviewing all the settings, toggles, and options during the installation procedure, you may have accidentally entered the wrong hostname. But don’t worry — Ubuntu lets you change your system’s hostname via GUI and a variety of terminal commands.
These steps will be valid for Ubuntu 23.04, but they should be similar to other versions of Ubuntu.
Related
Best laptops for Linux in 2024
Looking for a new laptop that can run Linux? Here’s our take on the best Linux laptops that you can buy right now.
How to change the hostname on Ubuntu with the Settings app
Similar to the process on Windows 11, if you want to change the hostname of an Ubuntu system, you can just head into the Settings app. The GUI makes it easy, which is the method we suggest most people use.
- Click on the power button and choose Settings (or a cog wheel).
- Click System.
- Click About.
- Enter a new device name in the top field.
You don’t need to restart your system after changing the hostname. The change should take effect right away. Some apps might not see the name change, though, and if this is the case, simply reboot your PC.
How to change the hostname on Ubuntu with the terminal
More advanced Ubuntu users might want to change the hostname using the terminal. This method requires you to enter a few commands. You won’t have to reboot your system, either.
- Open the terminal (Ctrl+Alt+T).
- Set a new hostname using the following command:
hostnamectl set-hostname new-hostname
(Be sure to replace “new-hostname” with the actual hostname you want to use.)
- Confirm the hostname was changed:
hostnamectl
Related
How to run an Ubuntu virtual machine on Apple Silicon for free
You can run a Ubuntu Virtual Machine on Apple Silicon for free, and here’s one of the ways to do so.
How to change the hostname on Ubuntu via configuration files
Since Ubuntu uses the hostname and host configuration files to store the name of your PC, you can rename it by replacing the old hostname with the name you wish to give your system.
- Open the terminal.
- Open the hostname file using the nano editor:
sudo nano /etc/hostname
- Overwrite the older name with the new hostname.
- Press Ctrl+X to exit the file. Be sure to tap Y when prompted to save the changes.
- Open the hosts config file:
sudo nano /etc/hosts
- Rename the string adjacent to the 127.0.1.1 IP address to the new hostname.
- Hit Ctrl+X followed by Y to save and exit the hosts file.
- (Optional) If you’re running Ubuntu as a cloud instance with the help of the cloud-init utility, you’ll need to modify a third config file called cloud.cfg. Simply open the file with this command and ensure the preserve_hostname string has the value true assigned to it.
sudo nano /etc/cloud/cloud.cfg
After using this method, you’ll need to restart your system for Ubuntu to reflect the hostname changes.
How to temporarily change the hostname on Ubuntu
It’s also possible to temporarily change the hostname on Ubuntu. This is handy if you don’t wish the hostname to remain changed.
- Open the terminal.
- Change the hostname temporarily:
sudo hostname new-hostname
(Replace “new-hostname” with the actual hostname you want to use.)
- Enter your password when prompted by Ubuntu.
Once you finish, you can confirm the hostname was changed with the hostname command.
What hostname did you pick for your Ubuntu PC?
Those are all the ways you can change the hostname on Ubuntu. Apart from the last method, every other procedure results in a permanent change in the hostname, though you can modify it as many times as you wish.
If you’re curious about Ubuntu, be sure to check out our detailed setup guide for the OS. We also have other articles that may interest developers, such as those on configuring environment variables and installing Anaconda and AWS CLI on Ubuntu.