You can find and set the name of your computer to make it easier for people to discover on a network using the
You will get a result saying your computer name and in my case it says
The first part of the result is the name of the computer and the second part is the name of the domain.
You can run the command above to return just the computer name.
The result will be simply
baransel this time.
Similarly, just use the command above to find out which domain you are on.
You can find the IP address for the
hostname using the command above.
A hostname can be given a name, and you can find all the aliases of the computer you are using by typing the command above.
If there are no aliases, your real hostname will be returned.
How to Change
You can change the
hostname of the computer by typing the following command:
Now when you run the
hostname command it will only show
This change is temporary and not particularly helpful.
To permanently change your hostname, use the
nano editor to open
sudo nano /etc/hosts
You will need elevated privileges to edit the hosts file, and you can use the
sudo command as shown above or switch users to root using the
/etc/hosts file has details about your computer and other machines on your network or other networks.
By default, your
/etc/hosts file will contain something like:
127.0.0.1 localhost.localdomain localhost
The first item is the IP address to resolve for the computer. The second item is the computer’s name and domain, and each subsequent field provides an alias for the computer.
To change the hostname, you can simply replace
localhost.localdomain with the computer name and domain name.
127.0.0.1 baranseldev.mydomain localhost
After saving the file, run the
hostname command, and you will get the following result:
hostname -dis shown as
hostname -sis shown as