{"id":2219,"date":"2021-06-25T11:17:06","date_gmt":"2021-06-25T08:17:06","guid":{"rendered":"https:\/\/www.scalahosting.com\/kb\/?p=2219"},"modified":"2022-02-07T16:13:24","modified_gmt":"2022-02-07T14:13:24","slug":"how-to-use-the-hosts-file","status":"publish","type":"post","link":"https:\/\/www.scalahosting.com\/kb\/how-to-use-the-hosts-file\/","title":{"rendered":"How to Use the &#8220;Hosts&#8221; File?"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">The <\/span><a href=\"https:\/\/www.scalahosting.com\/kb\/what-is-dns\/\"><b>domain name system (DNS)<\/b><\/a> <span style=\"font-weight: 400;\">is one reason we can browse the internet with ease. It allows people to connect to websites with easy-to-remember domain names instead of their <\/span><b>IP addresses<\/b><span style=\"font-weight: 400;\">\u2014<\/span><i><span style=\"font-weight: 400;\">the unique numeric ID assigned to every website.<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">When you try to <\/span><b>visit a website<\/b><span style=\"font-weight: 400;\">, your browser looks for the DNS information first in your computer DNS cache. If it finds the information, the browser uses the DNS cache to<\/span><b> connect the website<\/b><span style=\"font-weight: 400;\">; otherwise, it looks it up on <\/span><a href=\"https:\/\/www.scalahosting.com\/kb\/what-are-my-nameservers\/\"><b>DNS servers<\/b><\/a><span style=\"font-weight: 400;\"> across the internet.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The DNS client cache\u2019s hosts file helps map hostnames to their specific IP addresses. <\/span><i><span style=\"font-weight: 400;\">What is a hosts file, and how can you use it?<\/span><\/i><\/p>\n<h2><b>What\u2019s a Host File<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">A hosts file is a system files that translates <\/span><b>domain names into IP addresses<\/b><span style=\"font-weight: 400;\">. The local computer and operating system use the hosts file to <\/span><b>map a connection between IP addresses and domain names.&nbsp;<\/b><\/p>\n<p><span style=\"font-weight: 400;\">It contains IP addresses and the domains with space in-between, with each entry sitting on a separate line. <\/span><b>And here\u2019s how the entries look on a host file.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">216.58.223.228<\/span> <span style=\"font-weight: 400;\">google.com<\/span><\/p>\n<p><span style=\"font-weight: 400;\">000.000.000.000<\/span> <span style=\"font-weight: 400;\">thedomain.com<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can add the space between the IP address and the domain name using the <\/span><b>Tab<\/b> <b>key<\/b><span style=\"font-weight: 400;\"> on your keyboard. The hosts file also lets users change the<\/span><b> IP address a domain name resolves to.&nbsp;<\/b><\/p>\n<p><span style=\"font-weight: 400;\">For instance, you could edit your local host file to test whether a transfer to another host is successful before pointing the domain to the new server.&nbsp; <\/span><b>Changes to your host file only apply to your local computer<\/b><span style=\"font-weight: 400;\"> without affecting how the domain resolves worldwide. The hosts file is an <\/span><b>alternative name resolution mechanism<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><b>The Benefits of Using the Hosts File<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">The <\/span><b>hosts file improves users\u2019 browsing experiences by speeding up name resolutions <\/b><span style=\"font-weight: 400;\">and blocking annoying ads. Visiting a website in your hosts file resolves faster than it would if your browser <\/span><b>looks up the IP address on DNS servers<\/b><span style=\"font-weight: 400;\">. A hosts file resolution can save up to 50 percent of the DNS lookup time, helping improve user experience and seamless browsing.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The hosts file also lets you<\/span><b> block ads, malicious websites, and tracking sites by preventing your computer from connecting to them.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">You could do this by listing the domain on the hosts file and giving it the <\/span><i><span style=\"font-weight: 400;\">loopback IP address of 127.0.0.1 for IPv4 network standard or ::1 for IPv6 addressing.<\/span><\/i><\/p>\n<h2><b>Using the Hosts File for the Various Operating Systems<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Let\u2019s quickly examine how to use the hosts file for some of the <\/span><b>top operating systems in use<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h3><b>Windows 8 and 10<\/b><\/h3>\n<p><b>Windows is an operating system (OS) from Microsoft<\/b><span style=\"font-weight: 400;\"> to run personal computers. Take these steps to use the hosts file on a Windows computer. <\/span><b>Open the Windows search and type Notepad into the search bar.<\/b><\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-2220\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image5-6.png\" alt=\"How to Use the &#8220;Hosts&#8221; File?, Windows 8 and 10\" width=\"645\" height=\"601\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image5-6.png 645w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image5-6-300x280.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Click the drop-down arrow under <\/span><b>Open<\/b><span style=\"font-weight: 400;\"> to access a drop-down menu, then select <\/span><b>Run as administrator<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-2225\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image4-10.png\" alt=\"How to Use the &#8220;Hosts&#8221; File?, Windows 8 and 10 2\" width=\"431\" height=\"387\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image4-10.png 431w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image4-10-300x269.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">You could also right-click the app to<\/span><b> run as administrator.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">To open the hosts file on Notepad, click <\/span><b>File<\/b><span style=\"font-weight: 400;\">, then choose <\/span><b>Open<\/b><span style=\"font-weight: 400;\"> &gt; <\/span><b>Windows<\/b><span style=\"font-weight: 400;\"> &gt; <\/span><b>System32<\/b><span style=\"font-weight: 400;\">. Scroll to the <\/span><b>drivers <\/b><span style=\"font-weight: 400;\">folder and open it.<\/span><\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-2221\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image6-8.png\" alt=\"How to Use the &#8220;Hosts&#8221; File?, Windows 8 and 10 3\" width=\"673\" height=\"477\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image6-8.png 673w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image6-8-300x213.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">In the drivers folder, locate and open <\/span><b>etc<\/b><span style=\"font-weight: 400;\">, then <\/span><b>hosts<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-2222\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image1-8.png\" alt=\"How to Use the &#8220;Hosts&#8221; File?, Windows 8 and 10 4\" width=\"674\" height=\"477\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image1-8.png 674w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image1-8-300x212.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">In case you didn\u2019t see the hosts file in the etc folder, which often happens if you\u2019re opening the file for the first time, then switch the file type from \u201c<\/span><b>Text Documents (*.txt<\/b><span style=\"font-weight: 400;\">) to \u201c<\/span><b>All Files<\/b><span style=\"font-weight: 400;\">.\u201d<\/span><\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-2223\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image2-8.png\" alt=\"How to Use the &#8220;Hosts&#8221; File?, Windows 8 and 10 5\" width=\"673\" height=\"476\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image2-8.png 673w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image2-8-300x212.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/p>\n<p><b>Open the hosts file, add your entries below <\/b><span style=\"font-weight: 400;\">the last entry and save the changes.<\/span><\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-2224\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image3-8.png\" alt=\"How to Use the &#8220;Hosts&#8221; File?, Windows 8 and 10 6\" width=\"649\" height=\"523\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image3-8.png 649w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/image3-8-300x242.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Remember to use the <\/span><b>Tab key<\/b><span style=\"font-weight: 400;\"> to space the IP address and the domain name and the <\/span><b>Enter key<\/b><span style=\"font-weight: 400;\"> to begin a new entry.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Click <\/span><b>Files<\/b><span style=\"font-weight: 400;\"> &gt; <\/span><b>Save<\/b><span style=\"font-weight: 400;\"> to apply the changes.<\/span><\/p>\n<h3><b>Linux<\/b><\/h3>\n<p><b>Follow these quick steps to use the hosts file on Linux computers:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Open the Terminal by pressing <\/span><b>CTRL + ALT + T<\/b><span style=\"font-weight: 400;\"> on your keyboard.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Run this <\/span><b>nano<\/b><span style=\"font-weight: 400;\"> command on the command line <\/span><b>sudo nano \/etc\/hosts <\/b><span style=\"font-weight: 400;\">&nbsp;and enter your password when prompted.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Make your entries in the host file; of course, one entry per line.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Save the changes using the <\/span><b>Control<\/b><span style=\"font-weight: 400;\"> and <\/span><b>X<\/b><span style=\"font-weight: 400;\"> key combination.<\/span><\/li>\n<\/ul>\n<h3><b>Mac OS<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Editing the hosts file on <\/span><b>Mac requires the user to have administrator privileges<\/b><span style=\"font-weight: 400;\">. When you log in, take these steps to use the hosts files.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Open Terminal on Mac with the navigation path <\/span><b>Applications<\/b><span style=\"font-weight: 400;\"> &gt; <\/span><b>Utilities<\/b><span style=\"font-weight: 400;\"> &gt; <\/span><b>Terminal<\/b><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Run this command to open the hosts file on your Mac computer <\/span><span style=\"font-weight: 400;\">sudo nano \/<\/span><b>private<\/b><span style=\"font-weight: 400;\">\/etc\/hosts<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Make your desired changes or entries in the file.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use the <\/span><b>Control<\/b><span style=\"font-weight: 400;\"> and <\/span><b>X key <\/b><span style=\"font-weight: 400;\">combination plus <\/span><b>Y<\/b><span style=\"font-weight: 400;\"> and <\/span><b>Enter<\/b><span style=\"font-weight: 400;\"> to save the changes.<\/span><\/li>\n<\/ul>\n<h2><b>Wrapping It Up?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Hosts file helps resolve domain names locally.<\/span><\/p>\n<p><b>You could disable an entry by putting the hashtag sign \u201c#\u201d before the line, for example:&nbsp;<\/b><\/p>\n<p><span style=\"font-weight: 400;\"># <\/span><span style=\"font-weight: 400;\">216.58.223.228<\/span> <span style=\"font-weight: 400;\">google.com.&nbsp;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Adding the hashtag sign makes the hosts file ignore the entry and resolve the name via the <\/span><a href=\"https:\/\/www.scalahosting.com\/kb\/what-is-dns\/\"><b>domain name system (DNS)<\/b><\/a><span style=\"font-weight: 400;\">. Using website address designations like<\/span><i><span style=\"font-weight: 400;\"> \u201c\/\u201d or http:\/\/ also invalidates an entry.<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">If you have questions regarding using the hosts file, reach out to <\/span><a href=\"https:\/\/www.scalahosting.com\/contact-us.html\"><span style=\"font-weight: 400;\">our support<\/span><\/a><span style=\"font-weight: 400;\">. <\/span><b>We\u2019re always available to help.<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The domain name system (DNS) is one reason we can browse the internet with ease. It allows people to connect to websites with easy-to-remember domain names instead of their IP addresses\u2014the unique numeric ID assigned to every website. When you try to visit a website, your browser looks for the DNS information first in your [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","_seopress_robots_follow":"","_seopress_robots_imageindex":"","_seopress_robots_snippet":"","_seopress_robots_primary_cat":"","_seopress_robots_breadcrumbs":"","_seopress_robots_freeze_modified_date":"","_seopress_robots_custom_modified_date":"","_seopress_robots_canonical":"","_seopress_social_fb_title":"","_seopress_social_fb_desc":"","_seopress_social_fb_img":"","_seopress_social_fb_img_attachment_id":0,"_seopress_social_fb_img_width":0,"_seopress_social_fb_img_height":0,"_seopress_social_twitter_title":"","_seopress_social_twitter_desc":"","_seopress_social_twitter_img":"","_seopress_social_twitter_img_attachment_id":0,"_seopress_social_twitter_img_width":0,"_seopress_social_twitter_img_height":0,"_seopress_redirections_value":"","_seopress_redirections_enabled":"","_seopress_redirections_enabled_regex":"","_seopress_redirections_logged_status":"","_seopress_redirections_param":"","_seopress_redirections_type":0,"_seopress_analysis_target_kw":"","_seopress_news_disabled":"","_seopress_video_disabled":"","_seopress_video":[],"_seopress_pro_schemas_manual":[],"_seopress_pro_rich_snippets_disable_all":"","_seopress_pro_rich_snippets_disable":[],"_seopress_pro_schemas":[],"footnotes":""},"categories":[27],"tags":[],"class_list":["post-2219","post","type-post","status-publish","format-standard","hentry","category-vps-hosting"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/2219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/comments?post=2219"}],"version-history":[{"count":7,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/2219\/revisions"}],"predecessor-version":[{"id":3196,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/2219\/revisions\/3196"}],"wp:attachment":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media?parent=2219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/categories?post=2219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/tags?post=2219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}