How to Edit the Local Hosts File on Ubuntu 18.04 | 16.04

pc 1776995 640

This brief tutorial shows students and new users how to edit or modify Ubuntu local hosts file.

When you think of a hosts file, think of it as plain-text file used by the operating systems to map IP addresses to hostname on the local computer. The hosts file has priority over DNS.

When you type a domain name in your browser to go to a website, your computer translates the domain name your typed into an IP address and connect to the server that hosts the website.

While translating the name to IP, the local hosts file is the first file your operating look at. If the IP to domain mapping isn’t included in the host file, then it looks up a DNS server online. This is how the process works.

When you’re dealing with hosts file, the IP address and the domain or hostname should be separated by at least one space or tab. The lines starting with are comments and are ignored.

When you’re ready to edit Ubuntu local host file, follow the steps below:

Step 1: Open Ubuntu Hosts File

The process of editing Ubuntu hosts file is simple and straightforward. To add an entry or modify the hosts file, simply run the commands below to open the hosts file.

sudo nano /etc/hosts

A similar lines below should appear in the file.	localhost	ubuntu1804

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix

Changes you make to the hosts file take effect immediately. If you want to undo changes to the hosts file, simply open the file and remove the lines you added or precede the line with a # to ignore it.

Step 2: Add Host Records

For example, to add an entry to translate to, open the hosts file and add its entry by scrolling down to the end of the file and add your new entries:	localhost	ubuntu1804
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback

Save the file and exit.

As we said above, the changes takes effect immediately. You will be able to in your browser as soon as you save the file.


This is how one add or modify Ubuntu hosts file entry.

For student or new user looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS…. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use.

Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other devices…

When using Ubuntu, you will find that Linux isn’t so different than Windows and other operating systems in so many ways, especially when it comes to using the system to get work done.…

Both Ubuntu and Windows systems allow you to be productive, easy to use, reliable and enable you to install and run thousands of programs from gaming to productivity suite software for individuals and businesses.

You may also like the post below:


  1. A stupid question: how to save the /etc/hosts file?

    1. You just save it, just make sure you opened your text editor as root user or it won’t let you save it.

    2. Run this command in your terminal. It will open the host file in the nano text editor as super user so it can be saved.

      sudo nano /etc/hosts

    3. sudo nautilus 🙂

    4. Ctrl+s or Ctrl+o
      then to exit Ctrl+X

  2. great solution

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.