{"id":7205,"date":"2023-02-03T22:45:59","date_gmt":"2023-02-03T22:45:59","guid":{"rendered":"https:\/\/www.geekdecoder.com\/?p=7205"},"modified":"2023-02-03T22:45:59","modified_gmt":"2023-02-03T22:45:59","slug":"how-to-edit-your-hosts-file-to-preview-your-website-before-dns-changes","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2023\/02\/03\/how-to-edit-your-hosts-file-to-preview-your-website-before-dns-changes\/","title":{"rendered":"How to Edit Your Hosts File on Windows to Preview Your Website Before DNS Changes"},"content":{"rendered":"\n<p>If you ever set up a new domain hosting or migrate a domain to a new server, you will want to check to make sure that the changes are good before changing the DNS to the new server. <\/p>\n\n\n\n<p>We often get asked this question a lot as in many cases, clients change the DNS before checking to see if there site actually works. This can lead to frustration, downtime and lost revenue and customers.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>With the information in this article, we will outline how to map a domain name to the local hosts file, thus overriding temporarily the DNS record for a domain.<\/p>\n\n\n\n<p><strong>How The hosts File Works<\/strong><\/p>\n\n\n\n<p>All operation systems come with a hosts file. The default hosts file is quite simple. It\u2019s comprised of two things:<\/p>\n\n\n\n<p>IP Address \u2013 this is the IP address of the server or computer that you want to map a domain to.<br>Hostname \u2013 usually, this is the domain name that you want to map to the associated IP address.<\/p>\n\n\n\n<p>Whys does changing the hosts file work?<\/p>\n\n\n\n<p>Let&#8217;s take a look.<\/p>\n\n\n\n<p>Imagine a long time ago in the networking world. There are no DNS servers. So hosts files were used on early computer networks for name resolution before&nbsp;<strong>DNS<\/strong>&nbsp;was developed.<\/p>\n\n\n\n<p>So  when you ping or load a website, you computer does something interesting:<\/p>\n\n\n\n<p>It checks to see if the name queried is its own.<\/p>\n\n\n\n<p>It then searches a local Hosts file, a list of IP address and names stored on the local computer.<\/p>\n\n\n\n<p>It then checks the Domain Name System (DNS) servers which are queried.<\/p>\n\n\n\n<p><strong>How to Edit the Hosts File<\/strong><\/p>\n\n\n\n<p>Windows<\/p>\n\n\n\n<p>On a Windows System, the Hosts file is located at the following location:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nC:\\Windows\\System32\\drivers\\etc\\hosts\n<\/pre><\/div>\n\n\n<p>To edit the file, you will need to open it as Administrator. Find Notepad, and then right click to open as administrator. You will get a message to allow notepad to make changes to your system. Then click File &gt; Open &gt; C:\\Windows\\System32\\drivers\\etc\\hosts (you can paste it into the navigation bar to go directly there).<\/p>\n\n\n\n<p>Here is the default File:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_08-53-41.png\"><img loading=\"lazy\" decoding=\"async\" width=\"628\" height=\"391\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_08-53-41.png\" alt=\"\" class=\"wp-image-7218\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_08-53-41.png 628w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_08-53-41-300x187.png 300w\" sizes=\"auto, (max-width: 628px) 100vw, 628px\" \/><\/a><figcaption class=\"wp-element-caption\">C:\\Windows\\System32\\drivers\\etc\\hosts<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><\/li>\n<\/ul>\n\n\n\n<p>To add a domain, use the following format:<\/p>\n\n\n\n<p>IP Address \u2013 this is the IP address of the server that you want to map a domain to.<br>Domain \u2013 usually, this is the domain name that you want to map to the associated IP address.<br>Comments &#8211; Notes or a descriptor of the entry.<\/p>\n\n\n\n<p>Here is the Hosts file with a new entry.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_08-57-54.png\"><img loading=\"lazy\" decoding=\"async\" width=\"616\" height=\"501\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_08-57-54.png\" alt=\"\" class=\"wp-image-7219\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_08-57-54.png 616w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_08-57-54-300x244.png 300w\" sizes=\"auto, (max-width: 616px) 100vw, 616px\" \/><\/a><\/figure>\n\n\n\n<p>Note: when adding the entry&#8217;s, just hit tab between the entry&#8217;s to give them space.<\/p>\n\n\n\n<p>After the change, save the changes. <\/p>\n\n\n\n<p>You can test with a ping. Open your Command Prompt &gt; Start &gt; Type in cmd . Click on Command Prompt.<\/p>\n\n\n\n<p>Type in ping domain.com ( replace your domain name here&#8230;)<\/p>\n\n\n\n<p>Results.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nc:\\&gt;ping domain.com\nPinging domain.com &#x5B;192.168.0.55] with 32 bytes of data:\nReply from 192.168.0.55: bytes=32 time=66ms TTL=50\nReply from 192.168.0.55: bytes=32 time=73ms TTL=50\nReply from 192.168.0.55: bytes=32 time=68ms TTL=50\nReply from 192.168.0.55: bytes=32 time=71ms TTL=50\n\nPing statistics for 192.168.0.55:\n    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),\nApproximate round trip times in milli-seconds:\n    Minimum = 66ms, Maximum = 73ms, Average = 69ms\n<\/pre><\/div>\n\n\n<p>Now you can load the website in a browser to pint to the new IP Address. <\/p>\n\n\n\n<p>Note: Be sure to clear your browser cache so that the old domain location is not cached.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>NOTE:<\/p>\n\n\n\n<p>Firefox now uses DNS over HTTPS (or DOH) by default. That means instead of checking your local hosts file or even your DNS resolver. Firefox simply makes the DNS request over HTTPS from within the browser. This behavior guarantees that the website displayed points to the IP address that the Internet sees as authoritative for that domain. There are two primary ways to avoid this behavior while testing your new site. First, use a different browser. Chrome, Edge, Safari, and many others do not have this setting enabled by default and will continue to work as expected with a modified hosts file. The second method is to disable DOH in your Firefox browser. Follow the directions below to disable this setting. 1. Open your Firefox browser. 2. Click the menu button and select Options. 3. In the General panel, scroll down to Network Settings and click the Settings button. 4. In the dialog box that opens, scroll down to Enable DNS over HTTPS. 5. Uncheck the box beside Enable DNS over HTTPS. 6. Click OK to save your changes and close the window. You can now edit your Hosts File and proceed with testing your new site like you normally would. We do recommend re-enabling this feature as it keeps you safer while browsing.<\/p>\n<\/blockquote>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you ever set up a new domain hosting or migrate a domain to a new server, you will want to check to make sure that the changes are good before changing the DNS to the new server. We often get asked this question a lot as in many cases, clients change the DNS before &#8230; <a title=\"How to Edit Your Hosts File on Windows to Preview Your Website Before DNS Changes\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2023\/02\/03\/how-to-edit-your-hosts-file-to-preview-your-website-before-dns-changes\/\" aria-label=\"Read more about How to Edit Your Hosts File on Windows to Preview Your Website Before DNS Changes\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,56,60,126],"tags":[],"class_list":["post-7205","post","type-post","status-publish","format-standard","hentry","category-dns","category-kb","category-mac","category-windows-desktop"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/7205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=7205"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/7205\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=7205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=7205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=7205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}