{"id":711,"date":"2017-03-01T00:00:00","date_gmt":"2017-03-01T00:00:00","guid":{"rendered":"http:\/\/blog.hostinger.io\/hostinger-tutorials\/uncategorized\/how-to-edit-hosts-file-macos\/"},"modified":"2026-03-09T19:20:09","modified_gmt":"2026-03-09T19:20:09","slug":"how-to-edit-hosts-file-macos","status":"publish","type":"post","link":"\/ng\/tutorials\/how-to-edit-hosts-file-macos","title":{"rendered":"How to successfully locate and edit hosts file on a Mac using terminal"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>Users can emulate domain name system (DNS) changes by editing the hosts file. This includes overwriting DNS values set by the internet service provider (ISP) and setting custom IPs for a domain name.<\/p><p>By editing the Mac hosts file, you can easily preview your website on the local network. This helps if your domain is not yet registered, not pointed to a hosting account, or is still propagating.<\/p><p>This tutorial will teach you how to edit the Mac <strong>hosts<\/strong> file and flush the DNS cache.<\/p><figure class=\"wp-block-image size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/How-to-Speed-Up-Your-Website-EN.pdf\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/public\" alt=\"\" class=\"wp-image-69260\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure><p>\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-what-is-the-hosts-file-on-a-mac-and-why-is-it-important\">What Is the Hosts File on a Mac, and Why Is It Important<\/h2><p>A system&rsquo;s hosts file maps hostnames to IP addresses. Users can override default DNS information for a given domain and specify their IP addresses.<\/p><p>Mac users can find the hosts file in the<strong> \/private\/etc\/hosts <\/strong>directory. You can edit it with any text editor as long as you have root user privileges.<\/p><p><div><p class=\"important\"><strong>Important!<\/strong> Hosts file changes will only apply to the local machine. If you want a website to be visible to everyone, you must register a domain and point it to a hosting plan.<\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-locate-and-edit-the-hosts-file-on-macos\">How to Locate and Edit the Hosts File on macOS<\/h2><p>Let&rsquo;s start by finding and opening the hosts file.<\/p><p>1. Open the Hosts File<\/p><p>Follow these steps to access your <strong>hosts<\/strong> file on a Mac:<\/p><p>2. Open Terminal by searching it via the spotlight search (<strong>Command + Spacebar <\/strong>keys).<\/p><figure class=\"wp-block-image aligncenter size-large\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/03\/Finder-window-displaying-search-results-for-terminal.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1326\" height=\"248\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/Finder-window-displaying-search-results-for-terminal.png\/public\" alt=\"Finder window displaying search results for terminal\n\" class=\"wp-image-72984\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/Finder-window-displaying-search-results-for-terminal.png\/w=1326,fit=scale-down 1326w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/Finder-window-displaying-search-results-for-terminal.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/Finder-window-displaying-search-results-for-terminal.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/Finder-window-displaying-search-results-for-terminal.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/Finder-window-displaying-search-results-for-terminal.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1326px) 100vw, 1326px\" \/><\/a><\/figure><p>3. Open the <strong>hosts <\/strong>file with your preferred editor program. In this tutorial, we will use the <a href=\"\/ng\/tutorials\/how-to-install-and-use-nano-text-editor\">Nano text editor<\/a>. To open it, enter the following:<\/p><pre class=\"wp-block-preformatted\">sudo nano \/private\/etc\/hosts<\/pre><p>4. Since we use <strong>sudo<\/strong> to edit the <strong>hosts<\/strong> file, you will be asked to enter the administrator password of your macOS user account. Type your admin password and hit the <strong>Enter <\/strong>key.<\/p><figure class=\"wp-block-image aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/03\/The-terminal-window-displays-the-original-hosts-file-that-is-opened-with-the-nano-text-editor.-Here-users-can-add-a-specific-IP-address-to-map-to-a-specific-domain.png\"><img loading=\"lazy\" decoding=\"async\" width=\"952\" height=\"326\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/The-terminal-window-displays-the-original-hosts-file-that-is-opened-with-the-nano-text-editor.-Here-users-can-add-a-specific-IP-address-to-map-to-a-specific-domain.png\/public\" alt=\"The terminal window displays the original hosts file that is opened with the nano text editor. Here users can add a specific IP address to map to a specific domain\n\" class=\"wp-image-72985\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/The-terminal-window-displays-the-original-hosts-file-that-is-opened-with-the-nano-text-editor.-Here-users-can-add-a-specific-IP-address-to-map-to-a-specific-domain.png\/w=952,fit=scale-down 952w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/The-terminal-window-displays-the-original-hosts-file-that-is-opened-with-the-nano-text-editor.-Here-users-can-add-a-specific-IP-address-to-map-to-a-specific-domain.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/The-terminal-window-displays-the-original-hosts-file-that-is-opened-with-the-nano-text-editor.-Here-users-can-add-a-specific-IP-address-to-map-to-a-specific-domain.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/The-terminal-window-displays-the-original-hosts-file-that-is-opened-with-the-nano-text-editor.-Here-users-can-add-a-specific-IP-address-to-map-to-a-specific-domain.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 952px) 100vw, 952px\" \/><\/a><\/figure><p><div><p class=\"important\"><strong>Important!<\/strong> For security reasons, the cursor doesn&rsquo;t work in the command line. Use the arrow keys to navigate between the lines inside the hosts file.<\/p><\/div>\n\n\n\n<\/p><p>5. Edit the Hosts File on a Mac<\/p><p>To emulate DNS settings and point a domain name to an IP address, use the following syntax:<\/p><pre class=\"wp-block-preformatted\">IP_Address domain.com\n\nIP_Address www.domain.com<\/pre><p>For example, to emulate the DNS change for <strong>hostinger.com<\/strong> and <strong>www.hostinger.com<\/strong>, you would have to include the following lines at the bottom of the <strong>hosts<\/strong> file.<\/p><pre class=\"wp-block-preformatted\">185.185.185.185 hostinger.com\n\n185.185.185.185 www.hostinger.com<\/pre><p>This will emulate the IP address change of the<strong> hostinger.com<\/strong> domain and <strong>www.hostinger.com<\/strong> subdomain to <strong>185.185.185.185<\/strong>.<\/p><figure class=\"wp-block-image aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/03\/Mac_s-hosts-file-contents-with-custom-IPs-added-for-the-Hostinger.com-domain.-The-red-border-indicates-new-mapping-values-with-corresponding-IPs.png\"><img loading=\"lazy\" decoding=\"async\" width=\"822\" height=\"406\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/Mac_s-hosts-file-contents-with-custom-IPs-added-for-the-Hostinger.com-domain.-The-red-border-indicates-new-mapping-values-with-corresponding-IPs.png\/public\" alt=\"Mac's hosts file contents with custom IPs added for the Hostinger.com domain. The red border indicates new mapping values with corresponding IPs\n\" class=\"wp-image-72986\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/Mac_s-hosts-file-contents-with-custom-IPs-added-for-the-Hostinger.com-domain.-The-red-border-indicates-new-mapping-values-with-corresponding-IPs.png\/w=822,fit=scale-down 822w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/Mac_s-hosts-file-contents-with-custom-IPs-added-for-the-Hostinger.com-domain.-The-red-border-indicates-new-mapping-values-with-corresponding-IPs.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/Mac_s-hosts-file-contents-with-custom-IPs-added-for-the-Hostinger.com-domain.-The-red-border-indicates-new-mapping-values-with-corresponding-IPs.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2017\/03\/Mac_s-hosts-file-contents-with-custom-IPs-added-for-the-Hostinger.com-domain.-The-red-border-indicates-new-mapping-values-with-corresponding-IPs.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 822px) 100vw, 822px\" \/><\/a><\/figure><p>Once you are done editing the <strong>hosts<\/strong> file, press <strong>Control + X<\/strong> on your keyboard. Enter <strong>Y<\/strong> to save the changes, and hit the <strong>Enter <\/strong>button.<\/p><p>Now, your Mac will resolve the <strong>hostinger.com<\/strong> domain using the given IP address instead of what is set at the DNS Zone.<\/p><p>Editing the <strong>hosts<\/strong> file can also help you see your new site content during the propagation period after connecting a domain to web hosting. Remember that after propagation is done, you should remove the new lines from the <strong>hosts<\/strong> file.<\/p><p>6. Flush DNS Cache<\/p><p>The <strong>hosts<\/strong> file changes may not apply instantly. You can <a href=\"\/ng\/tutorials\/how-to-flush-dns\">flush the DNS cache<\/a> to help speed up the process. To flush a Mac&rsquo;s DNS cache, execute the following command:<\/p><p><strong>macOS Monterey, Big Sur<\/strong><\/p><pre class=\"wp-block-preformatted\">sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder<\/pre><p><strong>macOS Catalina, Mojave, High Sierra, Sierra, Mountain Lion, Lion<\/strong><\/p><pre class=\"wp-block-preformatted\">sudo killall -HUP mDNSResponder<\/pre><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-full\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-web-hosting\" href=\"\/ng\/web-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/public\" alt=\"Hostinger web hosting banner\" class=\"wp-image-98604\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Editing the <strong>hosts<\/strong> file helps point your domain to a hosting plan without changing DNS records. This lets your personal computer resolve the domain to a preferred IP address.<\/p><p>In this tutorial, we&rsquo;ve gone through editing the <strong>hosts<\/strong> file on a Mac and flushing the DNS cache to speed up the process.<\/p><p>We hope that you found this tutorial helpful. If you have any questions, let us know in the comments section below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Users can emulate domain name system (DNS) changes by editing the hosts file. This includes overwriting DNS values set by the internet service provider (ISP) and setting custom IPs for a domain name. By editing the Mac hosts file, you can easily preview your website on the local network. This helps if your domain is [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ng\/tutorials\/how-to-edit-hosts-file-macos\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":2,"featured_media":145396,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Locate and Edit Hosts File on Mac in 3 Simple Steps","rank_math_description":"Check out this article to learn how to Locate and Edit Hosts File on Mac: 1. Open hosts file 2. Edit hosts file 3. Flush DNS cache.","rank_math_focus_keyword":"hosts file mac","footnotes":""},"categories":[22631],"tags":[],"class_list":["post-711","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-domains"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-edit-hosts-file-macos","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/como-editar-o-arquivo-hosts-no-mac","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/archivo-hosts-mac","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-edit-hosts-file-macos","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-edit-hosts-file-macos","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-edit-hosts-file-macos","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/archivo-hosts-mac","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/archivo-hosts-mac","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/archivo-hosts-mac","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/como-editar-o-arquivo-hosts-no-mac","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-edit-hosts-file-macos","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-edit-hosts-file-macos","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-edit-hosts-file-macos","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-edit-hosts-file-macos","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/comments?post=711"}],"version-history":[{"count":16,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/711\/revisions"}],"predecessor-version":[{"id":145395,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/711\/revisions\/145395"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media\/145396"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media?parent=711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/categories?post=711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/tags?post=711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}