Skip to content

Test a Website Before Changing DNS: Hosts File Override

Updated 6 min read

Updated: 12 October 2026 · Applies to: Windows 10 and 11 (according to Microsoft), macOS (path checked on macOS 27), Linux (tested on Debian 13, Ubuntu 26.04 and AlmaLinux 10.2)

To test your website on a new server before you change DNS, add one line to the hosts file on your own computer: the new server's IP address, then your domain names, for example 203.0.113.10 example.com www.example.com. Your computer checks the hosts file before it asks DNS, so your browser opens the site from the new server while every other visitor still reaches the old one. Remove the line once you have switched DNS.

The hosts file is here:

  • Windows: C:\Windows\System32\drivers\etc\hosts
  • macOS: /etc/hosts (the same file as /private/etc/hosts)
  • Linux: /etc/hosts

How the hosts file overrides DNS

The hosts file is a plain text list of IP addresses and host names. When a program looks up a name, the operating system reads this file first and uses DNS only when the name is not in it. On Linux you can see the order in /etc/nsswitch.conf; Debian 13 and Ubuntu 26.04 both have:

hosts:          files dns

files is the hosts file. Microsoft describes the same order for Windows: the computer checks the hosts file first and only then asks DNS. The change affects only your computer: nobody else sees it, and the domain's real DNS records do not change.

Step 1: Find the new server's IP address

  • VPS or dedicated server: open the service in the client area under Services > My Services, or check its welcome email.
  • cPanel hosting: in cPanel, the General Information panel shows the Shared IP Address (or Dedicated IP Address) of your account.

If you cannot find it, open a ticket and our support team will tell you. The examples below use the documentation address 203.0.113.10; use your own.

Step 2: Edit the hosts file

Windows 10 and 11

  1. Press the Windows key and type Notepad. Right-click Notepad and choose Run as administrator. Without administrator rights you can open the file but not save it.
  2. In Notepad, choose File > Open, go to C:\Windows\System32\drivers\etc and set the file type filter to All files, because the hosts file has no extension. Open hosts.
  3. Add a line at the end:
    203.0.113.10    example.com www.example.com
  4. Save with Ctrl+S. If you use Save As instead, keep the name hosts with no .txt extension.

If you have Microsoft PowerToys, its Hosts File Editor does the same with a form, and according to Microsoft it backs up the hosts file before you edit it.

macOS

  1. Open Terminal (Applications > Utilities).
  2. Run sudo nano /etc/hosts and enter your Mac password.
  3. Add the line at the end, then press Ctrl+O and Enter to save and Ctrl+X to exit. (On current macOS, nano starts the pico editor, which uses the same keys.)

Linux

sudo nano /etc/hosts

Add the line at the end and save. Or add it in one command:

echo "203.0.113.10 example.com www.example.com" | sudo tee -a /etc/hosts

Format rules (the same on all three systems; Microsoft's default Windows hosts file describes them in its comment lines):

  • One IP address per line, then one or more names separated by spaces or tabs.
  • List example.com and www.example.com separately; each subdomain you want to test needs its own name (for example shop.example.com).
  • Wildcards do not work. In our Linux test, an entry for *.example.org did not match shop.example.org.
  • A line that starts with # is a comment, which is a quick way to switch an entry off.

Step 3: Clear cached lookups

Your computer and browser may still remember the old address. Close and reopen the browser, and clear the system DNS cache:

  • Windows: ipconfig /flushdns
  • macOS: sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
  • Ubuntu with systemd-resolved: sudo resolvectl flush-caches

More options, including Chrome's own cache, are in how to clear the DNS cache.

Step 4: Check that your computer uses the new IP

Use ping, which goes through the hosts file. Its first line shows the address it uses. Lab output from a Debian 13 test container with the line above in /etc/hosts:

$ ping -c 1 example.com
PING example.com (203.0.113.10) 56(84) bytes of data.

On Linux, getent ahosts example.com shows exactly what programs will get. Two things that look like failures but are not:

  • dig, nslookup and host ignore the hosts file. They ask DNS servers directly, so in our test they kept showing the domain's public addresses. That is correct: they show what the rest of the world sees.
  • Use getent ahosts, not getent hosts. With only an IPv4 line in the hosts file, getent hosts example.com printed the domain's public IPv6 addresses from DNS, because it asks for IPv6 first. getent ahosts, ping and curl all used 203.0.113.10. To keep IPv6 lookups away from the old server too, add a second line with the new server's IPv6 address, if it has one.

Then open the site in your browser. To prove where a page comes from, put a temporary test file on the new server only, or check with curl. In this lab, a test page on 127.0.0.1 stood in for the new server:

$ curl -sv http://www.example.com/
*   Trying 127.0.0.1:80...
* Connected to www.example.com (127.0.0.1) port 80
< HTTP/1.0 200 OK
Hello from the NEW server

(Output shortened.) HTTPS: the new server may not have a valid certificate for your domain yet, because free certificates are usually issued once the domain points to the server. A certificate warning during the preview is expected; check the site over http:// or accept the warning for this test only.

Test without editing the hosts file

For a quick check from a terminal, curl can override DNS for one request with --resolve:

$ curl -sv --resolve shop.example.net:80:127.0.0.1 http://shop.example.net/
* Added shop.example.net:80:127.0.0.1 to DNS cache
*   Trying 127.0.0.1:80...
* Connected to shop.example.net (127.0.0.1) port 80
< HTTP/1.0 200 OK

Use DOMAIN:443:IP and an https:// address to test the HTTPS site. On cPanel servers, the temporary URL is another way to look at files before DNS changes.

Step 5: Remove the entry after you change DNS

When the site looks right, point the domain to the new server (see how to change nameservers or add an A record in cPanel), then delete or comment out your hosts line and clear the DNS cache again. A forgotten hosts entry is a common reason why a site "works for me" but not for others, or why you keep seeing an old server after a later move. If the domain then does not open at all, see hostname could not be found: fix DNS errors, and check the public DNS answer with dig, nslookup and host.

Related services

Web hosting

shared hosting on Virtualmin with NVMe storage, free SSL and email.

SSL certificates

DV, OV and wildcard, with free installation help.

Reseller hosting

white-label cPanel hosting for your own clients.

Was this answer helpful?

Still stuck? Open a ticket