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.
Editing the local host file on Ubuntu Linux is a useful way to override the default DNS settings. This can be helpful in situations where you need to access a website or server by its domain name, but the DNS server is not resolving it correctly.
You can manually map the domain name to a specific IP address by editing the hosts file. This can also be useful for testing websites or applications on a local network, where you may not have access to a DNS server.
Overall, editing the local hosts file on Ubuntu Linux can be a useful tool for customizing and troubleshooting network settings on your computer.
When you’re ready to edit the 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:
# 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.
This is how one adds or modifies Ubuntu hosts file entry.
You may also like the post below: