If you have reached this point, it is because you have had the need to modify the Windows hosts file, something that we need in a more usual way than it seems. Throughout this guide you will learn
how to edit the hosts file in Windows
, in addition to other aspects related to this file that will surely help you.
I am going to divide the tutorial into two parts, a first one where we will enter fully into a simple process to modify the hosts files and a second part where we will delve a little more into the characteristics of this file.
How to edit the hosts file in Windows.
The hosts file is quite peculiar since it is an operating system file. In order to edit it, we will need to configure Windows to show hidden files and we will also need administrator permissions.
How to show hidden files and folders in Windows.
We have to access
Equipo
and from the
Herramientas → Opciones de Carpeta
menu
Herramientas → Opciones de Carpeta
we access the
Ver
tab. Within this tab we activate the option
"Show hidden files, folders and drives"
.
How to run a text editor with administrator permissions.
When we try to edit the hosts file with a text editor we will see that we cannot save the changes, since we need administrator permissions.
As an example I will show you how it would be done with Windows Notepad, although we could use any other text editor like
SublimeText
.
To run Notepad with administrator permissions we go to the
Inicio de Windows → Todos los programas → Accesorios
button
Inicio de Windows → Todos los programas → Accesorios
where we will see the shortcut to Notepad. We click with the right mouse button on the shortcut and in the context menu choose
"Run as administrator"
.
Now that we have Notepad open and with administrator permissions, we go to the
Archivo → Abrir
menu and where it names we paste
%systemroot%\system32\drivers\etc\hosts
and finally press the
Abrir
button.
We already have the hosts file open in Notepad, we only have to make the necessary changes and save them.
What is the hosts file and what is it for?
We will try to explain what the hosts file is used for and know exactly what you are doing when you edit this file. The hosts file of an operating system is a plain text file that translates host names to IP. For example, by default in Windows this file translates the host name
«localhost»
to the IP
«127.0.0.1»
.
The file format is quite simple, the host name is placed first on each line and then
(separated by a space or tab)
the IP. You can also add comments with the
#
character. An example would be:
#Sección personalizada de hosts para entorno de desarrollo (esto es un comentario)
127.0.0.1 TechnoWikis.dev
How to edit the hosts file from the console.
Being able to open and close the text editor with administrator permissions can be quite cumbersome on some occasions. We have a second option for more advanced users that consists of
editing the hosts file from the console
.
The command that we must execute through the
console with administrator permissions
is:
ECHO ^127.0.0.1 TechnoWikis.dev>>%WINDIR%\system32\drivers\etc\hosts
And as an extra method is to use some auxiliary program, personally I like the free and open source program
HostFileEditor
that we can find in
GitHub
.