{"id":7222,"date":"2023-02-05T15:51:11","date_gmt":"2023-02-05T15:51:11","guid":{"rendered":"https:\/\/www.geekdecoder.com\/?p=7222"},"modified":"2023-02-05T15:51:11","modified_gmt":"2023-02-05T15:51:11","slug":"how-to-edit-your-hosts-file-on-mac-to-preview-your-website-before-dns-changes","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2023\/02\/05\/how-to-edit-your-hosts-file-on-mac-to-preview-your-website-before-dns-changes\/","title":{"rendered":"How To Edit Your Hosts File On Mac 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<!--more-->\n\n\n\n<p><strong>How it it done?<\/strong><\/p>\n\n\n\n<p>We often get asked this question a lot as in many cases. Sometimes, 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<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><strong>IP Address<\/strong> \u2013 this is the IP address of the server or computer that you want to map a domain to.<br><strong>Hostname<\/strong> \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? Let\u2019s 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 DNS 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<ul class=\"wp-block-list\">\n<li>It checks to see if the name queried is its own.<\/li>\n\n\n\n<li>It then searches a local Hosts file, a list of IP address and names stored on the local computer.<\/li>\n\n\n\n<li>It then checks the Domain Name System (DNS) servers which are queried.<\/li>\n<\/ul>\n\n\n\n<p><strong>How To Edit Hosts File On Mac<\/strong><br>To edit the hosts file on Mac, you\u2019ll need to be logged in as a user with administrator privileges. You\u2019ll also need the password for your administrator account.<\/p>\n\n\n\n<p><strong>Open the Terminal<\/strong><br>To get started, open the Terminal application. You can find it by clicking on the Finder icon and then going to Applications &gt; Utilities:<\/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_09-42-25.png\"><img loading=\"lazy\" decoding=\"async\" width=\"668\" height=\"379\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_09-42-25.png\" alt=\"\" class=\"wp-image-7224\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_09-42-25.png 668w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_09-42-25-300x170.png 300w\" sizes=\"auto, (max-width: 668px) 100vw, 668px\" \/><\/a><\/figure>\n\n\n\n<p>Now, enter the following command and then press enter:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo nano \/private\/etc\/hosts\n<\/pre><\/div>\n\n\n<p>If prompted, enter your administrator password after running the command.<\/p>\n\n\n\n<p><strong>How to Add New Entries<\/strong><\/p>\n\n\n\n<p>Now, you can add as many entries as needed using the text editor. Just as with other operating systems, use the following format:<\/p>\n\n\n\n<p>IP Address (tab) domain.com (tab) #Comments<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n12.34.56.78      yoursite.com\n<\/pre><\/div>\n\n\n<p>Enter each IP address on its own line. For each IP address, you can add multiple hostnames on the same line.<\/p>\n\n\n\n<p>Here\u2019s an example of what it might look like:<\/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_09-43-54.png\"><img loading=\"lazy\" decoding=\"async\" width=\"727\" height=\"387\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_09-43-54.png\" alt=\"\" class=\"wp-image-7225\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_09-43-54.png 727w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-05_09-43-54-300x160.png 300w\" sizes=\"auto, (max-width: 727px) 100vw, 727px\" \/><\/a><\/figure>\n\n\n\n<p><strong><em>Be sure to replace the above example with your IP and domain name.<\/em><\/strong><\/p>\n\n\n\n<p>Now save the file. You can test with a ping test. Also, you can clear your browser cache and the reload the domain to see the new location. Also, using a private window will usually load the new IP for the domain.<\/p>\n\n\n\n<p>Changing the hosts file is extremally useful for developing new sites and for migrating sites to new servers. Once the migration or changes look good with the new site, you can then change the DNS for the site to the new IP. Be sure to comment out the hosts entry or you can remove it altogether.<\/p>\n\n\n\n<p>Another option is to use the tool at: <a href=\"https:\/\/www.skipdns.link\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.skipdns.link<\/a><\/p>\n\n\n\n<p>I you have any questions, feel free to leave a comment or contact us.<\/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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,60],"tags":[],"class_list":["post-7222","post","type-post","status-publish","format-standard","hentry","category-apple","category-mac"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/7222","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=7222"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/7222\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=7222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=7222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=7222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}