Hostname in Linux

Source: Internet
Author: User

hostname command to view the hostname of this machine,
#hostname
Hostname command to set the hostname of the system
#hostname newname
NewName is the new hostname to be set, which takes effect immediately after the run (restarting the shell), but changes are lost after the system restarts, and if you want to permanently change the system's hostname, modify the associated configuration file.

Redhat hostname, modify/etc/sysconfig/network file, will be inside the hostname this line to modify into Hostname=newname, where NEWNAME is the hostname you want to set.
The hostname configuration file for the Debian distribution is/etc/hostname.
After the configuration file is repaired, a new hostname is read from the configuration file when the system is restarted.

The relationship between hostname and/etc/hosts
A lot of people mention change hostname first think of modifying/etc/hosts file, think hostname configuration file is/etc/hosts. Actually, it's not.
The Hosts file works quite like DNS, providing the IP address to hostname correspondence. The early Internet computers were few, and the stand-alone hosts file was sufficient to store all networked computers. But with the development of the Internet, this is far from enough. A distributed DNS system is then present. The DNS server provides a similar IP address to the corresponding domain name. Specific can man hosts.
The Linux system queries the/etc/hosts file before issuing a domain name resolution request to the DNS server, and if it has a corresponding record, it will use the records inside the hosts.

After modifying hostname, if you want to use Newhostname to access it on this computer, you must add a newhostname record in the/etc/hosts file.
Like what:
#hostname Server1.localdomain

# cat/etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.2.5 Server1.localdomain
This way, I can access the machine via Server1 or Server1.localdomain.

Also note that 192.168.2.5 must be accessible, otherwise it will take a long time to start at starting Sendmai this step

Hostname in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.