As the number of computers connected to the network grows, each computer needs to have a property that distinguishes it from other computers. Like people in the real world, computers also have a property called hostname (host name).What is hostname
From its operating manual, hostname is used to display the DNS name of the system and to display and set its hostname or NIS domain name. So hostname relies on DNS (domain Name System) or NIS (Network Information System).How to show hostname
Hostname is a pre-installed command for every Linux distribution. By entering hostname in the console, you can display the hostname of your machine. Here's one with a simple command and its output.
The above command will tell you that the name of the computer is Ubuntu .How to set hostname
Hostname is set when you install Linux for the first time. One of the steps Linux will let you enter the host name information. However, if you wish, you can set it later.
To set up your hostname, you can use the following command:
# hostname dev-machine$ Hostnamedev-machine
You need to set/modify the hostname of your computer by using root or equivalent root privileges. The "#" identity proves that you are the root user. The above command sets the hostname of your computer as dev-machine. If you do not receive any error messages, then your hostname has changed. Once again, check with the hostname command to see the results.
Using the hostname command to set your hostname is not permanent . When you restart your computer, your settings will expire. in order to change permanently , you must manually modify the hostname configuration file.
Linux in the Debian/ubuntu system
You can find this file in the /etc/hostname and /etc/hosts folders.
Here are the contents of each file
# vi/etc/hosts127.0.0.1 localhost127.0.0.1 Dev-machine
You will find that you do not have to restart your Linux and it will take effect immediately.
Linux in the Redhat/centos system
You can find this file in the /etc/hosts and /etc/sysconfig/networks folders.
Here are the contents of each file
127.0.0.1 localhost.localdomain localhost dev-machine::localhost 127.0.0.1
How to display DNS domain namesNetworking=yesnetworking_ipv6=nohostname=dev-machine
From the above definition of hostname, hostname can also display your Linux DNS name. If your hostname command displays your hostname, then the DnsDomainName command will display your domain name as well. Take a look at this simple example.
In this post, the result of the DnsDomainName command is bris.co.id.
If you see the result is (none), then your machine is not configured with the FQDN (Fully qualified domain name fully complies with the standard domains) . The DnsDomainName command extracts information from the /etc/hosts file. You should configure it for the FQDN format. The following is a simple example:
127.0.0.1 localhost.localdomain localhost dev-machine::localhost 127.0.0.119188.8.131.52 dev-machine.bris.co.id Dev-machine
To show more detail, you can use the parameter- v
How to display more details about the hostname$ dnsdomainname-vgethostname () = ' dev-machine.bris.co.id ' resolving ' dev-machine.bris.co.id ' ... Result:h_name= ' dev-machine.bris.co.id ' result:h_aliases= ' dev-machine ' result:h_addr_list= ' 192.168.0.104 '
The hostname command can use multiple parameters and aliases, such as the DnsDomainName command, which is an alias. These parameters are useful in the daily operation. The results of the following commands are based on the above configuration of /etc/hosts .
Show IP Address
Show Domain name
Show short hostname $ hostname-s dev-machine
This command will produce the same results as the input hostname.
Display FQDN format
Display detail Information
All parameters, including the above information, can be summarized by using the parameter- v and- D . Let's take a look at an example.
$ hostname-v-dgethostname () = ' dev-machine.bris.co.id ' resolving ' dev-machine.bris.co.id ' ... Result:h_name= ' dev-machine.bris.co.id ' result:h_aliases= ' dev-machine ' result:h_addr_list= ' 192.168.0.104 ' Bris.co.id
Do you feel familiar? Yes, the result of the operation is the same as the above-mentioned dnsdomainname-v command.