If you want to access any domain hosted at our servers, but with DNS not pointing to us yet, you will need to edit the hosts file at your computer.
hosts file force viewing a domain to a specific IP, even if it points to any other server.
Depending on your operating system, the location of your hosts file is:
- Windows → C:\\Windows\\System32\\drivers\\etc\\hosts
- Mac OS / iPhone OS → /private/etc/hosts (or use this tool iHosts)
Once you locate the file, you'll need to open Notepad or any other text editor and Run as Administrator, to have enough privileges to be able to edit it, and add the following lines:
67.225.220.181 domain.com* 67.225.220.181 www.domain.com*
You will have to replace the IP with the IP of the server where your account is hosted on, and replace domain with your domain name.
As a simpler alternative, you could use SkipDNS, which will allow you to temporally access domains as if it were hosted at any server.
How to edit hosts file
The hosts file is present on every computer. It is a small “dictionary” that links domain names to IP addresses. It is so useful that, in fact, when we browse the internet, the first thing our browser does is check if there is pre-existing information about the site we want to access in this hosts file as a sort of shortcut. If no record is found, the information must be retrieved via DNS (which is the usual process). In this guide, we will see how to take advantage of this through its editing, especially for cases of recent domains or hosting migrations.
Benefits of editing the hosts file
A common, but not exclusive, use is the manual redirection of a recently purchased domain. This utility is similar to using it to point to a new server in case of hosting migrations. Why? Because, after purchasing a domain and delegating our site (files) to it, the process called “DNS propagation” can take up to 48 hours.
In the meantime, we will not have access to our site, and in the times we live in, we surely need to work on it and/or have it online right away. If we move our site to a new server (with new IP addresses), we will also be subjected to the DNS propagation process, which is why editing the hosts file can be helpful.
By editing the hosts file, we will have immediate access to our site. Of course, it’s important to remember that this resource will be only serve us. Even the neighbor across the street won’t be able to access our site until the delegation process is complete.
What is the hosts file and where is it located?
The hosts file is an ordinary text file. However, its simple nature is somewhat “hidden” because it does not have the typical .txt extension.
The location of the hosts file in Windows is as follows (note: if we have Linux or macOS, we will see the corresponding instructions below):
C:Windows/System32/drivers/etc
And no, it is not a driver even though it is in the “drivers” folder. It seems that on the day they wanted to decide where to place the hosts file within Windows, Mr. Bill got up on the wrong side of the bed.
![](https://duplika.com/blog/wp-content/uploads/2023/04/ubicacion-archivo-hosts.png)
Despite being a simple text file, since it is inside a system folder, we can only edit it with administrator rights.
Achieving this is easy: we simply run our “Notepad” app but by right-clicking to find the following necessary option:
![](https://duplika.com/blog/wp-content/uploads/2024/07/notepad-administrator.webp)
A prompt will appear to allow Notepad to edit protected system files. Something like this:
![](https://duplika.com/blog/wp-content/uploads/2024/07/administrator-prompt-1.webp)
We must click on the “Yes” button.
Once this is done, the text editor will appear on the screen as we know it (but it will allow us to edit and save the otherwise protected hosts file). We will navigate to Open and look for the hosts file in the previously indicated path (C:\Windows\System32\drivers\etc).
Special notice: when we get to the ‘etc’ folder, we will see no file at all. The reason behind this is that none of the files in that folder have the .txt extension.
In order to see the hosts file, we will click where indicated in the screenshot below to select “All files (.)”:
![](https://duplika.com/blog/wp-content/uploads/2024/07/notepad-all-files.webp)
Voilá!
![](https://duplika.com/blog/wp-content/uploads/2024/07/hosts-file-location.webp)
The content of the hosts file is really sparse. It will barely contain an informative text in English explaining its existence. It is below this information where we must type the line that concerns us. For the example, we have used one of Duplika’s DNS and the typical dummy name www.mysite.com
Clearly, we must enter the real DNS provided by our hosting service and write the correct path to our actual site (it might not even use WWW).
![](https://duplika.com/blog/wp-content/uploads/2024/07/add-line-hosts.webp)
Once finished, we will save the changes and close Notepad.
Done! Our operating system will now not look for our web’s IP via DNS as usual since it will know in advance the IP address of the server where we host (whether the DNS propagation is finished or not).
How to edit the hosts file on Linux?
On Linux, we can use any text editor of our choice. For this example, we will use Ubuntu’s Gedit. We must type the following line of code, followed by our Administrator password.
sudo su
Next, we will type:
gedit /etc/hosts
Once the file is open, we will add the IP address and domain of our site just as we have pointed out in the above screenshot for Windows.
How to edit the hosts file on Mac?
To edit the hosts file on macOS, we have to open the launchpad and look for the “Terminal” app. In the Terminal window, we will write the following code:
sudo nano /private/etc/hosts
After entering our Administrator password, the hosts file will open on our Mac. Again, the editing process is the same as seen in the above screenshot for Windows.
By editing the hosts file, our operating system will bypass the internet DNS to locate our site’s server, eliminating the wait for DNS propagation to complete. As a result, we can access our site immediately and begin working on it without delay.
Comments
0 comments
Please sign in to leave a comment.