{"id":198,"date":"2024-05-05T18:51:40","date_gmt":"2024-05-05T18:51:40","guid":{"rendered":"https:\/\/zalvis.com\/docs\/?p=198"},"modified":"2024-06-23T05:30:16","modified_gmt":"2024-06-23T05:30:16","slug":"how-to-edit-your-hosts-file-in-windows-macos-and-linux","status":"publish","type":"post","link":"https:\/\/zalvis.com\/docs\/how-to-edit-your-hosts-file-in-windows-macos-and-linux.html","title":{"rendered":"How To Edit Your Hosts File In Windows, MacOS And Linux"},"content":{"rendered":"<p>Using your computer\u2019s 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 Zalvis server. The most accurate way to preview your site from our platform will be to use your local computer\u2019s hosts file. There are also some free online tool options for beginners if you aren\u2019t feeling comfortable editing your hosts file.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/zalvis.com\/docs\/how-to-edit-your-hosts-file-in-windows-macos-and-linux.html\/#Preparing_To_Preview_Your_Website\" >Preparing To Preview Your Website<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/zalvis.com\/docs\/how-to-edit-your-hosts-file-in-windows-macos-and-linux.html\/#How_To_Edit_Hosts_File_In_Windows\" >How To Edit Hosts File In Windows<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/zalvis.com\/docs\/how-to-edit-your-hosts-file-in-windows-macos-and-linux.html\/#How_To_Edit_Hosts_File_In_Mac_OS\" >How To Edit Hosts File In Mac OS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/zalvis.com\/docs\/how-to-edit-your-hosts-file-in-windows-macos-and-linux.html\/#How_To_Edit_Hosts_File_In_Linux\" >How To Edit Hosts File In Linux<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/zalvis.com\/docs\/how-to-edit-your-hosts-file-in-windows-macos-and-linux.html\/#How_To_Edit_Hosts_File_Using_An_Online_Website_Pre-Viewer\" >How To Edit Hosts File Using An Online Website Pre-Viewer<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/zalvis.com\/docs\/how-to-edit-your-hosts-file-in-windows-macos-and-linux.html\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 id=\"preparing-to-preview-your-website\" class=\"has-anchor-hash\"><span class=\"ez-toc-section\" id=\"Preparing_To_Preview_Your_Website\"><\/span>Preparing To Preview Your Website<span class=\"ez-toc-section-end\"><\/span><\/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. If you are a Zalvis\u00a0customer, the server IP address can be found under the Info section within your Client Area.<\/p>\n<p>Once you have located your server\u2019s 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\"><span class=\"ez-toc-section\" id=\"How_To_Edit_Hosts_File_In_Windows\"><\/span>How To Edit Hosts File In Windows<span class=\"ez-toc-section-end\"><\/span><\/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\u2019s 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\"><span class=\"ez-toc-section\" id=\"How_To_Edit_Hosts_File_In_Mac_OS\"><\/span>How To Edit Hosts File In Mac OS<span class=\"ez-toc-section-end\"><\/span><\/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: \u201cTerminal\u201d. 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\u2019s 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<div class=\"hts-messages hts-messages--info hts-messages--withicon \">\n<p>&nbsp;<\/p>\n<p>Press \u201cControl + X\u201d to exit when you are done modifying the file. Type \u201cY\u201d to save, press \u201cEnter\u201d and quit.<\/p>\n<p>&nbsp;<\/p>\n<\/div>\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\"><span class=\"ez-toc-section\" id=\"How_To_Edit_Hosts_File_In_Linux\"><\/span>How To Edit Hosts File In Linux<span class=\"ez-toc-section-end\"><\/span><\/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\u2019s 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<div class=\"hts-messages hts-messages--info hts-messages--withicon \">\n<p>&nbsp;<\/p>\n<p><em><span class=\"screenshot_callout\">nano tip:<\/span><\/em><\/p>\n<p>Press \u201cControl + X\u201d to exit when you are done modifying the file. Type \u201cY\u201d to save, press \u201cEnter\u201d and quit.<\/p>\n<p>&nbsp;<\/p>\n<\/div>\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\"><span class=\"ez-toc-section\" id=\"How_To_Edit_Hosts_File_Using_An_Online_Website_Pre-Viewer\"><\/span>How To Edit Hosts File Using An Online Website Pre-Viewer<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"hts-messages hts-messages--alert \">\n<p>Please 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.<\/p>\n<\/div>\n<ol>\n<li>Access <a href=\"https:\/\/www.skipdns.link\/\" target=\"_blank\" rel=\"nofollow noopener\">skipdns.link<\/a> <em>(or <\/em><a href=\"https:\/\/hosts.cx\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\"><em>hosts.cx)<\/em><\/a> into 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<div class=\"hts-messages hts-messages--info hts-messages--withicon \">\n<p>The server needs to be specified as the IP address. If you are a Zalvis customer \u2013 you can find your server\u2019s IP address in the Hosting account setup email we\u2019ve sent you at the sign-up, under \u201c<em>FTP Information<\/em>\u201d section. You can also find it in your cPanel\u2019s dashboard &gt; <em>General Information<\/em> &gt; <em>Shared IP Address<\/em>.<\/p>\n<\/div>\n<h2 id=\"conclusion\" class=\"anchor\" aria-hidden=\"true\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/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\u2019t hesitate to get in touch with our support team by live chat or by creating a support ticket.<\/p>\n<div class=\"yovzr69e76c2ab1875\" >If you enjoyed this article, then you\u2019ll love Zalvis's Cloud Hosting platform. Turbocharge your website and get 24\/7 support from our veteran team. Our world-class hosting infrastructure focuses on auto-scaling, performance, and security. Let us show you the Zalvis difference! <a href=\"https:\/\/zalvis.com\/\">Check out our services.<\/a><\/div><style type=\"text\/css\">\r\n@media screen and (min-width: 1201px) {\r\n.yovzr69e76c2ab1875 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 993px) and (max-width: 1200px) {\r\n.yovzr69e76c2ab1875 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 769px) and (max-width: 992px) {\r\n.yovzr69e76c2ab1875 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 768px) and (max-width: 768px) {\r\n.yovzr69e76c2ab1875 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (max-width: 767px) {\r\n.yovzr69e76c2ab1875 {\r\ndisplay: block;\r\n}\r\n}\r\n<\/style>\r\n","protected":false},"excerpt":{"rendered":"<p>Using your computer\u2019s 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-198","post","type-post","status-publish","format-standard","hentry","category-server-setup"],"_links":{"self":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts\/198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/comments?post=198"}],"version-history":[{"count":3,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts\/198\/revisions"}],"predecessor-version":[{"id":511,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts\/198\/revisions\/511"}],"wp:attachment":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/media?parent=198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/categories?post=198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/tags?post=198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}