{"componentChunkName":"component---src-pages-markdown-remark-fields-slug-js","path":"/engineering/hosts-file/","result":{"data":{"markdownRemark":{"id":"ceb2a4e9-a19e-53ca-9623-5425dfcaeab2","excerpt":"What is the “hosts” file A hosts file which is used by operating systems to map a connection between an IP address and domain names before going to domain name…","html":"<h2 id=\"what-is-the-hosts-file\" style=\"position:relative;\"><a href=\"#what-is-the-hosts-file\" aria-label=\"what is the hosts file permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is the “hosts” file</h2>\n<p>A hosts file which is used by operating systems to map a connection between an IP address and domain names before going to domain name servers. This file is a simple text file with the mapping of IPs and domain names.</p>\n<h3 id=\"lets-talk-about-the-usage-of-the-hosts-file\" style=\"position:relative;\"><a href=\"#lets-talk-about-the-usage-of-the-hosts-file\" aria-label=\"lets talk about the usage of the hosts file permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Let’s talk about the usage of the hosts file</h3>\n<h5 id=\"protecting-privacy\" style=\"position:relative;\"><a href=\"#protecting-privacy\" aria-label=\"protecting privacy permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Protecting Privacy</h5>\n<p>You can use this to block advertisers, trackers, block marketing, or third party websites, block ads, banners, 3rd party page counters, or sites to protect your privacy. </p>\n<h5 id=\"block-website-for-your-kids\" style=\"position:relative;\"><a href=\"#block-website-for-your-kids\" aria-label=\"block website for your kids permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Block website for your kids</h5>\n<p>If you don’t want your children to open some websites you can block them by the hosts file. You can decide entirely what you wish to block and even most hijackers and possibly unwanted programs. </p>\n<h5 id=\"security\" style=\"position:relative;\"><a href=\"#security\" aria-label=\"security permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Security</h5>\n<p>We can utilize it as a firewall in our local system. The hosts file is to block Spyware and/or ad Networks you can add all the Spyware sites &#x26; ad Networks domain names in your hosts file also you can block dangerous sites, ransomware sites, blockchain sites. </p>\n<h5 id=\"development\" style=\"position:relative;\"><a href=\"#development\" aria-label=\"development permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Development</h5>\n<p>You know during the development, you need to run your web application on the localhost for verification. Websites can run on the localhost, 127.0.0.1, or localhost IP address. There are some limitations in the localhost, you want to review your website on the custom domain before launching on the public domain suppose you have developed the e-commerce. You want to debug some payment gateway issue but your payment gateway is not supporting localhost URL or IP in the case of successful payment. You can add custom domain in the hosts file and validate the payment process on localhost </p>\n<h4 id=\"how-to-edit-hosts-file\" style=\"position:relative;\"><a href=\"#how-to-edit-hosts-file\" aria-label=\"how to edit hosts file permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How to edit hosts file</h4>\n<h5 id=\"windows-8-or-10\" style=\"position:relative;\"><a href=\"#windows-8-or-10\" aria-label=\"windows 8 or 10 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Windows 8 or 10</h5>\n<p>Windows operating system we need to open the host file </p>\n<ol>\n<li>Go to the Start menu and start typing the Notepad.</li>\n<li>Right-click Notepad and choose Run as administrator</li>\n</ol>\n<p>  <img src=\"/20915351d9e41e6e17b66f533f7db315/windows1.webp\" alt=\"Start Menu\"></p>\n<ol start=\"3\">\n<li>\n<p>Open the hosts file. Click on File > Open and Copy and Paste the following path`</p>\n<p><code>c:\\Windows\\System32\\Drivers\\etc\\hosts</code></p>\n</li>\n</ol>\n<p>  <img src=\"/a52d88025ba356b78b68017472da1df7/windows2.webp\" alt=\"edit-hosts-file-windows\"></p>\n<p>You can edit the hosts file</p>\n<p>Suppose you want to block facebook.com on your system and want to add a custom domain for your website. Just Copy and Paste following Lines</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">0.0.0.0         www.facebook.com</span>\n<span class=\"grvsc-line\">127.0.0.1       www.customdomain.com</span></code></pre>\n<p>  <img src=\"/3074615f157eeced9b2f4894885241dd/windows3.webp\" alt=\"Save-hosts-file-windows\"></p>\n<p>After finishing the Editing, <strong>Save your hosts file</strong></p>\n<p>  <img src=\"/ead0cbcf828255f6f85c0fe51ebabff0/windows4.webp\" alt=\"Save-hosts-file-windows\"></p>\n<p>Open your browser and try to access www.facebook.com and see you can’t access this site</p>\n<p>  <img src=\"/220ec47e648a76dc4f5fb2e09725d9cf/windows5.webp\" alt=\"Facebook-windows\"></p>\n<h5 id=\"linux\" style=\"position:relative;\"><a href=\"#linux\" aria-label=\"linux permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Linux</h5>\n<p>Use following instructions for Linux </p>\n<ol>\n<li>\n<p>In the Linux terminal window, open hosts file using a favorite text editor </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">$ sudo vim /etc/hosts</span></code></pre>\n</li>\n</ol>\n<p>  <img src=\"/3095554fa34ec943f59ec582c335a595/linux1.webp\" alt=\"linux-hosts-file\"></p>\n<p>  It will prompt for the password, enter your administrator password.</p>\n<ol start=\"2\">\n<li>Using the vim or your favorite text editor you can easily edit. The Linux hosts file is similar to the windows hosts file. Now again I am blocking Facebook and adding a custom domain </li>\n</ol>\n<p>  <img src=\"/0a619c3369d143ad0fdc5e2c64eb80e0/linux2.webp\" alt=\"linux-hosts-file-edit\"></p>\n<ol start=\"3\">\n<li>Save the Changes</li>\n</ol>\n<h5 id=\"mac-os\" style=\"position:relative;\"><a href=\"#mac-os\" aria-label=\"mac os permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Mac OS</h5>\n<p>Use following instructions for macOS </p>\n<ol>\n<li>Find the terminal application on your system\n-- We can use Spotlight application to search </li>\n</ol>\n<p>  <img src=\"/e0b8a6efe1386a10aa3419333583826c/mac1.webp\" alt=\"linux-hosts-file-edit\"></p>\n<ol start=\"2\">\n<li>Type <code>sudo vim /etc/hosts</code> in the terminal\n-- It will prompt for the password, enter your administrator password\n-- Enter administrator Password\n</li>\n</ol>\n<p>  <img src=\"/f6ba574fac85962782fddd1d5ea01009/mac2.webp\" alt=\"mac-password\"></p>\n<p><em>Using the vim text editor you can easily edit you. The macOS hosts file is also similar to the windows and Linux hosts file. I am blocking Facebook and adding custom domain here as well</em>.</p>\n<p>  <img src=\"/ca8db5b6c7015e56d24e0eab54598b77/mac3.webp\" alt=\"mac-hosts-file-edit\"></p>\n<ol start=\"3\">\n<li>Save Changes\nOpen your browser and try to access www.facebook.com and see you can’t access this site.</li>\n</ol>\n<p>  <img src=\"/220ec47e648a76dc4f5fb2e09725d9cf/mac4.webp\" alt=\"edit-hosts-file-mac\"></p>\n<h3 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h3>\n<p>The hosts file is found on all operating systems. The hosts file is a powerful tool. It can make your computer more secure and safer by blocking malicious sites    </p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n</style>","headings":[{"value":"What is the “hosts” file","depth":2},{"value":"Let’s talk about the usage of the hosts file","depth":3},{"value":"Protecting Privacy","depth":5},{"value":"Block website for your kids","depth":5},{"value":"Security","depth":5},{"value":"Development","depth":5},{"value":"How to edit hosts file","depth":4},{"value":"Windows 8 or 10","depth":5},{"value":"Linux","depth":5},{"value":"Mac OS","depth":5},{"value":"Conclusion","depth":3}],"fields":{"slug":"/engineering/hosts-file/"},"frontmatter":{"metatitle":null,"metadescription":null,"description":"Hosts file maps hostnames to IP addresses, sometimes required to be edited either to block some sites or to test some custom domain.This blog explains how can we edit the hosts in different operating systems.","title":"Benefits and usages of Hosts File","canonical":null,"date":"July 20, 2020","updated_date":null,"tags":["Computer tricks","Networking","Hosts File"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.4184397163120568,"src":"/static/54b234435c9e01dc08a3d668cceb489e/2420f/index.webp","srcSet":"/static/54b234435c9e01dc08a3d668cceb489e/1c9b5/index.webp 200w,\n/static/54b234435c9e01dc08a3d668cceb489e/f1752/index.webp 400w,\n/static/54b234435c9e01dc08a3d668cceb489e/2420f/index.webp 640w","sizes":"(max-width: 640px) 100vw, 640px"}}},"author":{"id":"Vijay Singh Shekhawat","github":"code-vj","bio":"He is the Lead Product Architect @LoginRadius. He loves working with technology and building something new. He is also a breakthrough thinker, DevOps guy, and cybersecurity enthusiast.","avatar":null}}}},"pageContext":{"id":"ceb2a4e9-a19e-53ca-9623-5425dfcaeab2","fields__slug":"/engineering/hosts-file/","__params":{"fields__slug":"engineering"}}},"staticQueryHashes":["1171199041","1384082988","1711371485","1753898100","2100481360","229320306","23180105","528864852"]}