Hostname of CentOS

Source: Internet
Author: User
This article takes CentOS6.3 as an example: In Linux, there are several hostnames: 1. the HOSTNAME environment variable is in the system. The Command echo $ HOSTNAME will display the hostname (host name) 2. there is also a hostname command: it has several functions: a) query the host name: This article takes CentOS6.3 as an example: In Linux, there are several hostname-related: 1. the HOSTNAME environment variable is in the system. The Command echo $ HOSTNAME will display the hostname (host name) 2. there is also a hostname command: it has several features: A) query the host name: I. hostname // if no host name is set, the default host name short format is displayed, such as localhost; ii. hostname-f // the long format of the host name, with a domain name, such as localhost. localdomainiii. hostname-d // display the domain name, such as localdomain iv. hostname-I // display the IP address ivi corresponding to the host name. hostname-a // display the host alias (alias). the output result is the same as that of hostname, such as localhostv. hostname-s // display the short format of the host name, that is, the first part on the left, such as localhost. localdomain is preceded by localhost. B) set the host name.: The host name set with the command is temporary. after the system restarts, the host name is lost. I. hostname newname // Set the host name to newname3. permanent modification of the hostname modified by the hostname command is temporary. to change the hostname permanently, you must modify the corresponding configuration file. # Man hostname // in this sentence, "The host name is usually set once at system startup in/etc/rc. d/rc. inet1 or/etc/init. d/boot (normally by reading the contents of a file which contains the host name, e.g. /etc/hostname ). ". in CentOS, the hostname file is not mentioned in this example, but is composed of/etc/rc. d/rc. the sysinit script is responsible for setting the system's hostname. it reads the/etc/sysconfig/network text file, and the RedHat hostname is set in this file. Temporarily put down the/etc/sysconfig/network configuration method, first understand the difference between hostname without parameters and hostname-a-d-f,-I: hostname is to call gethostname (2) while the hostname-a-d-f and-I commands call the gethostbyname (3) function. The difference between gethostname (2) and gethostbyname (3) is gethostbyname (3) so the gethostbyname (3) function needs to ask/etc/nsswitch. conf and/etc/host. the conf file determines whether to read information from the/etc/sysconfig/network configuration file or from the/etc/hosts configuration file. Therefore, the hostname configuration has two configuration files:/etc/sysconfig/network and/etc/hosts. function introduction: no/etc/hosts function is just to provide a host name, the hostname in it is/etc/rc. d/rc. sysinit read configuration method: use vim to open the network file and change HOSTNAME = NEWNAME; in this way, the hostname is changed to newname/etc/hosts: it is related to the network, which is equivalent to DNS, provides the corresponding configuration method for IP address to hostname: use vim to open the hosts file. the configuration format is ip fqdn alias, such as 127.0.0.1 localhost. localdomain localhost // do not delete or modify it. keep this configuration 192.168.1.20.test. localdomain test // manually add the real IP address and host name of the local machine. IP address = 192.16 8.1.20., FQDN = test. localdomain, alias = test note: make sure that the hostname in the configuration file network is consistent with the alias in the hosts and the first part of the FQDN, otherwise, the hostname-a-f-d-I command cannot work normally. The fault is as follows:

# Ping localhost
Hostname: Unknown host

In addition, the samba service uses the netbios name by default, instead of the host name. However, if you do not specify the netbios name in samba, the netbios name will use your host name.

Related Article

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.