When your website moves to new hosting, every visitor reaches the new server once the domain’s DNS records have been changed. It is worth making sure beforehand that everything works there: that the pages load, that you can log in to the admin area and that the forms work. You don’t need to change the domain’s real DNS for this; it is enough to tell your own computer to look for the domain at the new server’s IP address. That is what the hosts file is for, or, more conveniently, a separate browser profile (see below).
How does it work?
The hosts file is a plain text file on your computer that maps domain names to IP addresses. When resolving a name, the operating system checks this file first and only asks DNS if the name is not in it. So if you write in the hosts file that pelda.hu is at the new server’s IP address, your browser connects there, while the rest of the world still sees the site on the old hosting. The browser also sends the domain name in its request, so the new server knows which website to serve, even if many other websites run on the same IP address.
This method is also useful because the website runs on its own domain: a WordPress site, for example, uses the address stored in its database, so on a temporary address it often would not load properly at all.
The IP address of the new hosting
- cPanel hosting: on the cPanel home page, in the General Information box on the right, in the Shared IP Address row.
- Web hosting (KeyHelp): on the Dashboard page, in the IP addresses row. It may show both an IPv4 address (for example
203.0.113.10) and an IPv6 address (for example2001:db8::10).
The IP address is also in the email you received when your hosting was set up. If we carry out the hosting migration for you, we also give it to you in the ticket.
What to write in the hosts file
Each line starts with an IP address, followed by the names, separated by spaces or tabs. You need to add the www version separately, because the file only knows the exact names you enter and does not accept wildcards (*.pelda.hu):
# aWh test, delete after the DNS change
203.0.113.10 pelda.hu www.pelda.hu
2001:db8::10 pelda.hu www.pelda.hu
Replace the domain and IP addresses in the example with your own. You only need the IPv6 line if the new hosting has an IPv6 address; if it does, add that one too. If you leave it out and the domain has an IPv6 (AAAA) record at the old hosting, your computer may still reach the old server over IPv6. The line starting with # is a comment; it helps you find and delete the lines at the end of the test. Don’t put a port or an https:// prefix in the line, only the IP address and the names.
Windows
- Open the Start menu, type
Notepad, right-click it and choose Run as administrator. You need administrator rights because thehostsfile is a system file. -
In Notepad, choose File › Open, paste the path below into the File name field and click the Open button:
C:\Windows\System32\drivers\etc\hosts - Add the lines above to the end of the file and save it (
Ctrl+S). If you get an access denied error when saving, Notepad is not running as administrator. Some antivirus programs protect thehostsfile; in that case, temporarily allow the change in your antivirus software. - Open a Command Prompt and clear your computer’s DNS cache:
ipconfig /flushdns
If you work with the hosts file often, the Hosts File Editor tool in Microsoft’s free PowerToys suite makes it easier to manage: you add the lines in a list and switch them on and off with a toggle.
macOS
-
Open the Terminal app and open the file in the
nanoeditor (your Mac will ask for your user password):sudo nano /etc/hosts - Use the arrow keys to go to the end of the file and type the lines. To save:
Ctrl+O, thenEnter; to exit:Ctrl+X. -
Clear the DNS cache:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Linux
Open the file with root rights, for example with sudo nano /etc/hosts, add the lines to the end and save it. On most systems the change takes effect immediately. The article on the basics of nano and vim shows how to use nano.
Check that you are seeing the new server
Browsers also cache resolved addresses for a while and reuse open connections, so after the change, close all browser windows and restart the browser. Clearing the system and browser caches is described in detail in the article on clearing the local DNS cache.
You can check whether your computer really uses the new address with the ping command, as it also takes the hosts file into account:
ping pelda.hu
At the start of the output, next to the domain, is the IP address your computer resolves the name to: this should be the address of the new hosting. (If no replies follow, that is fine; the address is what matters. On macOS and Linux, ping keeps running until you stop it with Ctrl + C.) The nslookup and dig commands are no good for this, because they query the DNS server directly and do not read the hosts file, so they show the old address even during the test.
A surer sign is to upload a file that exists only on the new hosting, for example test.txt, and open it in your browser (https://pelda.hu/test.txt). If it appears, you are seeing the new server. Delete the file after the test.
If the browser still shows the old site, check whether secure DNS (DNS over HTTPS) is switched on in it, and try without it or in another browser. If ping shows an IPv6 address, add the IPv6 line of the new hosting as well.
Certificate errors during testing
The new hosting can only issue the free SSL certificate once the domain’s DNS points to it, because the certificate authority validates the domain using the real DNS. During the test, the browser will therefore warn you on https:// addresses that the connection is not secure (for example with a NET::ERR_CERT_AUTHORITY_INVALID or NET::ERR_CERT_COMMON_NAME_INVALID error). This is expected here: on the warning page, click the Advanced button to proceed to the site. You can safely log in and fill in forms in this situation too, as you know you are connecting to your own new hosting.
If the browser won’t let you proceed, the site has previously told it to accept it only with a valid certificate (HSTS). In that case, use the separate browser profile described in the next section: it is an empty profile that knows nothing about this, so you can proceed there.
Easier: a separate Chrome or Edge profile, no administrator rights needed
Editing the hosts file affects the whole computer, requires administrator rights, and it is easy to forget the lines in the file, which can cause headaches months later. Chrome and Edge can do the same with a startup switch, but only for the pages opened in that window:
-
Windows (Command Prompt, i.e. cmd, not PowerShell; the command is a single line):
start chrome --user-data-dir="%TEMP%\chrome-test" --host-resolver-rules="MAP pelda.hu 203.0.113.10, MAP www.pelda.hu 203.0.113.10"For Edge, replace
chromewithmsedge. -
macOS (Terminal):
open -na "Google Chrome" --args --user-data-dir="$HOME/chrome-test" --host-resolver-rules="MAP pelda.hu 203.0.113.10, MAP www.pelda.hu 203.0.113.10" -
Linux:
google-chrome --user-data-dir="$HOME/chrome-test" --host-resolver-rules="MAP pelda.hu 203.0.113.10, MAP www.pelda.hu 203.0.113.10"
The --user-data-dir switch starts a separate, empty browser profile. Without it, if the browser is already running, it ignores the switches and opens a new window without the rules. When the new profile starts for the first time, the browser may offer to sign in or to set things up; you can safely skip these. You can also redirect all subdomains with a single rule: MAP *.pelda.hu 203.0.113.10.
Its advantages over the hosts file:
- it needs no administrator rights, so it works on a company computer too;
- only this one window sees the new hosting, while you keep viewing the old site in your usual browser, so you can even compare the two;
- the rule applies to every address, IPv6 included, and caches don’t get in the way;
- there is nothing to undo: close the window and delete the
chrome-testfolder.
On a phone, neither method is easy to use, so during the test it is best to check the responsive view with the developer tools of your desktop browser (F12, device mode).
There are also online services that show a website from a given IP address, but using them hands your login details and session cookies to a third party, so we don’t recommend them for testing an admin area.
Quick check from the command line: curl
If you only want to see whether the server responds and what it sends back, the --resolve option of curl maps the domain to the new IP address for a single command (curl is also available on Windows 10 and 11):
curl -I --resolve pelda.hu:443:203.0.113.10 https://pelda.hu/
The first line is the response code: 200 means the page loads properly, 301 or 302 indicate a redirect, and codes around 500 a server error (common HTTP errors explained). Until the new hosting has a valid certificate, curl stops with an error; in that case, also add the -k option to the command, which skips the certificate check.
After testing
If everything is fine, point the domain’s A record or name servers to the new hosting; the comparison of an A record and a name server change helps you decide which one to use. Then delete the lines from the hosts file and clear the DNS cache again, otherwise your computer will keep using the address you entered here even if the website moves again later. Because of DNS propagation, the change reaches everyone gradually.
Our cPanel hosting and web hosting plans come with free migration: we move the website for you, and you can check it as described above before changing the DNS. If something doesn’t work during the test the way it did on the old hosting, contact our support team.