Custom Search

Ubuntu hosts file

The Ubuntu hosts file is a static table lookup for host names. As the name suggests, it contains host names and ip addresses. By default, Ubuntu creates hosts file in /etc directory with localhost name and loop back ip address in its content.

Below is an example of a hosts file with modified content. A default hosts file only contains the first line ip address which resolves the localhost.       localhost       ubuntu
# 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

If you setup your Ubuntu system as a local network server, then you need to store other server or hosts in /etc/hosts file. Here is a format of hosts file from host manual page:

This manual page describes the format of the /etc/hosts file.  This file is a
simple text file that associates IP addresses with hostnames, one line per IP
address. For each host a single line should be present with the following information:
IP_address canonical_hostname [aliases...]

Fields of the entry are separated by any number of blanks and/or tab characters.
Text  from a "#" character until the end of the line is a comment, and is ignored.
Host names may contain only alphanumeric characters, minus signs ("-"), and
periods  (".").  They must begin with an alphabetic character and end with an
alphanumeric character. Optional aliases provide for name changes, alternate
spellings, shorter hostnames, or generic hostnames (for example, localhost).


  1. Thanks it is a working.
    Ganesh kulpe

  2. thanks I just didn't know its location now I got it, new user :)

  3. If you want to see what a hosts file is and how can you use it on a Linux Mint/Ubuntu operating system you can checkout Ubuntu Linux hosts file (video tutorial).


Please keep comment relevant and strictly no spam will be tolerated. Thank you.