Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm very new to Ubuntu and I want to know: what is the exact use of /etc/hosts?

Lets say I'm adding this into it :

127.0.x.x mydomain

What does that mean?

share|improve this question
up vote 12 down vote accepted


The hosts file is one of several system facilities that assists in addressing network nodes in a computer network. It is a common part of an operating system's Internet Protocol (IP) implementation, and serves the function of translating human-friendly hostnames into numeric protocol addresses, called IP addresses, that identify and locate a host in an IP network. In some operating systems, the hosts file's content is used preferentially to other methods, such as the Domain Name System (DNS), but many systems implement name service switches (e.g., nsswitch.conf for Linux and Unix) to provide customization. Unlike the DNS, the hosts file is under the direct control of the local computer's administrator

File content

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. For example, a typical hosts file may contain the following:

# This is an example of the hosts file  localhost loopback
::1        localhost

This example only contains entries for the loopback addresses of the system and their host names, a typical default content of the hosts file. The example illustrates that an IP address may have multiple host names, and that a host name may be mapped to several IP addresses.


This is invalid (?):

127.0.x.x mydomain

Wildcards are * so it should be 127.0.*.* but I hardly see anything else than ;)

What this means is that you can use mydomain as a name for that IP adres. It is easier to use than to remember the IP adres ( that Google uses for their searchengine. The same works locally (localhost) on your machine. If you run your own Apache instance you can set a local IP adres to a name and use that name in a browser.

The ::1 in the example is the IP v6 version for IP adresses.

share|improve this answer
Can you say me what is the use of ::1 localhost? – batman Sep 2 '12 at 10:36
@batman Same thing for IPv6 – Ward Muylaert Sep 2 '12 at 11:17
@batman good q. added it :) – Rinzwind Sep 2 '12 at 14:04

It means that the system will not do a DNS lookup for mydomain, it will be automatically redirected to the IP address you specified in your hosts file.

On most systems the default entry in the hosts file is:    localhost is always the address of the computer you're on. For example, if you run a web server on your pc, you can access it from the web browser via the http://localhost:port instead of typing the whole IP address

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.