The role of the hosts file is quite like DNS, which provides the correspondence between IP addresses and hostnames. The Linux system will query the /etc/hosts file before sending a domain name resolution request to the DNS server. If there are corresponding records in it, the records in hosts will be used.
Its format is as follows:
127.0.0.1 localhost.localdomain localhost
The format of the hosts file is one record per line, which are IP address hostname aliases. The three are separated by blank characters, and aliases are optional.
When the modification is completed, you can use uname -a to see what the hostname is.
After modifying /etc/hosts, you need to restart the service or restart the server, generally restart the service, the command is as follows:
Ubuntu: $sudo /etc/init.d/networking restart Gentoo: /etc/init.d/net.eth0 restart