{"id":656,"date":"2021-03-23T16:43:23","date_gmt":"2021-03-23T16:43:23","guid":{"rendered":"https:\/\/www.register365.com\/support\/?post_type=ht_kb&#038;p=656"},"modified":"2021-04-20T17:34:53","modified_gmt":"2021-04-20T16:34:53","slug":"how-to-edit-the-hosts-file-in-macos","status":"publish","type":"ht_kb","link":"https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/","title":{"rendered":"How to Edit the Hosts File in macOS"},"content":{"rendered":"\n<p>The hosts file is a text file that maps hostnames to IP addresses.<br>Upon typing a url address on the browser, the system is checking if there is a relevant entry on the hosts file and gets the corresponding IP address, else it resolves the IP via the active connection DNS servers.<\/p>\n\n\n\n<p>The hosts file can be edited to block certain hostnames (like ad-serving\/malicious hosts), or used for web development purposes, i.e. to redirect domains to local addresses.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Editing the hosts file<\/h2>\n\n\n\n<p>Editing the hosts file in macOS, is a pretty easy task, especially if you are familiar with the terminal.<\/p>\n\n\n\n<p><strong>Step 1 Open the Terminal.app<\/strong><\/p>\n\n\n\n<p>Either by start typing Terminal on the Spotlight, or by going into Applications -&gt; Utilities -&gt; Terminal.<\/p>\n\n\n\n<p><strong>Step 2 Open the hosts file<\/strong><\/p>\n\n\n\n<p>Open the hosts by typing on the Terminal that you have just opened:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo nano \/private\/etc\/hosts<\/pre>\n\n\n\n<p>Type your user password when prompted.<\/p>\n\n\n\n<p><strong>Step 3 Edit the hosts file<\/strong><\/p>\n\n\n\n<p>The hosts file contains some comments (lines starting with the # symbol), as well as some default hostname mappings (e.g. 127.0.0.1 localhost). Simply append your new mappings underneath the default ones. Or edit one of the default values if you know what you are doing! You can navigate the file using the arrow keys.<\/p>\n\n\n\n<p><strong>Step 4 Save the hosts file<\/strong><\/p>\n\n\n\n<p>When done editing the hosts file, press control-o to save the file. Press enter on the filename prompt, and control-x to exit the editor.<\/p>\n\n\n\n<p><strong>Step 5 Flush the DNS cache<\/strong><\/p>\n\n\n\n<p>On Leopard you can issue a simple Terminal command to flush the DNS cache, and have your host file changes to take immediate effect:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>$ dscacheutil -flushcache<\/code><\/pre>\n\n\n\n<p>You can now test your new mapping on the browser!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The hosts file is a text file that maps hostnames to IP addresses.Upon typing a url address on the browser, the system is checking if there is a relevant entry on the hosts file and gets the corresponding IP address, else it resolves the IP via the active connection DNS servers. The hosts file can [&hellip;]<\/p>\n","protected":false},"author":2,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[58,57],"ht-kb-tag":[70,62,63,61],"class_list":["post-656","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-managed-servers","ht_kb_category-servers","ht_kb_tag-dns","ht_kb_tag-managed-servers","ht_kb_tag-migration","ht_kb_tag-servers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Edit the Hosts File in macOS - Support Centre - Register365<\/title>\n<meta name=\"description\" content=\"The hosts file is a text file that maps hostnames to IP addresses.\" \/>\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.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Edit the Hosts File in macOS - Support Centre - Register365\" \/>\n<meta property=\"og:description\" content=\"The hosts file is a text file that maps hostnames to IP addresses.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/\" \/>\n<meta property=\"og:site_name\" content=\"Support Centre - Register365\" \/>\n<meta property=\"article:modified_time\" content=\"2021-04-20T16:34:53+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/\",\"url\":\"https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/\",\"name\":\"How to Edit the Hosts File in macOS - Support Centre - Register365\",\"isPartOf\":{\"@id\":\"https:\/\/www.register365.com\/support\/#website\"},\"datePublished\":\"2021-03-23T16:43:23+00:00\",\"dateModified\":\"2021-04-20T16:34:53+00:00\",\"description\":\"The hosts file is a text file that maps hostnames to IP addresses.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.register365.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Edit the Hosts File in macOS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.register365.com\/support\/#website\",\"url\":\"https:\/\/www.register365.com\/support\/\",\"name\":\"Support Centre - Register365\",\"description\":\"Register365 Support Centre\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.register365.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Edit the Hosts File in macOS - Support Centre - Register365","description":"The hosts file is a text file that maps hostnames to IP addresses.","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.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/","og_locale":"en_US","og_type":"article","og_title":"How to Edit the Hosts File in macOS - Support Centre - Register365","og_description":"The hosts file is a text file that maps hostnames to IP addresses.","og_url":"https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/","og_site_name":"Support Centre - Register365","article_modified_time":"2021-04-20T16:34:53+00:00","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/","url":"https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/","name":"How to Edit the Hosts File in macOS - Support Centre - Register365","isPartOf":{"@id":"https:\/\/www.register365.com\/support\/#website"},"datePublished":"2021-03-23T16:43:23+00:00","dateModified":"2021-04-20T16:34:53+00:00","description":"The hosts file is a text file that maps hostnames to IP addresses.","breadcrumb":{"@id":"https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.register365.com\/support\/articles\/how-to-edit-the-hosts-file-in-macos\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.register365.com\/support\/"},{"@type":"ListItem","position":2,"name":"How to Edit the Hosts File in macOS"}]},{"@type":"WebSite","@id":"https:\/\/www.register365.com\/support\/#website","url":"https:\/\/www.register365.com\/support\/","name":"Support Centre - Register365","description":"Register365 Support Centre","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.register365.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"}]}},"_links":{"self":[{"href":"https:\/\/www.register365.com\/support\/wp-json\/wp\/v2\/ht-kb\/656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.register365.com\/support\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.register365.com\/support\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.register365.com\/support\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.register365.com\/support\/wp-json\/wp\/v2\/comments?post=656"}],"version-history":[{"count":2,"href":"https:\/\/www.register365.com\/support\/wp-json\/wp\/v2\/ht-kb\/656\/revisions"}],"predecessor-version":[{"id":658,"href":"https:\/\/www.register365.com\/support\/wp-json\/wp\/v2\/ht-kb\/656\/revisions\/658"}],"wp:attachment":[{"href":"https:\/\/www.register365.com\/support\/wp-json\/wp\/v2\/media?parent=656"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.register365.com\/support\/wp-json\/wp\/v2\/ht-kb-category?post=656"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.register365.com\/support\/wp-json\/wp\/v2\/ht-kb-tag?post=656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}