Modify 'hosts' file in Windows, Mac and Linux

Aggiornato il 2026-10-21 14:00:48 387 visite

Occasionally, during a migration or other server change processes, it may be necessary to check the web content hosted on a new server without modifying the domain's DNS yet.

This allows verifying that the website works correctly in the new environment before permanently pointing the domain to SW Hosting's servers.

To do this, you can force the domain resolution to a specific IP by modifying the operating system's hosts file. This change only affects the local machine where the configuration is performed.

hosts file configuration by operating system

Windows

  1. Search for Notepad in the start menu.
  2. Right-click and select Run as administrator.
  3. Open the file:
C:\Windows\System32\drivers\etc\hosts
  1. Add a line with the IP of the new server and the domain:
81.25.123.45 swhosting.com www.swhosting.com
  1. Save the changes from File → Save.

From that moment on, when accessing swhosting.com, the browser will resolve the domain to the IP indicated in the hosts file instead of the one configured in DNS.

This change only affects the computer where the modification is made.

To restore normal behavior, delete the added line.
To apply the change globally, it will be necessary to modify the nameservers or the DNS records (A record).

info Remember to remove the entry from the hosts file once the tests are completed.

macOS

  1. Open Terminal (you can search for it in Spotlight).
  2. Edit the hosts file with the following command:
sudo nano /private/etc/hosts
  1. Enter the administrator password.
  2. Go to the end of the file and add:
81.25.123.45 swhosting.com www.swhosting.com
  1. Save the changes with Ctrl + O.
  2. Exit the editor with Ctrl + X.
  3. Clear the DNS cache:
dscacheutil -flushcache

After this, the domain will resolve to the indicated IP instead of the one configured in DNS.

info This change only affects the local machine. Remember to remove the line from the hosts file when it is no longer needed.

Linux

  1. Open the Terminal.
  2. Edit the hosts file:
sudo nano /etc/hosts
  1. Add to the end of the file:
81.25.123.45 swhosting.com www.swhosting.com
  1. Save with Ctrl + O and exit with Ctrl + X.

From that moment on, the system will resolve the domain to the indicated IP.

info This change only affects the local machine. To revert it, delete the added line.

Important note

This method is useful for migration tests, as it allows checking the operation of a website on a new server without affecting the real traffic of the domain.

To make the definitive change, it will be necessary to update:

  • DNS servers (nameservers)
  • DNS records (A record)