This tutorial instructs on how to modify Ubuntu local host files. The host file, a plain-text document, maps IP addresses to hostnames on a local computer, with priority over DNS. Editing is done via commands, with any changes taking effect immediately. To add an entry, users must input the domain and corresponding IP address.
This brief tutorial shows students and new users how to edit or modify Ubuntu local host files.
When you think of a host file, think of it as a plain-text file used by the operating systems to map IP addresses to the hostname on the local computer. The host’s 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 connects to the server that hosts the website.
While translating the name to IP, the local host’s file is the first file your operating look at. If the IP to domain mapping isn’t included in the host file, it looks up a DNS server online. This is how the process works.
When dealing with a host 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:
Open Ubuntu Hosts File
The process of editing Ubuntu host files is simple. To add an entry or modify the host’s file, simply run the commands below to open the host’s file.
sudo nano /etc/hosts
Similar lines below should appear in the file.
127.0.0.1 localhost 127.0.1.1 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 host’s file take effect immediately. If you want to undo changes to the host’s file, simply open the file and remove the lines you added or precede the line with a # to ignore it.
Add Host Records
For example, to add an entry to translate 127.0.0.1 to example.com, open the host’s file and add its entry by scrolling down to the end of the file and add your new entries:
127.0.0.1 localhost
127.0.1.1 ubuntu1804
127.0.0.1 example.com
# 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 take effect immediately. You can use example.com in your browser when you save the file.
Conclusion:
This is how one adds or modifies Ubuntu hosts file entry.
You may also like the post below:
A stupid question: how to save the /etc/hosts file?
You just save it, just make sure you opened your text editor as root user or it won’t let you save it.
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
sudo nautilus 🙂
Ctrl+s or Ctrl+o
then to exit Ctrl+X
great solution