{"id":4546,"date":"2019-11-27T21:02:04","date_gmt":"2019-11-28T02:02:04","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=4546"},"modified":"2019-11-27T21:02:05","modified_gmt":"2019-11-28T02:02:05","slug":"how-hosts-file-works","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/","title":{"rendered":"How hosts file works"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/HostFiles-StepByStep.jpg\" alt=\"\" class=\"wp-image-4548\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><br>What should you understand to start?<\/h2>\n\n\n\n<p>In this tutorial, we will explain how hosts file works on your local computer, for users running Linux, Windows or MacOS and how to modify it.<\/p>\n\n\n\n<p>The way how hosts file works is a very simple. The hosts file is simple and small, but very useful file located in your local computer that can be used to map hostnames to IP addresses. The information entered into the hosts file will by-pass the public DNS server response.  It is very useful for developers to test their application, when the application can not resolve an IP via DNS or must resolve to a different IP than the public DNS IP. They don&#8217;t need to buy separate Domain to test the application. They just need to add a static entry in hosts file to allow the application to access with the hostname. Host file allows you to manually point a website address to a specific IP address. Using host file you can override DNS servers and control access to websites and network traffic.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hosts file on Linux<\/h2>\n\n\n\n<p>You can  modify the hosts file in Linux-based operating system with the following steps :<\/p>\n\n\n\n<p>1. Open a new terminal window.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"361\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/Linux-Open-Terminal.png\" alt=\"\" class=\"wp-image-4551\"\/><figcaption>Open Terminal<\/figcaption><\/figure>\n\n\n\n<p><br>2.  Use your favorite text editor to open the hosts file, located into \/etc\/hosts.<\/p>\n\n\n\n<p><code> sudo nano \/etc\/hosts <\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"407\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/Linux-Open-Hosts-File.png\" alt=\"\" class=\"wp-image-4552\"\/><\/figure>\n\n\n\n<p><br>3.  Add your DNS entry into at the end of the hosts file. The syntaxe must be as following: IP address host1 host2.<\/p>\n\n\n\n<p><code> 192.168.0.100&nbsp;yourdomain.com www.yourdomain.com <\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"410\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/Linux-Modify-Hosts-File.png\" alt=\"\" class=\"wp-image-4553\"\/><\/figure>\n\n\n\n<p><br>4.  Save and close the file, when you are finished.<\/p>\n\n\n\n<p>You can now test the name resolution with the following command:<\/p>\n\n\n\n<p><code> ping yourdomain.com <\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"203\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/Linux-Test-Hosts.png\" alt=\"\" class=\"wp-image-4554\"\/><\/figure>\n\n\n\n<p><br>You can also test the name resolution with the web browser. Open your web browser and type the URL\u00a0http:\/\/yourdomain.com. You will be redirected to the website hosted on the server with IP 192.168.0.100.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><br>Modify Hosts File in Windows 10<\/h2>\n\n\n\n<p>You can modify the hosts file in Windows 10 operating system with the following steps:<\/p>\n\n\n\n<p>1.  Press the windows key or click the &#8220;Start&#8221; button and then type &#8220;notepad&#8221; in the search bar.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"633\" height=\"514\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/Windows-Start-Notepad.png\" alt=\"\" class=\"wp-image-4559\"\/><\/figure>\n\n\n\n<p><br>3. Right click on <strong>Notepad <\/strong>and select <strong>Run as administrator<\/strong>. This will open Notepad application with administrator rights.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"630\" height=\"516\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/Windows-Start-Notepad-as-Administrator.png\" alt=\"\" class=\"wp-image-4560\"\/><\/figure>\n\n\n\n<p><br>4. From Notepad, click on the File menu and then click Open. Browse into X:\\Windows\\System32\\Drivers\\etc\\hosts, and then selection &#8220;All files (*.*). Then click on file named &#8220;hosts&#8221; and click Open.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"954\" height=\"495\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/Windows-Open-Hosts-File.png\" alt=\"\" class=\"wp-image-4561\"\/><\/figure>\n\n\n\n<p><br>5.  Add your DNS entry into at the end of the hosts file. The syntaxe must be as following: IP address host1 host2<\/p>\n\n\n\n<p><code> 192.168.0.100\u00a0yourdomain.com www.yourdomain.com <\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"954\" height=\"493\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/Windows-Edit-Hosts-File.png\" alt=\"\" class=\"wp-image-4562\"\/><\/figure>\n\n\n\n<p><br>6.  Save and close the file.<\/p>\n\n\n\n<p>7. Open\u00a0yourdomain.com\u00a0through the web browser.  The host should now resolve the IP that been entered into the hosts file.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"385\" src=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/Windows-Ping-Host.png\" alt=\"\" class=\"wp-image-4563\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><br>Modify Hosts File in MacOS<\/h2>\n\n\n\n<p>Into MacOS, you can create the hosts file using the following steps:<\/p>\n\n\n\n<p>1.  Open your terminal from Applications -&gt; Utilities -&gt; Terminal<\/p>\n\n\n\n<p>2.  Use your favorite text editor to open the hosts file, located into \/private\/etc\/hosts:<\/p>\n\n\n\n<p><code> sudo nano  \/private\/etc\/hosts <\/code><\/p>\n\n\n\n<p>3. You will need to provide your user&#8217;s password. Then, add the following line at the end of the file:<\/p>\n\n\n\n<p><code> 192.168.0.100&nbsp;yourdomain.com www.yourdomain.com <\/code><\/p>\n\n\n\n<p>4. Save and close the file, when you are finished.<\/p>\n\n\n\n<p>Open\u00a0yourdomain.com\u00a0through the web browser.  The host should now resolve the IP that been entered into the hosts file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"NEEDREVIEWS-Usingthehostsfile-Stepbystep-Conclusion\"><br>Conclusion<\/h2>\n\n\n\n<p>I hope you have now enough knowledge to setup hosts file for name resolution. You can now test your website without purchasing domain name using the hosts file.<br><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Learn how the hosts file works and how to modify it on your local computer. Modifying your local hosts file allow you you to resolve a host to a custom IP.<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[136,135,134,124,138,137],"class_list":["post-4546","post","type-post","status-publish","format-standard","hentry","category-web-hosting","tag-developper","tag-dns","tag-hosts-file","tag-linux","tag-macos","tag-windows"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How hosts file works - Globo.Tech<\/title>\n<meta name=\"description\" content=\"Learn how the hosts file works and how to modify it on your local computer. Modifying your local hosts file allow you you to resolve a host to a custom IP.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How hosts file works - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"Learn how the hosts file works and how to modify it on your local computer. Modifying your local hosts file allow you you to resolve a host to a custom IP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-28T02:02:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-11-28T02:02:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/HostFiles-StepByStep.jpg\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/\",\"name\":\"How hosts file works - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/HostFiles-StepByStep.jpg\",\"datePublished\":\"2019-11-28T02:02:04+00:00\",\"dateModified\":\"2019-11-28T02:02:05+00:00\",\"author\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"Learn how the hosts file works and how to modify it on your local computer. Modifying your local hosts file allow you you to resolve a host to a custom IP.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/#primaryimage\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/HostFiles-StepByStep.jpg\",\"contentUrl\":\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/HostFiles-StepByStep.jpg\",\"width\":1200,\"height\":628},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.globo.tech\/learning-center\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How hosts file works\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\/\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How hosts file works - Globo.Tech","description":"Learn how the hosts file works and how to modify it on your local computer. Modifying your local hosts file allow you you to resolve a host to a custom IP.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/","og_locale":"en_US","og_type":"article","og_title":"How hosts file works - Globo.Tech","og_description":"Learn how the hosts file works and how to modify it on your local computer. Modifying your local hosts file allow you you to resolve a host to a custom IP.","og_url":"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/","og_site_name":"Globo.Tech","article_published_time":"2019-11-28T02:02:04+00:00","article_modified_time":"2019-11-28T02:02:05+00:00","og_image":[{"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/HostFiles-StepByStep.jpg","type":"","width":"","height":""}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/","url":"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/","name":"How hosts file works - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/#primaryimage"},"image":{"@id":"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/#primaryimage"},"thumbnailUrl":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/HostFiles-StepByStep.jpg","datePublished":"2019-11-28T02:02:04+00:00","dateModified":"2019-11-28T02:02:05+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"Learn how the hosts file works and how to modify it on your local computer. Modifying your local hosts file allow you you to resolve a host to a custom IP.","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/#primaryimage","url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/HostFiles-StepByStep.jpg","contentUrl":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2019\/11\/HostFiles-StepByStep.jpg","width":1200,"height":628},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/how-hosts-file-works\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How hosts file works"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/4546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=4546"}],"version-history":[{"count":14,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/4546\/revisions"}],"predecessor-version":[{"id":4570,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/4546\/revisions\/4570"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=4546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=4546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=4546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}