+5 votes
246 views
How to edit the hosts file in Windows easily

in Guides by (552k points)
reopened | 246 views

1 Answer

+3 votes
Best answer

How to edit the hosts file in Windows.
What is the hosts file and what is it for?
How to edit the hosts file from the console.
How to show hidden files and folders in Windows.
How to run a text editor with administrator permissions.

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.

image

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" .

image

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" .

image

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.

image

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 .


by (3.5m points)

Related questions

+3 votes
1 answer
+5 votes
1 answer
asked Aug 9, 2019 in Guides by backtothefuture (552k points) | 183 views
+5 votes
1 answer
asked Aug 10, 2019 in Guides by backtothefuture (552k points) | 420 views
+5 votes
1 answer
+5 votes
1 answer
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users