{"id":673,"date":"2017-04-04T09:52:59","date_gmt":"2017-04-04T09:52:59","guid":{"rendered":"https:\/\/chemicloud.com\/kb\/?post_type=article&#038;p=673"},"modified":"2024-10-25T11:51:43","modified_gmt":"2024-10-25T11:51:43","slug":"edit-hosts-file","status":"publish","type":"ht_kb","link":"https:\/\/chemicloud.com\/kb\/article\/edit-hosts-file\/","title":{"rendered":"How to Edit your Hosts File in Windows, MacOS and Linux"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>Using your computer&#8217;s hosts file will allow your computer to override the results of a typical DNS query and instruct your computer to always load your website from a specific server or IP address. This can come in handy after migrations as you might want to test how your website works on a different server before changing the DNS or in case the DNS hasn\u2019t propagated yet.<\/p>\n<p>There are a few different ways to preview your site before switching the DNS to your ChemiCloud server. The most accurate way to preview your site from our platform will be to use your local computer&#8217;s hosts file. There are also some free online tool options for beginners if you aren\u2019t feeling comfortable editing your hosts file.<\/p>\n<h2 id=\"preparing-to-preview-your-website\" class=\"has-anchor-hash\">Preparing to Preview Your Website<\/h2>\n<p>For you to be able to preview a website from a specific server you will need to know the <strong>IP address<\/strong> that is assigned to the server hosting your website.<\/p>\n<p>Once you have located your server&#8217;s IP address, you can use the following instructions to preview your website before changing your DNS using your computers hosts file.<\/p>\n<h2 id=\"how-to-edit-hosts-file-in-windows\" class=\"has-anchor-hash\">How to Edit Hosts File in Windows<\/h2>\n<p id=\"windows-10-and-windows-8\"><strong>Windows 10 and Windows 8<\/strong><\/p>\n<ol>\n<li>Press the\u00a0<strong>Windows<\/strong>\u00a0key.<\/li>\n<li>Type\u00a0<strong>Notepad<\/strong>\u00a0in the search field.<\/li>\n<li>In the search results, right-click\u00a0<strong>Notepad<\/strong>\u00a0and select\u00a0<strong>Run as administrator<\/strong>.<\/li>\n<li>From Notepad, open the following file:<strong>c:\\Windows\\System32\\Drivers\\etc\\hosts<\/strong><\/li>\n<\/ol>\n<p>When the file opens, you will see two columns of information, the first column contains IP addresses and the second contains hostnames. By default, a Windows hosts file should be similar to the following:<\/p>\n<div class=\"code\">\n<p>Filename: <span class=\"screenshot_callout\">hosts<\/span><\/p>\n<pre>127.0.0.1 localhost<\/pre>\n<\/div>\n<p>You can add additional lines to this file that will point requests for a particular domain to your new server&#8217;s IP address. Example:<\/p>\n<div class=\"code\">\n<p>Filename: <span class=\"screenshot_callout\">hosts<\/span><\/p>\n<pre>127.0.0.1 localhost\r\n70.32.88.203 example.com\r\n70.32.88.203 www.example.com<\/pre>\n<\/div>\n<p>6. Select <strong>File &gt; Save<\/strong>\u00a0to save your changes.<\/p>\n<p>7. You will need to close and reopen any pages you had open in your browser.<\/p>\n<p>8. Open your browser and visit your new site.<\/p>\n<h2 id=\"how-to-edit-hosts-file-in-mac-os\" class=\"has-anchor-hash\">How to Edit Hosts File in Mac OS<\/h2>\n<p>In macOS, the hosts file is located at:\u00a0<code>\/etc\/hosts<\/code>. The instructions below are valid for all macOS versions.<\/p>\n<p>Use Command + Space and enter: &#8220;Terminal&#8221;. In your terminal window, open the hosts file using your favorite text editor, like nano or vi. We are using nano, below:<\/p>\n<pre>sudo nano \/etc\/hosts<\/pre>\n<p>When prompted enter your administrative password.<\/p>\n<p>Scroll down to the end of the file and add your new entries. Add your domain and the server&#8217;s IP address to the bottom of the file. For example:<\/p>\n<div class=\"code\">\n<pre>##\r\n# Host Database\r\n#\r\n# localhost is used to configure the loopback interface\r\n# when the system is booting. Do not change this entry.\r\n##\r\n70.32.88.203 domain.com www.domain.com\r\n70.32.88.203 otherdomain.com www.otherdomain.com\r\n<\/pre>\n<\/div>\n<div class=\"tip\">\n    \t\t<div class=\"hts-messages hts-messages--info   hts-messages--withicon \"   >\r\n    \t\t\t    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\t\n<p>Press &#8220;Control + X&#8221; to exit when you are done modifying the file. Type &#8220;Y&#8221; to save, press &#8220;Enter&#8221; and quit.<\/p>\n    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n<\/div>\n<ol>\n<li>Save the changes and flush the DNS cache:\n<pre><code class=\"code-blank\">dscacheutil -flushcache<\/code><\/pre>\n<\/li>\n<li>Visit your new site.<\/li>\n<\/ol>\n<h2 id=\"how-to-edit-hosts-file-in-linux\" class=\"has-anchor-hash\">How to Edit Hosts File in Linux<\/h2>\n<p>In Linux, the hosts file is located at:\u00a0<code>\/etc\/hosts<\/code>. The instructions below are valid for Linux distribution, including Ubuntu, CentOS, RHEL, Debian and Linux Mint.<\/p>\n<p>In your terminal window, open the hosts file using your favorite text editor, such as nano or vi. We are using nano below:<\/p>\n<div class=\"highlight\">\n<pre class=\"chroma console-bash\"><code class=\"language-console-bash\" data-lang=\"console-bash\"><span class=\"line\">sudo nano \/etc\/hosts<\/span><\/code><\/pre>\n<\/div>\n<p>When prompted enter your sudo password.<\/p>\n<p>Scroll down to the end of the file and add your new entries. Add your domain and the server&#8217;s IP address to the bottom of the file. For example:<\/p>\n<div class=\"code\">\n<pre>##\r\n# Host Database\r\n#\r\n# localhost is used to configure the loopback interface\r\n# when the system is booting. Do not change this entry.\r\n##\r\n70.32.88.203 domain.com www.domain.com\r\n70.32.88.203 otherdomain.com www.otherdomain.com<\/pre>\n<\/div>\n<div class=\"tip\">\n    \t\t<div class=\"hts-messages hts-messages--info   hts-messages--withicon \"   >\r\n    \t\t\t    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\t\n<p><em><span class=\"screenshot_callout\">nano tip:<\/span><\/em><\/p>\n<p>Press &#8220;Control + X&#8221; to exit when you are done modifying the file. Type &#8220;Y&#8221; to save, press &#8220;Enter&#8221; and quit.<\/p>\n    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n<\/div>\n<p>Save the changes and visit your new site.<\/p>\n<h2 id=\"how-to-edit-hosts-file-using-an-online-website-pre-viewer\" class=\"has-anchor-hash\">How to Edit Hosts File Using an Online Website Pre-Viewer<\/h2>\n    \t\t<div class=\"hts-messages hts-messages--alert    \"   >\r\n    \t\t\t    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\tPlease note that while using hosts with an online tool, it may not be that accurate as while using your local computer hosts file. Also, online website pre-viewer tools have limited capabilities.    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n<ol>\n<li>Access <a href=\"https:\/\/www.skipdns.link\/\" target=\"_blank\" rel=\"nofollow noopener\">skipdns.link<\/a>\u00a0into your browser.<\/li>\n<li>\n<p class=\"sub-title\">Please enter your server IP address and the domain name which should be requested.<\/p>\n<\/li>\n<\/ol>\n<p class=\"sub-title\">    \t\t<div class=\"hts-messages hts-messages--info   hts-messages--withicon \"   >\r\n    \t\t\t    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\tThe server needs to be specified as the IP address.    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n<h2 id=\"conclusion\" class=\"anchor\" aria-hidden=\"true\">Conclusion<\/h2>\n<p>By now you should have a great understanding of how the hosts file works and how to make modifications to the file. If you want to undo the changes, simply open the file and remove the lines you added.<\/p>\n<p>If you are experiencing any difficulties while using hosts file, please don&#8217;t hesitate to get in touch with our support team by live chat or by creating a support ticket.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Using your computer&#8217;s hosts file will allow your computer to override the results of a typical DNS query and instruct your computer to always load your website from a specific server or IP address. This can come in handy after migrations as you might want to test how your&#8230;<\/p>\n","protected":false},"author":10,"featured_media":2823,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"ht-kb-category":[188],"ht-kb-tag":[209],"class_list":["post-673","ht_kb","type-ht_kb","status-publish","format-standard","has-post-thumbnail","hentry","ht_kb_category-support-resources","ht_kb_tag-test-website"],"_links":{"self":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/comments?post=673"}],"version-history":[{"count":28,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/673\/revisions"}],"predecessor-version":[{"id":8538,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/673\/revisions\/8538"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/media\/2823"}],"wp:attachment":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/media?parent=673"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=673"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}