{"id":4061,"date":"2020-03-06T13:28:33","date_gmt":"2020-03-06T13:28:33","guid":{"rendered":"https:\/\/lamp.ciscoar.com\/?page_id=4061"},"modified":"2020-03-08T18:51:33","modified_gmt":"2020-03-08T18:51:33","slug":"windows-hosts-file-vs-dns","status":"publish","type":"page","link":"https:\/\/lamp.ciscoar.com\/?page_id=4061","title":{"rendered":"Windows hosts file vs DNS"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">DNS vs the Windows hosts file<\/h2>\n\n\n\n<p>We&#8217;ve been working on a local LAB environment, you probably know that even in this kind of scenarios we can emulate the service provided by a DNS just adding entries for each of your <strong>local domain names<\/strong> (domains that are not valid outside your LAB) into the file called &#8220;hosts&#8221; located at the following folder on a Windows machine.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"vim\" class=\"language-vim\">C:\\Windows\\System32\\drivers\\etc<\/code><\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/path-to-hosts-file-on-windows.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"328\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/path-to-hosts-file-on-windows.jpg\" alt=\"\" class=\"wp-image-4064\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/path-to-hosts-file-on-windows.jpg 693w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/path-to-hosts-file-on-windows-300x142.jpg 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/a><figcaption>Path to &#8220;hosts&#8221; file on Windows <\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Opening Notepad as an Administrator<\/h2>\n\n\n\n<p>The &#8220;hosts&#8221; file is a system file and as such it can only be modified by a user with Administrative rights, since we&#8217;re going to use Notepad to open the &#8220;hosts&#8221; file, then you must open Notepad as the Administrator user, see image below.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/Windows-no-DNS-hosts-file-01.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"455\" height=\"287\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/Windows-no-DNS-hosts-file-01.jpg\" alt=\"\" class=\"wp-image-4067\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/Windows-no-DNS-hosts-file-01.jpg 455w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/Windows-no-DNS-hosts-file-01-300x189.jpg 300w\" sizes=\"auto, (max-width: 455px) 100vw, 455px\" \/><\/a><figcaption>Opening Notepad as Administrator<\/figcaption><\/figure><\/div>\n\n\n\n<p>Notepad will be open empty, now you can open the &#8220;hosts&#8221; file and rest assured that you&#8217;ll be able to save all the changes done.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/notepad-was-open-as-admin.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"664\" height=\"371\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/notepad-was-open-as-admin.jpg\" alt=\"\" class=\"wp-image-4070\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/notepad-was-open-as-admin.jpg 664w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/notepad-was-open-as-admin-300x168.jpg 300w\" sizes=\"auto, (max-width: 664px) 100vw, 664px\" \/><\/a><figcaption>Notepad is being executed by the Administrator<\/figcaption><\/figure><\/div>\n\n\n\n<p>Browse the file system of your Windows machine to reach the folder &#8220;C:\\Windows\\System32\\drivers\\etc&#8221; then switch from <strong>Text Documents<\/strong> to <strong>All Files<\/strong> to be able to see the &#8220;hosts&#8221; file.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/switch-txt-to-all-files.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"805\" height=\"322\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/switch-txt-to-all-files.jpg\" alt=\"\" class=\"wp-image-4072\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/switch-txt-to-all-files.jpg 805w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/switch-txt-to-all-files-300x120.jpg 300w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/switch-txt-to-all-files-768x307.jpg 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Maping Local Domain to Local IP Address<\/h2>\n\n\n\n<p>In order to be able to &#8220;emulate&#8221; one DNS you can add pairs of Local Domain Names and the Localhost IP Address, see image below.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/mapping-local-domain-with-localhost-ip-address-02.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"576\" height=\"219\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/mapping-local-domain-with-localhost-ip-address-02.jpg\" alt=\"\" class=\"wp-image-4075\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/mapping-local-domain-with-localhost-ip-address-02.jpg 576w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/03\/mapping-local-domain-with-localhost-ip-address-02-300x114.jpg 300w\" sizes=\"auto, (max-width: 576px) 100vw, 576px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>As you can see in the image above, just as an example, we do have 2(two) Virtual Machines running on <a rel=\"noreferrer noopener\" aria-label=\"Oracle Virtual Box (opens in a new tab)\" href=\"\/virtual-box\/\" target=\"_blank\">Oracle Virtual Box<\/a>, their ip addresses are different both VM&#8217;s are hosting multiple websites taking advantage of the great Apache&#8217;s feature that allow us to run <a rel=\"noreferrer noopener\" aria-label=\"Virtual Hosts (opens in a new tab)\" href=\"\/add-an-apaches-virtual-host\/#What_is_an_Apaches_Virtual_Host\" target=\"_blank\">Virtual Hosts<\/a>.<\/p>\n\n\n\n<p>Once you&#8217;ve saved the changes and only if the counter part configuration was done on the Apache&#8217;s side, that is a Virtual Host was properly configured, then you&#8217;ll be able to go to your website using its local domain name.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Not a real DNS but a useful trick<\/h2>\n\n\n\n<p>You must be aware that this kind of configuration is only good for a LAB, this is not by any means equivalent to a real DNS, we&#8217;re going to cover the building of a real DNS running on a <a href=\"\/creating-a-new-virtual-machine\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Linux CentOS VM (opens in a new tab)\">Linux CentOS VM<\/a> in further article, stay tuned.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DNS vs the Windows hosts file We&#8217;ve been working on a local LAB environment, you probably know that even in this kind of scenarios we can emulate the service provided by a DNS just adding entries for each of your local domain names (domains that are not valid outside your LAB) into the file called &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/lamp.ciscoar.com\/?page_id=4061\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Windows hosts file vs DNS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-4061","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/pages\/4061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4061"}],"version-history":[{"count":20,"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/pages\/4061\/revisions"}],"predecessor-version":[{"id":4120,"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/pages\/4061\/revisions\/4120"}],"wp:attachment":[{"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}