Test your website before changing DNS: how to use the hosts file
Published on November 9, 2026 8 min read
Preview your site on the new server before you switch DNS. Edit the hosts file on Windows, macOS or Linux and test everything before going live.
You can preview your website on the LJPc hosting server before you change your DNS by editing the hosts file on your own computer. Add one line with the IP address of your hosting package and your domain name. Your computer then loads the site from the new server, while every other visitor still sees your current site. That way you find and fix problems before anyone else notices, and you only switch your DNS once everything works.
This guide covers which IP address to use, how to edit the hosts file on Windows, macOS and Linux, what to expect on https and what to test before you go live. The full migration plan is in migrate your website to LJPc; this article expands on its testing step.
What does the hosts file do?
Every computer has a small text file called hosts in which you can map a domain name to an IP address yourself. Your computer checks this file before it asks DNS. If your domain is listed there, your computer uses that address.
Each line holds an IP address, a space and one or more host names. A line that starts with # is a comment and is ignored. The change only applies to the computer you edit it on, and only for as long as the line is there. Your phone, your colleagues and your visitors are not affected.
Which IP address do you need?
You find the IP address of your hosting package in Plesk, in the DNS check of your domain. It works as soon as your site exists in Plesk, even while your domain does not point to LJPc yet.
- Open Plesk from the customer portal: go to Services, choose Sites, click your site and click Log in to Plesk. See open Plesk from the customer portal for details.
- Open the Hosting & DNS tab of your domain and click DNS check.
- Look at the Expected column on the
yourdomain.com (A)row. That is the IPv4 address. If there is also ayourdomain.com (AAAA)row, its value is the IPv6 address. Click a value to copy it.
The rest of the DNS check is explained in point your domain to LJPc hosting.
Use those addresses to build your lines. Put your domain and the www version on the same line so both go to the new server. With the documentation example addresses it looks like this:
192.0.2.10 yourdomain.com www.yourdomain.com
2001:db8::10 yourdomain.com www.yourdomain.com
Use your own addresses from the DNS check. If your server has an IPv6 address, add the second line too, so your computer also reaches the new server over IPv6. Testing a site on a subdomain, such as shop.yourdomain.com? Put that name on the line, with the addresses from the DNS check of that site.
How to edit the hosts file
| System | Hosts file | Flush the DNS cache |
|---|---|---|
| Windows 10 and 11 | C:\Windows\System32\drivers\etc\hosts | ipconfig /flushdns |
| macOS | /etc/hosts | sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder |
| Linux | /etc/hosts | sudo resolvectl flush-caches (with systemd-resolved) |
You need administrator rights on your computer to save the file.
Windows 10 and 11
- Open Start and type Notepad. Right-click Notepad, choose Run as administrator and confirm the Windows prompt.
- In Notepad choose File > Open and go to
C:\Windows\System32\drivers\etc. In the bottom right, change Text Documents (*.txt) to All files, otherwise the file stays hidden. Openhosts. - Add your lines at the bottom, each on its own line and without a
#in front. - Save with Ctrl+S. Avoid Save As, because Windows may turn the file into
hosts.txt, which your computer ignores. - Open Command Prompt and run
ipconfig /flushdnsto flush the DNS cache.
If Windows says you do not have permission to save, Notepad is not running as administrator. Close it and start again at step 1.
macOS
- Open Terminal (in Applications > Utilities).
- Type
sudo nano /etc/hostsand press Return. Enter your Mac password; nothing appears on screen while you type. - Use the arrow keys to go to the end of the file and add your lines.
- Save with Control+O and Return, then exit nano with Control+X.
- Flush the DNS cache with
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder.
Linux
- Open a terminal and run
sudo nano /etc/hosts. - Add your lines at the bottom, save with Ctrl+O and Enter, and exit with Ctrl+X.
- The change usually takes effect right away. If your system uses systemd-resolved, flush its cache with
sudo resolvectl flush-caches.
Then quit your browser completely and open it again, because browsers hold on to connections and DNS answers for a while. To clear the cache inside Chrome, Edge or Firefox, see what is DNS cache.
How to tell you are on the new server
- With ping. Run
ping yourdomain.comin Command Prompt or Terminal. The first line shows the IP address your computer uses. If that is the address from the DNS check, your hosts file works. Whether replies come back does not matter for this check; stop ping on Mac and Linux with Ctrl+C. - From the page itself. If you see the page This domain is reserved, you are on the new server: it is the default page of a new hosting package. Either your site is not uploaded yet, or that page's
index.htmlis still inhttpdocs. See the Plesk File Manager for uploading your files.
What you see on https: a certificate warning
Your site gets its Let's Encrypt certificate once your domain points to LJPc; our system then requests it for you automatically. During this test your domain has no certificate yet, while the server does send you to https://, even when you type http://. Your browser therefore warns that the connection is not private or not secure, with the code NET::ERR_CERT_COMMON_NAME_INVALID in Chrome and Edge or SSL_ERROR_BAD_CERT_DOMAIN in Firefox. The server presents its own certificate, which does not match your domain. During this test, that is exactly what you should expect.
- Continue to your site. Click Advanced in the warning and choose to proceed to your domain. Only do this for your own domain, during this test.
- No option to proceed? Your browser remembers that your current site only works over https (HSTS). Test in a different browser in which you have never opened your site.
After you switch your DNS, the real certificate follows automatically. See Let's Encrypt for how that works.
What to test before you switch your DNS
- Pages and navigation. Click through your main pages, your menu and your search. Check that images, fonts and downloads load.
- Logging in. Log in to the back end of your site, for example
/wp-adminfor WordPress, and open a few settings. - Forms. Send a test message. If your form sends to an address on your own domain while your email is hosted elsewhere, also test with an address on another domain. The reason is explained in contact form not sending email.
- Your online shop. Check products and the cart. Test a real payment only after the switch: your payment provider sends its confirmation to your domain, which still points to your old host for everyone else.
- Mobile view. You cannot edit the hosts file on a phone. Check the mobile version on your computer with your browser's developer tools (F12).
- Errors. Blank page or an error message? Find the cause in the Plesk error log. A database connection error is fixed in your site's configuration file, as in step 6 of migrate your website to LJPc.
Still working on your old site while you test, or receiving orders and messages there? Copy those changes over right before the switch, for example with a fresh export of your database.
Still seeing your old website?
| What you see | Cause | Fix |
|---|---|---|
ping still shows the old IP address | The file was not saved, there is a # in front of your line, the name has a typo, or Windows saved it as hosts.txt | Open the file again, check your line and save as described above |
ping shows the new address, your browser the old site | Your browser still holds the old address | Quit your browser completely or clear the browser cache |
| It stays on the old site, even after clearing the cache | Your browser uses secure DNS (DNS over HTTPS) and skips the hosts file | Temporarily turn off secure DNS in your browser settings, or test in another browser |
Only www.yourdomain.com or only yourdomain.com reaches the new server | The other name is missing from your line | Put both names on the line |
After testing: remove the line and switch your DNS
Once everything works, remove your lines from the hosts file, or put a # in front of them, and flush the DNS cache again. That way you see what your visitors see after the switch, and your computer never ends up pointing to a fixed address you forgot about.
Then point your domain to LJPc: with the LJPc nameservers, or with records at your current provider as in point your domain to LJPc hosting. How long it takes before everyone reaches the new server is explained in what is DNS propagation. Prefer not to move your site yourself? LJPc hosting helps you migrate your website for free. Contact us to get started.
Frequently asked questions
Will my visitors notice my hosts file test?
No. The hosts file only works on the computer you edit it on. All your visitors keep reaching your current website until you change the DNS of your domain.
Where do I find the IP address of my LJPc hosting package?
In Plesk, in the DNS check of your domain: open the Hosting & DNS tab and click DNS check. The Expected column shows the IPv4 address on the A row and the IPv6 address on the AAAA row.
Why do I get a certificate warning when I open my site through the hosts file?
Your domain only gets its certificate once it points to LJPc. During the test the server shows its own certificate, which does not match your domain. Click Advanced and proceed to your site; the real certificate follows automatically after the switch.
Can I test my website through the hosts file on my phone?
You cannot edit the hosts file on an iPhone or Android phone. Test on your computer and check the mobile view with your browser's developer tools (F12).
Should I remove the hosts file entry after testing?
Yes. That way you see what your visitors see after the switch, and your computer does not keep pointing to a fixed IP address if something changes later. Remove the line or put a # in front of it and flush the DNS cache.
Does the hosts file work for a subdomain too?
Yes. Put the full name on the line, for example shop.yourdomain.com, with the IP address from the DNS check of that site.