codeaware GmbH Logo

Testing Server Migration: How to Change the Hosts File

From time to time, a server migration is on the agenda. The complete migration usually takes place through the update of the DNS entries. But how do you test in advance if everything has worked out?

Testing Server Migration: How to Change the Hosts File
Ing. Philipp Doblhofer Ing. Philipp Doblhofer

Ing. Philipp Doblhofer

From time to time, server migrations (e.g., when changing a server host) of a website are necessary. This involves copying all necessary website data and possibly the database to another server. To actually deliver the data of the new server when calling the domain (such as www.codeaware.at), it is necessary to adjust the IP address at the DNS server.

However, before this is carried out, it makes sense to extensively test the copy beforehand. But how can you access the server in the best way? The magic word here is: Hosts file. When a domain is entered in the browser, it attempts to find out the corresponding IP address to finally address the server. Simplified, there are two sources for this:

  1. First, the local hosts file is searched to see if a corresponding entry exists
  2. If no IP address was found, a DNS server is queried. This server, according to the example above, has the address of the old server stored.

Since the hosts file has a higher priority, the server migration can be easily tested by modifying the hosts file. Here, the new IP address for the domain needs to be entered to access the new server via the usual URL.

The hosts file exists on all common systems like Windows, Linux, and Mac. However, administrator permissions are required to edit it.

How to change the hosts file under Windows?

  1. Open the program Editor/Notepad as Administrator Server migration Windows Step 1

  2. Open the file C:\Windows\System32\Drivers\etc\hosts Server migration Windows Step 2

  3. Enter the new server’s IP address in a new line, then – separated by spaces – the desired domain. (e.g., 1.2.3.4 www.demoseite.at) Server migration Windows Step 3

  4. Save the changes

  5. If the changes are not effective immediately, restart the computer. (The DNS entries are cached by the computer)

How to change the hosts file under Linux?

  1. Open the program Terminal
  2. There, enter the command sudo nano /etc/hosts. Sudo allows running programs as administrator. Nano is a console text editor
  3. Enter the user password
  4. In a new line, enter the new server’s IP address, then – separated by spaces – the desired domain. (e.g., 1.2.3.4 www.demoseite.at) Server migration Linux
  5. Save the changes (Ctrl+X, then Y and Enter)
  6. If the changes are not effective immediately, restart the computer. (The DNS entries are cached by the computer)

How to change the hosts file under Mac?

  1. Open the program Terminal
  2. There, enter the command sudo nano /etc/hosts. Sudo allows running programs as administrator. Nano is a console text editor
  3. Enter the user password
  4. In a new line, enter the new server’s IP address, then – separated by spaces – the desired domain. (e.g., 1.2.3.4 www.demoseite.at) Server migration Mac
  5. Save the changes (Control+X, then Y and Enter)
  6. If the changes are not effective immediately, restart the computer. (The DNS entries are cached by the computer)