{"id":21682,"date":"2026-11-21T08:33:00","date_gmt":"2026-11-21T05:33:00","guid":{"rendered":"https:\/\/sunucun.com.tr\/blog\/?p=21682"},"modified":"2026-11-21T08:33:00","modified_gmt":"2026-11-21T05:33:00","slug":"where-is-the-hosts-file","status":"publish","type":"post","link":"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/","title":{"rendered":"Where Is the Hosts File? Editing It on Windows, Mac and Linux"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_90 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><\/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:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#Where_Is_the_Hosts_File\" >Where Is the Hosts File?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#The_Hosts_File_Format\" >The Hosts File Format<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#How_to_Edit_the_Hosts_File_on_Windows\" >How to Edit the Hosts File on Windows<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#Editing_on_macOS\" >Editing on macOS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#Editing_on_Linux\" >Editing on Linux<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#What_Is_the_Hosts_File_Used_For\" >What Is the Hosts File Used For?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#Is_the_Hosts_File_Read_Before_DNS\" >Is the Hosts File Read Before DNS?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#Common_Mistakes\" >Common Mistakes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#The_Hosts_File_and_Security\" >The Hosts File and Security<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#Restoring_the_Default_Hosts_File\" >Restoring the Default Hosts File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#I_cant_see_the_hosts_file_What_should_I_do\" >I can&#8217;t see the hosts file. What should I do?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#The_change_I_made_to_the_hosts_file_isnt_working_Why\" >The change I made to the hosts file isn&#8217;t working. Why?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/sunucun.com.tr\/blog\/where-is-the-hosts-file\/#Can_ads_be_blocked_with_the_hosts_file\" >Can ads be blocked with the hosts file?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<p>The <strong>hosts file<\/strong> is a plain text file containing domain name to IP address mappings that your computer checks before asking DNS. It&#8217;s used to test a site on a new server without changing DNS, or to block a particular domain. In this article we explain where the hosts file is on Windows, macOS and Linux, how to edit it and common mistakes.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Where_Is_the_Hosts_File\"><\/span>Where Is the Hosts File?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<table>\n<thead>\n<tr>\n<th>Operating system<\/th>\n<th>File path<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Windows 10 \/ 11<\/td>\n<td><code>C:WindowsSystem32driversetchosts<\/code><\/td>\n<\/tr>\n<tr>\n<td>macOS<\/td>\n<td><code>\/etc\/hosts<\/code> (actually <code>\/private\/etc\/hosts<\/code>)<\/td>\n<\/tr>\n<tr>\n<td>Linux<\/td>\n<td><code>\/etc\/hosts<\/code><\/td>\n<\/tr>\n<tr>\n<td>Android<\/td>\n<td><code>\/system\/etc\/hosts<\/code> (can only be changed with root access)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>On Windows the file has no extension; its name is just <em>hosts<\/em>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"The_Hosts_File_Format\"><\/span>The Hosts File Format<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Each line contains the IP address first, then one or more spaces and the domain name. Lines starting with <code>#<\/code> are comments and are ignored:<\/p>\n<pre><code># To test the new server\n203.0.113.25    example.com\n203.0.113.25    www.example.com\n\n# To block a domain\n0.0.0.0         unwanted-site.com<\/code><\/pre>\n<p>Wildcards (*.example.com) can&#8217;t be used in the hosts file; you need to write each subdomain on a separate line.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Edit_the_Hosts_File_on_Windows\"><\/span>How to Edit the Hosts File on Windows<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li>Search for <strong>Notepad<\/strong> in the Start menu, right-click it and choose <strong>Run as administrator<\/strong>.<\/li>\n<li>Use <strong>File \u2192 Open<\/strong> to go to the <code>C:WindowsSystem32driversetc<\/code> folder.<\/li>\n<li>Set the file type to <strong>All Files (*.*)<\/strong> and open the <em>hosts<\/em> file.<\/li>\n<li>Add your lines at the bottom and save.<\/li>\n<li>Flush the DNS cache by typing <code>ipconfig \/flushdns<\/code> in Command Prompt.<\/li>\n<\/ol>\n<p>If you don&#8217;t open Notepad as administrator, you&#8217;ll get an &#8220;Access denied&#8221; error. Some security software protects the hosts file; you may need to turn this protection off temporarily while editing.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Editing_on_macOS\"><\/span>Editing on macOS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li>Open Terminal, type <code>sudo nano \/etc\/hosts<\/code> and enter your Mac password.<\/li>\n<li>Add your lines, save with <strong>Ctrl + O<\/strong> and exit with <strong>Ctrl + X<\/strong>.<\/li>\n<li>Flush the cache: <code>sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder<\/code><\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Editing_on_Linux\"><\/span>Editing on Linux<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Open and edit the file with <code>sudo nano \/etc\/hosts<\/code>. On distributions that use systemd-resolved, you can flush the cache with <code>sudo resolvectl flush-caches<\/code>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_Is_the_Hosts_File_Used_For\"><\/span>What Is the Hosts File Used For?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><strong>Site migration testing:<\/strong> checking the site on the new server from your own computer before changing the domain&#8217;s DNS records.<\/li>\n<li><strong>Development environments:<\/strong> opening projects running on a local server with the real domain name.<\/li>\n<li><strong>Blocking:<\/strong> shutting off access to certain domains by pointing them to 0.0.0.0.<\/li>\n<li><strong>Naming devices on the network:<\/strong> reaching a device on the local network by name instead of IP.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Is_the_Hosts_File_Read_Before_DNS\"><\/span>Is the Hosts File Read Before DNS?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Yes. When resolving a domain name, the operating system checks the hosts file by default first and then the DNS server. That&#8217;s why an entry added to the hosts file takes effect regardless of what DNS says. If your computer opens a different server for a site than everyone else sees, check your hosts file. To compare DNS records, see our guide <a href=\"https:\/\/sunucun.com.tr\/blog\/how-to-do-a-dns-lookup\/\">how to do a DNS lookup<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Common_Mistakes\"><\/span>Common Mistakes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><strong>Saving the file as .txt:<\/strong> if the file name becomes <em>hosts.txt<\/em>, the system won&#8217;t read it.<\/li>\n<li><strong>Putting # at the start of the line:<\/strong> it stays a comment and doesn&#8217;t work.<\/li>\n<li><strong>Forgetting to delete the line after testing:<\/strong> you&#8217;ll keep seeing the old server even after DNS changes.<\/li>\n<li><strong>Browser cache:<\/strong> if the change doesn&#8217;t show, close and reopen the browser or try a private window. In some browsers the hosts file is still respected when encrypted DNS (DoH) is on, but you may need to clear the browser&#8217;s own DNS cache.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"The_Hosts_File_and_Security\"><\/span>The Hosts File and Security<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Some malware adds lines to the hosts file to redirect banking or security sites to fake servers, or to block antivirus updates. If you see lines you don&#8217;t recognise, scan your computer with up-to-date security software.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Restoring_the_Default_Hosts_File\"><\/span>Restoring the Default Hosts File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The default Windows hosts file contains only comment lines. Deleting all the lines you added and saving is enough to return the file to its default state. Then run <code>ipconfig \/flushdns<\/code>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"I_cant_see_the_hosts_file_What_should_I_do\"><\/span>I can&#8217;t see the hosts file. What should I do?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Set the file type to &#8220;All Files&#8221; in Notepad&#8217;s open window. If the file really doesn&#8217;t exist, you can create a new file named <em>hosts<\/em> with no extension in the same folder.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"The_change_I_made_to_the_hosts_file_isnt_working_Why\"><\/span>The change I made to the hosts file isn&#8217;t working. Why?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You may not have saved it with administrator rights, flushed the DNS cache or put a space between the IP and the domain name. Also try restarting the browser.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_ads_be_blocked_with_the_hosts_file\"><\/span>Can ads be blocked with the hosts file?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It&#8217;s possible with ready-made lists that point ad domains to 0.0.0.0, but keeping the lists up to date is hard. DNS-based blockers are a more practical method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The hosts file is a plain text file containing domain name to IP address mappings that your computer checks before asking DNS. It&#8217;s used to test a site on a new server without changing DNS, or to block a particular domain. In this article we explain where the hosts file is on Windows, macOS and&hellip;<\/p>\n","protected":false},"author":1,"featured_media":21683,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[1523],"tags":[],"class_list":["post-21682","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-network"],"_links":{"self":[{"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/posts\/21682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/comments?post=21682"}],"version-history":[{"count":1,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/posts\/21682\/revisions"}],"predecessor-version":[{"id":21944,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/posts\/21682\/revisions\/21944"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/media\/21683"}],"wp:attachment":[{"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/media?parent=21682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/categories?post=21682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/tags?post=21682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}