About Linux host hostname settings! (Gethostname gets localhost)

Source: Internet
Author: User

Today, hostname settings are not very concerned, but once a Linux host encounters a hostname setting problem, it may also cause some incredible network problems and service process problems.
Hostname check,
Uname-n
Hostname-A |-S |-d |-F
Hostname commands can be used to determine the host and hostname settings;

The gethostname () function gets localhost because hostname is not set.

Settings of/etc/hosts;
For DHCP hosts, the settings are as follows,

127.0.0.1myhost.mydomain.comlocalhost.localdomain localhost myhost

For hosts with fixed IP addresses,
127.0.0.1localhost.localdomain localhost
192.168.0.10myhost.mydomain.commyhost
Run/etc/init. d/network restart after setting. Otherwise, it will not work.

Use the hostname command to set the hostname,
Hostname myhost.mydomain.com
While/etc/hostname can exist and can be absent,
Check/etc/sysconfig/network. For hosts with fixed IP addresses,
Hostname = "myhost.mydomain.com"
Networking = Yes
For DHCP hosts, we recommend that you add settings to the interface settings of/etc/sysconfig/networking-scripts/. Generally, dhcp_hostname is used;
The most direct hostname is recorded in/proc/kernel/hostname.
Echo "myhost.mydomain.com">/proc/kernel/hostname
.
Let's talk about it first!

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.