6

I have googled and searched Ask Ubuntu on this, but got no relevant answers. I have no hosts file in /etc, I cannot find a hosts file in search, I am talking about the system hosts file not lampp/etc. I mention that because there is no hosts file there either - maybe that is a clue.

I want to know how to create a hosts file in Ubuntu or obtain a sample file I could copy and paste or I am happy to use the terminal if someone can help with best way to create the file and edit it.

I am not even sure what extension it should have - basically I just want the default hosts file that I understand Ubuntu should come with in my /etc folder.

muru
  • 207,228
kerry
  • 311

1 Answers1

8

Lines in the /etc/hosts file have the following format:

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

You can create and/or edit the file with your preferred editor:

sudo nano /etc/hosts     # with nano in a terminal
gksudo gedit /etc/hosts  # with gedit
kdesudo kate /etc/hosts  # with kate

Here are some useful lines for the file – lines beginning with # are comments and get ignored, empty lines are allowed:

# The following line is desirable for IPv4 capable hosts
127.0.0.1       localhost

# The following lines are desirable for IPv6 capable hosts
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

You can read more about the format and get examples on the manpage (How can I get help on terminal commands?):

man hosts

There's also a Howto on ubuntuforums.org.

Further reading:

pa4080
  • 30,621
dessert
  • 40,956