Domains & DNS

Test a Website on a New Server Before DNS Changes (Hosts File Guide)

A simple tweak to your system’s hosts file can allow immediate access to a website without waiting for DNS propagation.

Short answer: Add a line with the new server’s IP address and your domain to your computer’s hosts file, for example 203.0.113.10 example.com www.example.com. Your computer then opens the site from the new server, while everyone else still sees the old one. The file is C:\Windows\System32\drivers\etc\hosts on Windows and /etc/hosts on macOS and Linux. Flush your DNS cache, test the site, and remove the line once DNS has been updated.

Why DNS changes take time

When you change a DNS record, resolvers around the world keep the old answer until its TTL (time to live) runs out. This is often called propagation. With a typical TTL it takes from a few minutes to a day, and in some cases up to two days. The hosts file lets you skip that wait on your own computer, so you can check the new server before anyone else is sent to it.

The hosts file only changes what your computer sees. It does not speed up DNS for visitors.

Step 1: find the new server’s IP address

The IP address is in your hosting welcome email, in cPanel under General Information (Shared IP Address or Dedicated IP Address), or in your server details. The examples below use 203.0.113.10; replace it with your own.

Step 2: edit the hosts file

Windows

  1. Open the Start menu, type Notepad, right-click it and choose Run as administrator.
  2. Choose File > Open and open C:\Windows\System32\drivers\etc\hosts. Set the file type to All Files so it appears.
  3. Add the line at the end of the file and save.

macOS and Linux

sudo nano /etc/hosts

Add the line at the end, then press Ctrl+O and Enter to save, and Ctrl+X to exit.

The line to add

203.0.113.10 example.com www.example.com

Use only the domain names, without http://, https:// or a path. Lines that start with # are comments.

Step 3: clear the DNS cache

# Windows (Command Prompt)
ipconfig /flushdns

# macOS
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

# Linux with systemd-resolved
sudo resolvectl flush-caches

Close and reopen the browser, because browsers keep their own short DNS cache. If the old site still appears, try a private window. Browsers set to use secure DNS (DNS over HTTPS) may skip the hosts file, so turn that setting off while you test. Our guide to flushing DNS and browser caches has more detail.

Step 4: confirm you are on the new server

ping example.com          # should show 203.0.113.10
nslookup example.com      # shows public DNS, which ignores the hosts file

ping uses the hosts file, so it should show the new IP address. nslookup asks a DNS server directly, so it still shows the old address until DNS changes. That difference is a quick way to confirm your hosts entry works. A small test file, for example a test.txt uploaded only to the new server, also tells you which server you reached.

Test without editing any file

If you are comfortable with the command line, curl can send a single request to the new server without changing your hosts file:

curl -I --resolve example.com:443:203.0.113.10 https://example.com/
curl -I --resolve example.com:80:203.0.113.10 http://example.com/

What to check on the new server

  • ✓ The home page and key pages load, with images and styles.
  • ✓ Logins, contact forms and checkout work.
  • ✓ The site connects to its database without errors.
  • ✓ Email settings, if the site sends mail.
  • ✓ Scheduled tasks (cron jobs) are set up.

A certificate warning is normal at this stage if the new server cannot get a Let’s Encrypt certificate until DNS points to it. AutoSSL issues one shortly after the switch.

Step 5: remove the hosts entry

Once you change DNS and the new records are live, delete the line from the hosts file and flush the DNS cache again. A forgotten entry keeps your computer on that IP address, even after a later move, which is a common cause of “the site works for everyone but me”.

Planning a move? See our guide to moving a website without downtime.

Need help with this?

Moving to UnderHost? Our team can help copy your site and plan the DNS switch.

See web hosting plansContact @CustomerPanel

Frequently asked questions

Does editing the hosts file speed up DNS propagation?

Only for your own computer. Visitors still see the old server until their DNS caches expire.

Where is the hosts file on Windows?

C:\Windows\System32\drivers\etc\hosts. Open it with Notepad running as administrator.

Why does my browser still show the old site?

The browser or system DNS cache still has the old address, or the browser uses secure DNS. Flush the cache, restart the browser, or try a private window.

Can I use the hosts file on a phone?

Not easily. Test from a computer, or use curl with the –resolve option.

How do I lower the wait before switching DNS?

A day before the move, lower the TTL of your DNS records, for example to 300 seconds. The switch then reaches most visitors within minutes.