How To Configure The "/etc/hosts" File On Linux [ID 242490.1]
Applies to:
Linux OS - Version Enterprise Linux 4.0 and laterLinux x86
Linux x86-64
***Checked for relevance on 17-Jun-2010***
***Checked for relevance on 20-Feb-2013***
Purpose
This article will show you how to properly configure the "/etc/hosts" file on a Linux platform.
Scope
This is intended for Linux system administrators and Linux DBAs with system administration skills.
Details
What Is /etc/hosts And Why Is It Used?
In order to send network traffic to a host, the numeric Internet Protocol (IP) address for that host must be known. The IP address is traditionally written as xxx.xxx.xxx.xxxwhere each xxx represents a value from 0 to 255, for an IPv4 network address. Computers require these addresses but humans find remembering numeric values difficult. The Domain Name Service (DNS) provides a mechanism to associate one or more alphanumeric names with a numeric IP address. On a Linux system, these readable names are converted to their numeric IP equivalents by the Resolver Library, contained in the libresolve.so files provided as part of the glibc RPM package. Programs that need to lookup the numeric IP address for a name issue calls to this library.
Host names and their IP addresses may be found in a variety of places: local files, remote DNS servers, or NIS+ servers, to name a few. The order these resources are searched depends on the hosts: entry in the /etc/nsswitch.conf file. This line typically looks like this:
This causes the resolver library to consult the local /etc/hosts file first; if the host name is not found there, then consult the remote DNS name servers identified by the/etc/resolv.conf file.
Linux does provide the bind RPM package to allow an administrative domain to configure and maintain its own DNS service, but frequently the size of the local network is only a few hosts and makes justifying the effort of maintaining a DNS service unwarranted.
Format Of The /etc/hosts File
The /etc/hosts file is an ordinary text file. Two types of lines are permitted:
- Empty Lines
- Host name definitions
Lines may be intermingled as needed.
Comments begin with a hash symbol (#) and continue to the end of the line.
Associating Host Names And IP Addresses
For each host a single line should be present with the following information:
Fields of the entry are separated by any whitespace (spaces or tabs).
The first field is the numeric IP address to be used for all the host names on this entry. Either an IPv4 address , an IPv6 address (2001:0db8:0000:0000:0000:0000:1428:57ab), or an IPv6 abbreviation (::1) may be used, depending on your requirements.
After the IP address, remaining tokens specify the locally-known hostnames associated with that IP address. By convention, the first name after the IP address is the canonical or fully-qualified domain name. An example of a canonical name would be this is the official name of the host.
Any remaining names defined for the IP address are aliases or alternate names for the official host name. For example, suppose that one of the duties assigned to is to be the corporate FTP site. A suitable alias might then be my and this name could be added to the /etc/hosts entry after the canonical name. Many times, an alias is simply the host name, without any domain suffix.
The advantage to listing the canonical host name as the first definition on the line is that IP-to-hostname conversion (similar to reverse DNS lookups) usually display only the first name found; convention uses the canonical name for this. In our example, the command:
PING myhost.oracle.com (192.168.2.244) 56(84) bytes of data.
64 bytes from myhost.oracle.com (192.168.2.244): icmp_seq=1 ttl=64 time=0.023 ms
64 bytes from myhost.oracle.com (192.168.2.244): icmp_seq=2 ttl=64 time=0.028 ms
64 bytes from myhost.oracle.com (192.168.2.244): icmp_seq=3 ttl=64 time=0.028 ms
Note that we pinged myftp but results come from host myhost: this is a reliable hint that you are addressing an alias, not the actual host.
Official Reference
The format of the host table is described in the Internet Request-For-Comments (RFC) 952. These RFCs are available many places around the Internet, such as the web site.
Example
The example below shows a typical /etc/hosts file for an Oracle Real Application Cluster (RAC).
9.25.120.143 rac1 # Oracle 9i Rac node 1 - public network
9.25.120.144 rac2 # Oracle 9i Rac node 2 - public network
10.1.1.1 int-rac1 # Oracle 9i Rac node 1 - interconnect
10.1.1.2 int-rac2 # Oracle 9I Rac node 2 - interconnect
The cluster has two nodes, rac1 and rac2, that are accessible from the external network.
The cluster nodes are connected by a private interconnect that uses an internal IP network. The int-rac1 and int-rac2 names refer to these network connections.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15747463/viewspace-759070/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【Linux】/etc/hosts.deny與/etc/hosts.allowLinux
- oracle grid control etc/hostsOracle
- How To Configure Server Side Transparent Application FailoverServerIDEAPPAI
- How to Configure a New Plant in SAP?
- How to Configure the DNS Server for 11gR2 SCAN On LinuxDNSServerLinux
- /etc/hosts,GoldenGateGo
- 【Autofs】How to Configure Autofs on CentOS 7?CentOS
- How to Configure A Second Listener on a Separate Network in 11.2 Grid
- How to configure password openldap server in Red Hat Enterprise Linux 5?LDAServerLinux
- How to use ASMCA in silent mode to configure ASMASM
- How to configure a firewall for domains and trustsAIRust
- How to Configure TAF and Client Load Balancing in a Replicated Environment [ID 210596.1]client
- How to build a jar file by mavenUIJARMaven
- mac 修改 /etc/hosts 檔案Mac
- /etc/hosts檔案簡介
- How to Install and Configure VNC Server in CentOS 7VNCServerCentOS
- Metlink:How to Configure DM-Multipathing
- How to Install and Configure VNC on Ubuntu 18.04VNCUbuntu
- How to Convert Class File to Java File Online?Java
- How to configure Client Failover after Data Guard Switchover or Failover [ID 316740.1]clientAI
- Linux 修改本機 /etc/hosts 的 hostName 後經常不生效Linux
- How to use Qt Designed Ui fileQTUI
- How to dynamically evaluate a tag within a java fileJava
- HOW TO PRINT FILE TO NOTEPAD IN GUI?GUI
- How To Configure Notification Rules in Enterprise Manager Grid Control_429422.1
- How to restore raid after reinstall LinuxRESTAILinux
- Oracle ASM How many allocation units per fileOracleASM
- How to configure a Vagrant (Homestead) VM in Phpstorm with Xdebug on MacPHPORMMac
- 轉發:How To Configure Logging and Log Rotation in NginxNginx
- 轉:Linux hostname主機名配置檔案與檔案 /etc/hosts解說Linux
- How to read Oracle 10046 trace fileOracle
- configure ssh service in linux :Linux
- configure vnc server in linuxVNCServerLinux
- How to copy a datafile from ASM to a file system not using RMANASM
- How to get the exact duration of an audio file in js All In OneJS
- Docker非root使用者修改/etc/hosts檔案Docker
- File getPath()、getAbsolutePath()、getCanonical
- linux下檢視hosts檔案Linux