User Feedback – /etc/hosts explained : Ubuntu (5.10 / 6.06.1 / 6.10)

By | 2006/12/05

One of you contacted me recently with a few questions regarding my previous post, Network File System (NFS) : Ubuntu (6.06.1 / 6.10). I wanted to post some follow up information on that to help clarify a few of the steps. Some of this may be very simple for many of you, for others it will hopefully open your eyes to a few more powerful aspects of an Ubuntu Linux system. Here goes.

Question: How did you modify the /etc/hosts file to use the ‘media’ shortcut?

Editing the /etc/hosts file is really simple and you can do quite a bit with it. Ever wish you could simple visit “mysite” in your browser and it’d know where you wanted to go? Ever wish you could give nicknames to your local network machines instead of trying to remember the IP address? Here is the place to do it.

To edit the file you would want to use a quick command within a terminal:

sudo gedit /etc/hosts

Simply add a line to your /etc/hosts file to create a network shortcut using the following syntax: ip.address shortcut. Example (on my network):

127.0.0.1 localhost
127.0.1.1 notebook.local notebook

192.168.0.3 media
192.168.0.8 silverbox
192.168.0.2 blackbox

# 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 three lines in italics are my additions. You can use the same syntax to update your /etc/hosts file and go wherever you want! The above is an example of using a shortcut for the local network but the same goes for the outside world. Try something like:

google.com 42
ubuntu-tutorials.com bestsiteever

…and the next time you type “42” in your browser it’ll come right up with google (yes, the answer to life, the universe and everything!), or put in “bestsiteever” and come right back here for some more great tutorials!

One thought on “User Feedback – /etc/hosts explained : Ubuntu (5.10 / 6.06.1 / 6.10)

  1. Maarten

    Thanks.

    One question though…
    after a reboot, my /etc/hosts file is back to default, without my additions.
    Any ideas how to make additions to /etc/hosts permanent ?

    Thank you in advance,
    Maarten.

Comments are closed.