How to change computer name ubuntu
How to change computer name ubuntu
How to change the Computer name in Ubuntu 20.04 Linux
If you have just installed a new Ubuntu 20.04 Linux on your PC or Laptop and it has used the system’s OS as a computer name, then you can change it. Or you are just a beginner who has set the Linux hostname something, let’s say ‘John’ but after some time you would like to change and reset the computer name to ‘JohnPc’. Then for sure, you might be looking for a way to remove the existing hostname of your Ubuntu 20.04/18.04/19.04/16.04 PC or Laptop. If yes, then this tutorial will help you with that.
What do we learn in this tutorial?
Things we need?
Ubuntu Linux system 20.04,19.04,18.04,17.04,16.04… other open-source Linux OS such as Linux Mint, Elementary OS, Debian are also can be used to follow the below steps. Remember the hostname and Computer name both are the same things.
Note: If you don’t want to use the Command line method and running a graphical user interface then use that: How to change Ubuntu Linux Device name Graphically
Change Ubuntu Linux computer name using the command terminal
1: Open a command terminal.
2: Command to check the Ubuntu Linux computer name
First, check the existing Ubuntu hostname of your PC. In case you don’t know it then this will apprise you that. However, the name on command terminal just before the :$ and after the @ is the one you want to change. To get the detail info type: hostnamectl
3: Edit Hostname file
Use VIM or Nano editor to open the /etc/hostname file which contains the computer name of your Linux PC or laptop. The command to edit and update is:
When the above file will open you will see the existing name of your computer just delete and type the one you want to use.
To save and exit Nano editor: Ctrl+X and type Y followed by the Enter button.
How to Change Computer Name (aka hostname) in Ubuntu 21.10
This simple tutorial shows you how to change the hostname (also known as computer name) in Ubuntu 21.10 Impish Idri.
The computer name is a unique identifier given to each computer. It’s not a big deal for small home networks or single use home computers. It matters however in larger organizations where you need to be able to identify servers. The name is a single word with no spaces, it has only letters, numbers or a hyphen with up to 253 characters.
The default name was set during installing the Ubuntu system. You can however change it at anytime as you want. And here’s the universal way to do the trick in either Ubuntu desktop or server editions.
Tutorial Objectives:
Change computer name until reboot:
To get started, first either connect to your Ubuntu server or open terminal by pressing Ctrl+Alt+T on keyboard or searching from the overview screen. When it opens, run command:
Replace ‘NEW_NAME’ in command with your desired computer name. And it will take place until reboot.
NOTE: the new name takes effect immediately but not visible until you start a new terminal window.
Change computer name permanently:
In most Linux distributions, you can edit the “/etc/hostname” configuration file to set new computer name.
1.) To do so, open terminal from start menu or connect to the command console of remote server, then run command:
When the file opens, delete the old name and type a new one. And press Ctrl+X, then type y, and hit Enter to save changes!
2.) It’s important to edit /etc/hosts file to map the new name to 127.0.1.1 and/or the permanent IP address if any.
NOTE: you have to set same name in both /etc/hosts and /etc/hostname to avoid networking issues. And save file by pressing Ctrl+X, type y, and hit Enter.
How to Change Hostname on Ubuntu 20.04
Home » SysAdmin » How to Change Hostname on Ubuntu 20.04
A hostname is a user-generated custom name which identifies a computer system in a network. In Ubuntu 20.04, users assign a hostname to the machine during OS setup.
You may decide to change your computer’s hostname for several reasons. For example, no two computers on a network can have the same hostname and, if you find yourself in this situation, you will have to change the hostname to avoid a network conflict.
In this tutorial, you will learn how to change a hostname on Ubuntu 20.04 using the Linux command line or GUI.
How to Check Current Hostname on Ubuntu 20.04
To check the current hostname of your Ubuntu system, use one of two available commands.
The Static hostname line displays your machine’s hostname.
Note: Valid hostnames are between 2 and 64 characters in length. They can contain only letters, numbers, periods, and hyphens, but must begin and end with letters and numbers only.
Temporarily Change Hostname on Ubuntu 20.04
Use the hostname command to make a temporary change to your computer’s hostname.
In the terminal, type the following, replacing new-hostname with the name you choose:
If successful, this step will not provide any output. To confirm the result of the process, check the current system hostname:
Change Hostname on Ubuntu 20.04 (No Reboot Required)
If you wish to permanently change the hostname without rebooting your computer, use the hostnamectl command.
Step 1: Use set-hostname to Change the Hostname
Type the following command:
Step 2: Use hostnamectl to Confirm the Change
Just like the hostname command, if successful, hostnamectl set-hostname does not produce any output. Therefore, use hostnamectl to check the result.
Step 3: Change the Pretty Hostname (Optional)
A “pretty” hostname is the hostname presented to the user, not to another computer on a network. A computer system identifies another computer only by its static hostname.
Note: The pretty hostname does not have the naming limitations of its static counterpart – any UTF-8 value is permitted.
To change a machine’s “pretty” hostname, use the same hostnamectl command with the —pretty option:
Replace new-hostname with your own UTF-8 value.
Note: The “pretty” hostname is stored in /etc/machine-info. Updating this file is another way to perform this optional step.
Change Hostname on Ubuntu 20.04 – Alternative Method (Reboot Required)
Another way to permanently change the hostname is by editing two configuration files:
The changes take effect immediately after system reboot.
Step 1: Open /etc/hostname and Change the Hostname
Edit the file with a text editor of your choice. In this example, we will be using the Vim editor:
The /etc/hostname file contains only the current hostname. Replace it with your new choice.
Step 2: Open /etc/hosts and Change the Hostname
Now edit the /etc/hosts file in the same way.
The file /etc/hosts maps hostnames to IP addresses. Look for the hostname you wish to change and simply replace it with your new choice.
Save the edits and exit.
Step 3: Reboot the System
Reboot your computer to apply the changes:
Change Hostname on Ubuntu 20.04 Using GUI
The Ubuntu GUI also provides a way to edit the system hostname:
1. First, navigate to Settings > About.
2. Now, locate the Device Name field.
3 Clicking the Device Name field opens the Rename Device dialogue box.
4. In the Rename Device dialogue box, replace the current hostname with a new one and confirm your choice by clicking the Rename button. This action permanently changes the hostname.
This article presented three methods in which you can change the hostname on your Ubuntu 20.04 machine, using the command line or GUI. All the methods are simple and straightforward, so you can choose whichever one fits your use case best.
How do I change the computer name?
When I connect to my server (ubuntu server 10.10), I get this:
How can I remove «.belkin»?
14 Answers 14
You need to edit the computer name in two files:
These will both need administrative access, so run
Replace any instances of the existing computer name with your new one. When complete run
The name will also be changed if you restart your computer.
hostnamectl set-hostname on 13.10+ desktop
This is the best way if you have systemd (13.10 onwards) and if cloud-init is not active (see below):
18.04 onwards: cloud-init
18.04 Introduced cloud-init which can control setting of the hostname so hostnamectl changes it won’t stick after a reboot if cloud-init is installed. TODO: how to check if it is installed, is it installed by default on the desktop image or just server?
If you want hostnamectl changes to stay after a reboot, then you’ll need to edit the cloud-init config files, disable cloud-init’s hostname set/update module:
or disable cloud-init entirely:
You should also make the same changes in /etc/hosts file
Run sudo service hostname start
As long as you have no application settings depending on the ‘old’ hostname, you should be ok 😉
It is safe to do, you just need to be sure you edit both the system hostname configuration file (/etc/hostname) and the hostname name resolution file (/etc/hosts). From a terminal execute the following:
In addition to editing /etc/hosts and /etc/hostname, various services might have issues with the change as well. Mysql and postfix are installed by default in ubuntu. A broken postfix won’t affect most ubuntu users, since it’s a background email server that isn’t used by much.
The default config for mysql doesn’t use hostname, so it will work fine as-is. If you have customized it, edit the files in /etc/mysql/ and restart the service.
You may also want to edit /etc/motd (message of the day), which is shown on virtual terminals and remote logins. That one won’t harm anything though.
Other services that you may have installed that would need fixing are apache, bind9, etc. In each case, find and edit the hostname in their config and restart the service.
How to Change Hostname in Ubuntu 16.04 (Change Computer Name)
In this tutorial we will see How to Change Hostname in Ubuntu 16.04. This method will work without the need of restarting your computer.
The host name is set by default at the time of installing Ubuntu operating system. But it can be easily changed.
There are two ways to change the Computer Name.
Temporarily change the hostname
We can change the hostname temporarily i.e. it will work till the computer is restarted. For this just open your terminal (short key Ctrl+Alt+T) and run the following command:
After running the above command, Just open the new terminal. In the new terminal you will see the new host-name.
Change the hostname using hostnamectl
Check the current hostname on Ubuntu using hostnamectl
the output for the above command
Change the current hostname on Ubuntu using hostnamectl
Now after changing the hostname, Just open the new terminal. Now, we can verify the hostname using the hostnamectl status again.