Using etchosts

Using the /etc/hosts file to resolve host names to IP addresses, and the other way around, is one of the oldest ways to do it. It is rather primitive, because the file has to be maintained on every host where you need it and because no synchronization is established between hosts. However, it is a fast way to make information available locally that needs to be available locally. In fact, using the /etc/hosts file makes name resolving faster and reduces Internet traffic; in addition, you can use it to add some host names that need to be available locally only. Listing 13-3 shows the contents of this file as it is created after a default installation of SUSE Linux Enterprise Server.

Listing 13-3. Example of/etc/hosts

# hosts

# Syntax

# IP-Address Full-Qualified-Hostname Short-Hostname

This file describes a number of hostname-to-address mappings for the TCP/IP subsystem. It is mostly used at boot time, when no name servers are running. On small systems, this file can be used instead of a "named" name server.

127.0.0.1 localhost

# special IPv6 addresses

::1 localhost ipv6-localhost ipv6-loopback fe00::0 ipv6-localnet ff00::0 ipv6-mcastprefix ff02::1 ipv6-allnodes ff02::2 ipv6-allrouters ff02::3 ipv6-allhosts

127.0.0.2 laksmi.sandervanvugt.com laksmi

192.168.1.125 laksmi.sandervanvugt.com laksmi

As you can see, the contents of the /etc/hosts file are rather simple. First you see the IP address of the host, which can be an IPv4 as well as an IPv6 IP address. Next, you see the fully qualified host name. This is the name of the host, followed by its DNS suffix. Last, you see the short host name. It will, however, also work if you use just the IP address followed by the name of the host you want to add. For example, the following will also work:

192.168.1.130 damayanti

In most cases, it is not necessary to specify anything in /etc/hosts; if, however, you want to make sure certain information can be resolved faster or can be resolved when the records are not available in DNS, it is a good idea to use this file.

Was this article helpful?

0 0

Post a comment