This article is also available in:

How to find and edit host files on Linux?

The Hosts file is an essential tool to change the way your computer sees a particular website.

Although most users will never need to edit their hosts file, a web developer or user may need to edit the file to view a new site under development.

In order for your computer to display your test site rather than the live site, you must add the IP address of the test site, as well as the domain name, to the Hosts file.

As long as this information is contained in your Hosts file, your browser will redirect the request to display the site to the specified IP address.

This allows us to test the functionality without changing the DNS of our production site.

To edit the file, follow the steps below.

Depending on your operating system version and your personal choice, you have installed one or more desktop environments such as Unity, KDE, Xfce, LXDE, GNOME shell, MATE.
Open the corresponding Notepad (usually via Applications > Accessories > Terminal ).
Enter the following command:

Note that the sudo prefix gives you the necessary root privileges. The hosts file is a system file and is particularly well protected on Ubuntu.

You can then use your notebook or terminal to edit the host file.
On a newline, enter the IP address of the test server and the domain name you want to use for that IP address (for example: ' VOTREDOMAINE.FR`. Of course: will have to be replaced by the IP address of the server and will have to be replaced by your own domain name).
In addition, if your site was using the www. , you will also need to put the following line: ` WWW.VOTREDOMAINE.FR." Then, press Ctrl+O to overwrite the existing file, then press Enter to confirm the overwriting, This saves the changes made to the file.

Updated on: 24/10/2023

Was this article helpful?

Share your feedback


Thank you!