Modify the hosts file – .com

In this tutorial we will see what the hosts file is, what it is for, and how to modify it to test a website that we are developing or renewing.

What is the hosts file?

To make it easy, we could say that it is a file that our computer consults before accessing a website, and that we can use filterto prohibit or modify access to certain web pages.

Actually technically it goes further, but for what we are going to do today that explanation is the simplest.

Many companies, organizations and schools use the hosts file to prohibit access to certain websites, such as social networks, erotic content pages, forums, etc. This is how they keep their workers, members or students from using the connection for something that is not related to their work.

Thus, before connecting to the web, the computer consults the file. If it is prohibited, it does not go any further and the connection is terminated. But if that website is not listed, then it already connects to our Internet access provider, so that it gives you access to that website.

Using hosts to “redirect” a website

Well, as we can see, this useful file allows us to prohibit access to certain websites. But in reality, what we are doing is not a “ban” as such, but rather a “redirection”.

To understand it better, let’s see how it is done, so it will be very clear. Let’s imagine we want to remove access to ebay.com. We would only have to add this line at the end of the entire file:

127.0.0.1 ebay.com

And that’s it. Nothing more. Only with this we have already “captured” that web. But why? What have we really done? Just a redirect.

We have told our computer that ebay.com it is actually located at the IP address 127.0.0.1, instead of the actual IP. And why 127.0.0.1 exactly? Well, simply because that IP is our localhost, that is, our computer. This is always the case, regardless of your computer or operating system. There are even some freaky T-shirts with the message “There is no place like 127.0.0.1”, alluding to “There is no place like home”. 😉

See also  Remove "Add to cart" button in WooCommerce - .com

We could also have banned it with a wrong IP:

0.0.0.0 ebay.com

And that will simply give an error, since that IP does not exist.

Anyway, curiosities aside, we have to understand that we are telling our computer that any connection to that website must go to that specific IP, thus preventing it from ever reaching its real IP, where the website is hosted. But then… What would happen if instead of 127.0.0.1 we put another IP? Indeed, what you imagine. On that computer, when someone connected to that website, they could see the content of another server.

Hence many viruses try to access that localhost. Imagine what they could do by changing the IPs of the websites of the main banking entities. They could make a website with a homepage identical to that of your bank and redirect everyone there, to capture users and passwords. very dangerous

But come on, we are not here to give Machiavellian ideas, but rather to give this file a more practical and educational utility, such as its use to view webs in production.

Use hosts to see a web in production

Thus, in the same way that we can direct any domain to our localhost to “prohibit” access to a website, we can also direct any domain to an IP where we have hosted a website that we are developing. Let’s see an example.

Let’s imagine that we have to redesign the web “example.com”. And we are doing it in a temporary domain, of the style “example.com.mialias.net”. If you don’t know how to do this, take a look at the tutorial.

See also  Timp Course #8. Timp Express and Timp App - .com

One option would be to work all the time with the subdomain “example.com.mialias.net”. And in principle nothing strange would happen. But of course, when we have finished, we will have to modify all the URLs of the database so that instead of “example.com.mialias.net” they go to “example.com”. How could we avoid that? Obviously with the hosts file.

Let’s imagine that “example.com” points to the IP 23.92.23.113, which is where the web is. Well, we could tell you that on that computer (and only in that one), point to another IP, which is where we are developing the web. For example, at 25.91.32.123. To do that we simply have to write this at the end of the file

25.91.32.123 example.com

And that’s it. Now when someone connects to “example.com” they will see the web we are creating on that IP, instead of the real one. Obviously, we can also direct that domain to our localhost (127.0.0.1), but for that we should set up a server environment that “collects” that website, something more technical. I tell you how to do it in the tutorial

It is important to note that this website “in development” will only be seen by us on that computer, so if we want someone else to see it, we must tell them to modify their hosts file so that it also points to that IP. So, if we want to show a client a website that we are developing, we must tell them how to add that line (and remind him not to worry if he sees errors, because only he sees them 😉.

Where is the hosts file?

Ok, are you ready to mess around with the hosts file? Well, the first thing is to locate its location. It depends on the operating system you use, but for the two main ones you have it in:

  • Windows: C:\WINDOWS\system32\drivers\etc\hosts
  • OSX: /private/etc/hosts
See also  File and folder permissions in WordPress - .com

It looks something like this, depending a bit on whether you have already edited it yourself or some program you have installed:

In the case of Windows, you can open and edit it with any word processor, even with notepad. And in the case of Mac, you must do it with Nano, the file editor that already comes with the system. You can do it with the following Terminal function:

sudo nano /private/etc/hosts

And in both cases, editing it is as easy as adding the lines you want below everything, saving and that’s it.

Summary and conclusion

If we want to create a website in a “whatever.com” domain, but without touching what is in that domain while we are doing it, we can create a “redirection” on our computer so that instead of showing the real website, it will see the website in tests

To do it, as easy as adding a line in our “hosts” file with the IP where we want it to go (whether it is local or online) and the domain that we want to redirect.

Anyway, gentlemen, this is all for today. You already know that if you want to learn more, you have at your disposal the . More than 400 videos, and on top of that a new class every day. And you are also helping me to continue writing these 😉

Loading Facebook Comments ...
Loading Disqus Comments ...