Defining the Linux hostname in/etc/hosts

Source: Internet
Author: User

The problem today is that a program is always 0x7f000001 when it gets an IP address on a newly installed Linux server. At first no attention, then carefully think, 0x7f000001 not just is well. A colleague looked up the/etc/hosts and found a line in the file: mylinuxsvr localhost.localhost.localdomain localhost

Among them, Mylinuxsvr is the name of this server. No wonder you can only get every time. Of course, this server's IP address is actually good, but somehow, there is a different server communication between the program to get the IP address through/etc/hosts ...

Found some articles on Linux server network configuration, recorded here: Quick HOWTO:Ch03:Linux networking adding Red Hat Enterprise Linux Hosts

The following abstracts are from Quick HOWTO:Ch03:Linux networking.

Configuring Your/etc/hosts File

The/etc/hosts file is just a list of IP addresses and their corresponding server names. Your server would typically check this file before referencing DNS. If the name is found with a corresponding IP address then DNS won ' t being queried at all. Unfortunately, if the IP address is for this host changes, you are also have to also update the file. This May is a concern for a single server and but can become laborious if it has to being done companywide. For ease of management, it's often easiest to limit entries in this file to just the loopback interface and also the Serv Er ' s own hostname, and use a centralized DNS server to handle most of the rest. Sometimes you might is the one managing the DNS server, and in such cases it may is easier to add a quick/etc/hosts f Ile entry till the centralized change can be made.  Smallfry

In the example above server Smallfry has a IP address of You can access using the ping, Telnet or no other network aware is referring to it as Smallfry. This is a example using the ping command to-whether Smallfry is alive and the network:

[Root@bigboy tmp]# ping smallfry
Ping Zero ( bytes of data.
Bytes from Smallfry ( icmp_seq=0 ttl=64 time=0.197 ms-bytes from
smallfry ( icmp_s  Eq=1 ttl=64 time=0.047 ms

---smallfry ping statistics---
2 packets transmitted, 2 received, 0% packet loss, time 2017ms
RTT Min/avg/max/mdev = 0.034/0.092/0.197/0.074 ms, pipe 2
[Root@bigboy tmp]#

You can also add aliases to the "end of the" which enable you to refer to the server using other names. Here we are have set it up so this smallfry can also be accessed using the names Tiny and Littleguy.  smallfry  Tiny  Littleguy

You should never have a IP address more than once in this file because Linux would use only the values in the It finds.  Smallfry    # (wrong)  Tiny        # (wrong)  Littleguy   # (wrong)

The loopback Interface ' s localhost Entry

Usually the entry in/etc/hosts defines the IP address of the server ' s virtual Loopback interface. This is usually mapped to the name Localhost.localdomain (the universal name used when a server refers to itself) and Loca Lhost (the shortened alias name). By default, Fedora inserts the hostname of the server between the and the localhost as this:     bigboy    localhost.localdomain    localhost

When the ' server is ' connected to the ' Internet this ' entry ' needs to be the fully qualified domain n Ame (FQDN) of the server. For example,, like this:    localhost.localdomain    localhost

Some programs such as Sendmail are very sensitive to-this and if they detect what they feel are an incorrect FQDN they would Default to using the ' name Localhost.localdomain when communicating with another server ' on the network. This can cause confusion, as the other server also feels it is localhost.localdomain.

Note:you must always have a localhost and localhost.localdomain entry mapping to for Linux to work properly and Securely.

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: 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.