11.2. Local Hosts File

11.2. Local Hosts File

As already mentioned, initially, the /etc/hosts file was used to resolve host names to IP addresses. This text file contains entries of the following format:

 127.0.0.1  localhost.localdomain localhost 192.168.77.1 FlenovM 

Each entry in the file maps a host name to its corresponding IP address. By default, there are only two entries in the file. The first entry is the loopback mapping. For all computers, the localhost name and the 127.0.0.1 IP address specify the local machine. Thus, the local computer can be pinged as follows :

 ping 127.0.0.1 

The second entry maps the computer name to the explicitly specified IP address of the machine's network adapter. In this case, the network card's IP address is set to 192.168.77.1; it is mapped to the FlenovM computer name. This means that either the computer name or its IP address can be specified as the parameter for the ping command. The following two commands are identical:

 ping 192.168.77.1 ping FlenovM 

When the second command is executed, a request will be made to the /etc/hosts file to obtain the corresponding IP address. Then the echo request will be directed to that address.

But which, the /etc/hosts file or DNS, is referenced first to resolve an address? This depends on the configuration of the operating system. There is the following line in the /etc/host.conf file:

 order hosts, bind 

The order directive specifies the order, in which the address resolution systems are referenced. At this setting, first the /etc/hosts file will be consulted, and only if the necessary information is not found in it will the bind command be executed to send a request to the DNS server. This speeds up access to main servers. Suppose that you visit the www.redhat.com site every day. When a request is sent to the DNS server, it takes a couple of seconds to resolve the host name to its IP address and to start loading the page.

To speed up the loading, the following entry can be made in the /etc/hosts file:

 209.132.177.50 www.redhat.com 
Note 

The 209.132.177.50 address corresponded to the www.redhat.com site when this book was being written. However, the address can change.

If, for some reason, the site will no longer load, delete the corresponding entry from the /etc/hosts file. Then execute the ping redhat.com command to check the communication with the server and to find out its IP address. This will display the IP address, with which the ping messages are exchanged. IP addresses of most sites change rarely, so once a mapping entry is added to the /etc/hosts file, you can save lots of time and nerves, especially when there are problems with the DNS server.



Hacker Linux Uncovered
Hacker Linux Uncovered
ISBN: 1931769508
EAN: 2147483647
Year: 2004
Pages: 141

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net