Testing a Website Using a Local DNS Resolver

The following Help Center article describes how you can easily test websites on a server on the Internet without having to make any changes to your DNS settings.

Prerequisites

  • Linux, macOS, Windows
  • Administrator privileges



General Explanation

All common operating systems have a hosts file in which a simple mapping of IPv4 or IPv6 addresses to a FQDN (Fully Qualified Domain Name) can be stored for name resolution.

The syntax is the same across operating systems, but the file is located in different places within the file system depending on the operating system.

As soon as your system attempts to resolve a domain name to an IP address, it first checks the hosts file to see if there are any entries for the domain; if not, it sends the request to the configured DNS server as usual.


Remember to remove the changes after your tests to avoid unwanted side effects with DNS name resolution.


Please note that certificate error messages may occur if the web server associated with the IP address listed in /etc/hosts does not have a valid certificate for the domain you specified.



Syntax

The file consists of pairs of IPv4 or IPv6 addresses and domain names, as shown in the following example:

# Comment

# <ipv-4-address> <FQDN>
# <ipv-6-address> <FQDN>

1.2.3.4 staging-test.mydomain.de
2001:db8:1234:5678::1 staging-test.mydomain.de

1.2.3.4 mydomain.de
2001:db8:1234:5678::1 mydomain.de


In the example above, when staging-test.mydomain.de is resolved to 1.2.3.4 when using IPv4 and to 2001:db8:1234:5678::1 when using IPv6, even though the DNS servers would resolve it to a different IP address. The same applies to the main domain meinedomain.de.



Linux and macOS

On Linux and macOS, the file is located at /etc/hosts and can be edited with any standard text editor, such as nano.


Editing /etc/hosts requires root privileges, which is why the command must usually be run with sudo on client machines.

sudo nano /etc/hosts



Windows

Windows manages the file at the path C:\Windows\System32\drivers\etc\hosts, which also requires administrator privileges to edit.

The following examples open the file for editing using Windows Notepad.

CMD (Administrator password must be entered manually):

runas /user:Administrator "notepad C:\path\to\file.txt"
Enter the password for Administrator:


PowerShell (UAC authorization, GUI-based Yes/No prompt):

Start-Process notepad.exe -ArgumentList "C:\Windows\System32\drivers\etc\hosts" -Verb RunAs



Common Error Messages


Expected webpage does not load

If you believe you are not accessing the correct website, it is possible that your local DNS cache still contains the original IP address (before the change), which prevents the DNS query from being routed through either the /etc/hosts file or your configured DNS server.

Clearing the DNS cache on your client system is a possible solution; this can be done as follows:


Windows

Open PowerShell or CMD:

ipconfig /flushdns


macOS

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder


Linux

NetworkManager:

sudo nmcli general reload dns-full

Systemd-Resolver:

 sudo systemd-resolve --flush-caches

or

 sudo resolvectl flush-caches

Dnsmasq:

sudo systemctl restart dnsmasq