Difference between revisions of "The /etc/hosts file"

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
(Created page with " == Debian == In the Debian Linux Distribution, or distributions such as Ubuntu that are Debian based, the hosts file looks something like this: 127.0.0.1 localhost 127.0...")
 
Line 1: Line 1:
 +
As your machine gets started, it will need to know the mapping of some hostnames to IP addresses before DNS can be referenced. This mapping is kept in the /etc/hosts file. In the absence of a name server, any network program on your system consults this file to determine the IP address that corresponds to a host name.
  
 +
Format:
 +
<IP> <HOSTNAME>.<DOMAIN> <ALIAS>
 +
 +
Example:
 +
127.0.0.1 localhost.localdomain localhost
 +
 +
The hosts file contains lines of text consisting of an IP address in the first text field followed by one or more host names.
 +
* Each field is separated by white space (blanks or tabulation characters).
 +
* Comment lines may be included; they are indicated by a hash character (#) in the first position of such lines.
 +
* Entirely blank lines in the file are ignored.
 +
 +
Modifying the hosts file will override the DNS for a domain, on that particular machine.
  
 
== Debian ==
 
== Debian ==

Revision as of 16:05, 27 June 2014

As your machine gets started, it will need to know the mapping of some hostnames to IP addresses before DNS can be referenced. This mapping is kept in the /etc/hosts file. In the absence of a name server, any network program on your system consults this file to determine the IP address that corresponds to a host name.

Format:

<IP> <HOSTNAME>.<DOMAIN> <ALIAS>

Example:

127.0.0.1 localhost.localdomain localhost

The hosts file contains lines of text consisting of an IP address in the first text field followed by one or more host names.

  • Each field is separated by white space (blanks or tabulation characters).
  • Comment lines may be included; they are indicated by a hash character (#) in the first position of such lines.
  • Entirely blank lines in the file are ignored.

Modifying the hosts file will override the DNS for a domain, on that particular machine.

Debian

In the Debian Linux Distribution, or distributions such as Ubuntu that are Debian based, the hosts file looks something like this:

127.0.0.1 localhost
127.0.1.1 <host_name>

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

The IP address 127.0.1.1 in the second line is unique to Debian. The Debian Installer creates this entry for a system without a permanent IP address as a workaround for buggy software such as the Gnome desktop.

For a system with a permanent IP address, that permanent IP address should be used here instead of 127.0.1.1.

For a system with a permanent IP address and a fully qualified domain name (FQDN) provided by the Domain Name System (DNS), that canonical <host_name>.<domain_name> should be used instead of just <host_name>.