+3 votes
229 views
How to use Hostname command on Linux

in Linux / Unix by (551k points)
reopened | 229 views

1 Answer

+4 votes
Best answer

When managing Linux operating systems, for audit or control reasons, it is necessary to know in detail the exact name of a computer in order to have a centralized administration on them. To better manage this aspect in a network, we can use the hostname command..

The hostname command is implemented and has been developed to display or set the hostname and domain name of a particular computer and is one of the commands. In this regard we must remember that a host name is a name assigned to a local computer that allows it to be uniquely identified on any network and with it can be fully managed without using its full IP address .

The basic syntax to use this hostname command is:

 hostname [options] [new_name] 
When we use the hostname command without any option or argument, the result will be the current hostname and domain names of the local machine. The default hostname and domain in Linux is localhost.localdomain. When we add a name as an argument, it will become the new host or computer name selected.

All changes to the host name can only be made by the root account due to its administrative privileges or, failing that, put the su command and the respective password first..

We will see some examples of how to use this command on Linux.

By using the hostname command without adding any parameters, we can see the name of the host and the domain to which it is associated if it exists:

Step 1

We run the hostname line:

image

 hostname -i - hostname -I 
Step 2

When the hostname is resolved, that is, it has a defined name, it is possible to display the IP addresses of the hostname with the -i parameter and the -I option defines all configured network interfaces and results in all addresses Network of the selected host:

image

 hostname -d - hostname -f - hostname -A 
Step 3

These options give us more administrative results, in this case associated with the DNS, for example, to see the name of the DNS domain and FQDN (Fully Qualified Domain Name) of the selected equipment, we can use the -fy -d parameters , simultaneously, and using the -A parameter it will be possible to see all the FQDNs of the mentioned machine:

image

 hostname -a 
Step 4

This command gives us the possibility to display the alias name, that is, replacement names, if they exist on the selected device.

image

 sudo hostname New_Name 
Step 5

If it is necessary to edit the name of the current machine, just run this syntax, hostname plus the new name of the device and thus set the desired name for it:

image

There are other options such as:

hostname -F
The -F parameter changes the host and domain names in a plain text file whose name is generated after this option as an argument. Comments, that is, lines that begin with a pound sign, in the file are ignored.

hostname -s
This parameter displays the short name of the selected device.

hostname -v
This parameter offers more information about the equipment.

hostname -V
With this parameter we will see the version of the selected device

hostname -h
Display hostname help.

image

We can see how the use of this command is simple but fully functional and practical for all administration tasks at the team name level..


by (3.5m points)
edited

Related questions

+5 votes
1 answer
asked Apr 30, 2020 in Linux / Unix by backtothefuture (551k points) | 294 views
+4 votes
1 answer
+3 votes
1 answer
asked Oct 5, 2019 in Linux / Unix by backtothefuture (551k points) | 806 views
+3 votes
1 answer
asked Oct 20, 2020 in Linux / Unix by backtothefuture (551k points) | 221 views
+4 votes
1 answer
asked Sep 22, 2020 in Linux / Unix by backtothefuture (551k points) | 312 views
Sponsored articles cost $40 per post. You can contact us via Feedback
10,634 questions
10,766 answers
510 comments
3 users