{"id":1679,"date":"2026-09-03T17:21:11","date_gmt":"2026-09-03T11:51:11","guid":{"rendered":"https:\/\/cpanelfree.com\/blog\/how-to-test-migrated-website-before-changing-dns-hosts-file\/"},"modified":"2026-09-03T17:24:32","modified_gmt":"2026-09-03T11:54:32","slug":"how-to-test-migrated-website-before-changing-dns-hosts-file","status":"publish","type":"post","link":"https:\/\/cpanelfree.com\/blog\/how-to-test-migrated-website-before-changing-dns-hosts-file\/","title":{"rendered":"How to Test a Migrated Website on New Server Before Changing DNS (Hosts File Guide)"},"content":{"rendered":"<div style=\"background-color: #f8fafc;border-left: 4px solid #0ea5e9;padding: 20px;border-radius: 6px;margin-bottom: 25px\">\n<p style=\"margin: 0;font-size: 16px;color: #1e293b\">\n        <strong>Quick Answer:<\/strong> To test a migrated website on a new server before changing public DNS records, add your new server IP and domain name to your local computer&#8217;s <code>hosts<\/code> file (e.g. <code>203.0.113.50 yourdomain.com www.yourdomain.com<\/code>). This forces your computer to resolve the domain to the new server while all other global visitors continue browsing the old server without interruption.\n    <\/p>\n<\/div>\n<h2>Why You Should Never Update DNS Without Pre-Testing<\/h2>\n<p>Changing your domain nameservers or A record before testing is dangerous. If database credentials in <code>wp-config.php<\/code> have a typo, PHP versions are incompatible, or rewrite rules fail, your live visitors will experience broken layouts and 500 errors. Editing your local <strong>hosts file<\/strong> creates an isolated sandbox where you can test WooCommerce checkout, login sessions, and contact forms safely.<\/p>\n<h2>Step 1: Editing the Hosts File on Windows<\/h2>\n<ol style=\"padding-left: 20px;line-height: 1.8\">\n<li>Press the <strong>Windows Key<\/strong>, type <code>Notepad<\/code>, right-click it, and select <strong>Run as administrator<\/strong>.<\/li>\n<li>In Notepad, click <strong>File &gt; Open<\/strong> and browse to: <code>C:\\Windows\\System32\\drivers\\etc\\hosts<\/code> (Select <em>All Files (*.*)<\/em> in the file type dropdown).<\/li>\n<li>Scroll to the bottom of the file and add your new server IP followed by your domain:\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">203.0.113.50 yourdomain.com\n203.0.113.50 www.yourdomain.com<\/pre>\n<\/li>\n<li>Save the file and flush your DNS: <code>ipconfig \/flushdns<\/code>.<\/li>\n<\/ol>\n<h2>Step 2: Editing the Hosts File on macOS \/ Linux<\/h2>\n<p>Open Terminal and edit the hosts file with sudo privileges:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">sudo nano \/etc\/hosts<\/pre>\n<p>Add the line at the bottom, save (<code>Ctrl + O<\/code>, <code>Enter<\/code>), exit (<code>Ctrl + X<\/code>), and flush DNS cache:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder<\/pre>\n<h2>Step 3: Alternative Browser Extension Method (Virtual Hosts)<\/h2>\n<p>If you don&#8217;t have administrator privileges on your computer, install the free <strong>Virtual-Hosts<\/strong> or <strong>LiveHosts<\/strong> extension for Google Chrome. Enter your new server IP and domain name to toggle between old and new servers with a single click.<\/p>\n<div style=\"background-color: #f8fafc;border: 1px solid #e2e8f0;border-left: 4px solid #0ea5e9;padding: 20px;border-radius: 8px;margin: 30px 0\">\n<h3 style=\"margin-top: 0;color: #0f172a;font-size: 18px;display: flex;align-items: center\">\n        <span style=\"margin-right: 8px\">\ud83d\udd17<\/span> Recommended Related Technical Guides:<br \/>\n    <\/h3>\n<ul style=\"margin: 10px 0 0 0;padding-left: 20px;line-height: 1.8\">\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/what-is-dns-ttl-best-values-before-migration\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">What is DNS TTL and Best Pre-Migration Values<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-migrate-wordpress-to-new-host-manually\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">How to Migrate WordPress Manually (Zero Plugins)<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-check-global-dns-propagation-live-tools\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">How to Check Global DNS Propagation Live<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/#plans\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">Explore $0 Free cPanel Web Hosting Plans<\/a><\/li>\n<\/ul>\n<\/div>\n<h2>Automating Hosts File Testing with Modern Browser Developer Tools<\/h2>\n<p>In addition to manual hosts file editing, web developers can use the <code>curl<\/code> command with the <code>--resolve<\/code> flag to test origin server response codes and SSL handshakes directly from the terminal:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\"># Test target IP directly presenting production domain headers\ncurl -Iv https:\/\/yourdomain.com --resolve yourdomain.com:443:203.0.113.50<\/pre>\n<p>Verify that the output returns <code>HTTP\/2 200 OK<\/code> and that the SSL certificate subject name matches your domain.<\/p>\n<h2>Validating WooCommerce Checkout and Session Cookies<\/h2>\n<p>While testing via the local hosts file, perform a complete end-to-end transaction in test mode: add products to cart, proceed to checkout, verify payment gateway webhooks, and confirm transactional order receipt emails.<\/p>\n<h2>Comprehensive Hosts File Testing Checklist for Migrated Websites<\/h2>\n<ul style=\"padding-left: 20px;line-height: 1.8\">\n<li>\u2705 <strong>Verify WordPress Admin Login:<\/strong> Log in to <code>\/wp-admin\/<\/code> and ensure session cookies persist without redirection loops.<\/li>\n<li>\u2705 <strong>Test WooCommerce Checkout:<\/strong> Place a test transaction using Stripe\/PayPal sandbox mode to verify SSL webhook communication.<\/li>\n<li>\u2705 <strong>Submit Contact Forms:<\/strong> Test contact forms and transactional email delivery to verify SMTP connectivity.<\/li>\n<li>\u2705 <strong>Check Media Uploads:<\/strong> Upload a new image in the Media Library to verify directory write permissions (<code>chmod 755 wp-content\/uploads<\/code>).<\/li>\n<li>\u2705 <strong>Audit Console Errors:<\/strong> Open Chrome DevTools (F12) and inspect the Console tab for any mixed content warnings or 404 JavaScript errors.<\/li>\n<\/ul>\n<h2>Flushing Local DNS Resolver Caches Across Platforms<\/h2>\n<table style=\"width: 100%;border-collapse: collapse;margin: 20px 0;font-size: 14px\">\n<thead>\n<tr style=\"background-color: #0f172a;color: #ffffff\">\n<th style=\"padding: 10px;border: 1px solid #334155\">Operating System<\/th>\n<th style=\"padding: 10px;border: 1px solid #334155\">DNS Flush Command<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background-color: #f8fafc\">\n<td style=\"padding: 10px;border: 1px solid #cbd5e1;font-weight: bold\">Windows 11 \/ 10<\/td>\n<td style=\"padding: 10px;border: 1px solid #cbd5e1\"><code>ipconfig \/flushdns<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border: 1px solid #cbd5e1;font-weight: bold\">macOS (Sonoma \/ Ventura)<\/td>\n<td style=\"padding: 10px;border: 1px solid #cbd5e1\"><code>sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder<\/code><\/td>\n<\/tr>\n<tr style=\"background-color: #f8fafc\">\n<td style=\"padding: 10px;border: 1px solid #cbd5e1;font-weight: bold\">Linux (systemd-resolved)<\/td>\n<td style=\"padding: 10px;border: 1px solid #cbd5e1\"><code>sudo resolvectl flush-caches<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div style=\"background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);border: 1px solid #334155;border-radius: 12px;padding: 25px;margin: 30px 0;text-align: center\">\n<h3 style=\"color: #38bdf8;margin-top: 0;font-size: 20px\">Zero-Risk Website Migrations on CpanelFree<\/h3>\n<p style=\"color: #94a3b8;font-size: 14px;line-height: 1.6;max-width: 600px;margin: 0 auto 15px\">\n        Test and deploy websites with 100% confidence. Enjoy free staging environments, cPanel management, and NVMe SSD hosting on <strong>CpanelFree<\/strong>.\n    <\/p>\n<p>    <a href=\"https:\/\/cpanelfree.com\/free-wordpress-hosting\" style=\"display: inline-block;background-color: #0ea5e9;color: #ffffff;padding: 10px 22px;border-radius: 6px;text-decoration: none;font-weight: bold;font-size: 14px\">Launch Free Staging Site<\/a>\n<\/div>\n<h2>Frequently Asked Questions<\/h2>\n<div style=\"border-bottom: 1px solid #e2e8f0;padding: 12px 0\">\n<h4 style=\"margin: 0 0 8px 0;color: #1e293b\">Remember to remove the hosts file entry after testing!<\/h4>\n<p style=\"margin: 0;color: #475569;font-size: 14px\">Once you verify the new server and update your domain registrar&#8217;s DNS records, delete the custom IP line from your hosts file so your computer resumes standard DNS resolution.<\/p>\n<\/div>\n<h2>Troubleshooting Hosts File Permissions and Antivirus Locks<\/h2>\n<p>On Windows, third-party antivirus suites (such as Windows Defender, Bitdefender, or Kaspersky) may lock the <code>hosts<\/code> file to prevent malware tampering. If Notepad reports <em>Access Denied<\/em> when saving, temporarily disable host file protection in your security suite or run PowerShell as Administrator to append the test record:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\"># Append test IP in Windows PowerShell (Administrator)\nAdd-Content -Path \"C:\\Windows\\System32\\drivers\\etc\\hosts\" -Value \"`n203.0.113.50 yourdomain.com`n203.0.113.50 www.yourdomain.com\"<\/pre>\n<div style=\"border-bottom: 1px solid #e2e8f0;padding: 12px 0\">\n<h4 style=\"margin: 0 0 8px 0;color: #1e293b\">How do I know if my browser is loading the new server or old server?<\/h4>\n<p style=\"margin: 0;color: #475569;font-size: 14px\">Open Chrome DevTools (F12) &gt; Network tab &gt; click your domain request &gt; look at <strong>Remote Address<\/strong>. It will display the IP address your browser is actively connected to.<\/p>\n<\/div>\n<div style=\"background-color: #f1f5f9;padding: 15px;border-radius: 8px;margin: 20px 0\">\n<h4 style=\"margin-top: 0;color: #1e293b\">Pro Sysadmin Tip: Testing SSL Handshake with OpenSSL CLI<\/h4>\n<p style=\"margin: 0;color: #475569;font-size: 14px\">Run <code>openssl s_client -connect 203.0.113.50:443 -servername yourdomain.com<\/code> to verify TLS cipher suite negotiation and ensure Let&#8217;s Encrypt certificates are valid before public cutover.<\/p>\n<\/div>\n<p>Utilizing local hosts file overrides provides an essential quality assurance safety net, preventing customer-facing downtime and ensuring 100% flawless website migrations.<\/p>\n<p>Testing your migrated website using local hosts file overrides ensures that database connections, SSL certificates, payment gateways, and theme assets are 100% functional before updating public DNS records.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick Answer: To test a migrated website on a new server before changing public DNS records, add your new server IP and domain name to your local computer&#8217;s hosts file (e.g. 203.0.113.50 yourdomain.com www.yourdomain.com). This forces your computer to resolve the domain to the new server while all other global visitors continue browsing the old [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1678,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-1679","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/comments?post=1679"}],"version-history":[{"count":5,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1679\/revisions"}],"predecessor-version":[{"id":1725,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1679\/revisions\/1725"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media\/1678"}],"wp:attachment":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media?parent=1679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/categories?post=1679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/tags?post=1679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}