Il file hosts allows you to map a domain to a specific IP address, bypassing DNS. By editing this file, you can make your computer access a specific domain (even if not yet mapped to the internet) by pointing it to a local IP address or test server.
To proceed you must know the server IP and, obviously, the domain name.
For example, if you have a cpanel with dominiomio.com but the domain has not yet been purchased or its DNS connects it to another server, to view what is present in the cpanel, you must modify the hosts file as described below.
**Here's how to edit the file*hosts* on Windows, macOS and Linux:**
🖥 Windows
- Open Notepad as administrator:
- award
Win + S
, typeBlocco note
(o Notepad). - Right-click on Notepad and select Run as administrator.
- Open the hosts file:
- From the menu File > Open.
- Go to this directory:
C:\Windows\System32\drivers\etc\
- Select the file
hosts
. (Make sure to choose “All Files” in the opening window.)
- Edit the file:
Add a new line with the following syntax:
<IP_del_server> <nome_del_dominio>
Example:
192.168.1.100 www.miosito.local
Like this, typing www.miosito.local
in the browser, your computer will access the local server with IP 192.168.1.100
.
- Save the file:
- award Ctrl + S to save.
- Clear your DNS cache (optional but recommended):
- Open Command Prompt as administrator (
cmd
) and type:ipconfig /flushdns
🍏 macOS
- Open Terminal:
- Go up Applications > Utility > Terminal.
- Edit the hosts file:
- Type the command:
sudo nano /etc/hosts
- Enter your administrator password if required.
- Add a new line:
<IP_del_server> <nome_del_dominio>
Example:
192.168.1.100 www.miosito.local
- Save and close:
- award
Ctrl + O
, ThenInvio
to save. - award
Ctrl + X
to exit the editor.
- Clear your DNS cache:
- Type in Terminal:
sudo dscacheutil -flushcache sudo killall -HUP mDNSResponder
🐧 Linux
- Open Terminal.
- Edit the hosts file:
- Type:
sudo nano /etc/hosts
- Add a new line:
<IP_del_server> <nome_del_dominio>
Example:
192.168.1.100 www.miosito.local
- Save and close:
- award
Ctrl + O
, ThenInvio
to save. - award
Ctrl + X
to exit the editor.
- Clear your DNS cache:
- It depends on the distribution, but common commands are:
sudo systemctl restart systemd-resolved
or:sudo /etc/init.d/networking restart
🛠 Important Notes:
- Backup del file hosts: Before modifying it, it is always advisable to make a copy of the original file.
- After the change, if it doesn't work immediately, try restarting your browser or the entire system.