2.1.5 How to work with a site without an active domain using the hosts file
When you start creating your own website, a situation may arise when you need to check its functionality, but you do not yet have a registered domain name. In such cases, it is very convenient to be able to work with your site without having a domain. In the article, we will consider a method that will enable you to work with a site without a domain name.
If it is necessary to check your website during its transfer from one hosting to another, it is important to make sure that it is operational before redirecting the domain. This method is great for such a check and will help avoid possible problems during the site migration
In the article, we will consider the method of working with the site by configuring the hosts file on your computer. This method allows you to redirect requests directly to a specific IP address when working with a website.
Editing the hosts file
In the hosts file, entries are contained in the form of IP
domain
, between which there must be a space character or a tab (to indent, it is enough to press the Tab
button on the keyboard).
- This example uses the IP address
192.192.192.192
and the domainexample.domain.com
.
You will need to substitute your Hosting/Server IP and Domain. - All lines starting with the character # are considered a comment - this means that the line with the entry will not work.
Important: Administrator or root privileges are required to edit the hosts file.
How to find the hosts file in the Windows operating system
To find the hosts file in the Windows operating system, you need to open File Explorer, find the hosts file and open it with a text editor. Next, we will describe each step:
1. Open the hosts file located in the directory C:\Windows\System32\drivers\etc
.
2. Add two lines to the end of the file: IP address of your_domain
and IP address of www.your_domain
.
192.192.192.192 example.domain.com
192.192.192.192 www.example.domain.com
- Instead of
192.192.192.192
, substitute theIP address
of the hosting/server. - Replace
example.domain.com
with yourdomain
.
3. Save the file.
How to find the hosts file in Linux/MacOS
In Linux and MacOS operating systems, the hosts file can be opened using the terminal, below we will describe the steps to be taken to open the terminal. Next, we will describe each step:
1. Open a terminal.
For Linux:
- Press Ctrl + Alt + T. This is the standard keyboard shortcut for opening a terminal in most distributions.
- Alternatively, open the applications menu and search for terminal or terminal emulator.
For MacOS:
- Open Terminal using Spotlight: Press Cmd + Space, type Terminal, then press Return.
- Or go to Programs - Utilities - Terminal and open Terminal from there.
2. Enter the command
- sudo nano /etc/hosts
- you will need to specify the root password.
3. Add two lines to the end of the file: IP address of your_domain
and IP address of www.your_domain
.
192.192.192.192 example.domain.com
192.192.192.192 www.example.domain.com
- Instead of
192.192.192.192
, substitute theIP address
of the hosting/server. - Replace
example.domain.com
with yourdomain
.
4. Press Ctrl + X, then Y to save changes.
Important: after using this method, be sure to remove or comment out the lines in the hosts file when you’re done with the site, as they can prevent normal access to real domains. Verify that you have entered the correct IP address and domain name to avoid redirection issues. Be careful with changes in the hosts file, as this may affect the operation of your operating system.