<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Locahl</title>
    <description>The latest articles on DEV Community by Locahl (@locahl_9bd77121e3d366f72f).</description>
    <link>https://dev.to/locahl_9bd77121e3d366f72f</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4032775%2F94fe31a9-7dfd-4446-88b0-06fc72180331.png</url>
      <title>DEV Community: Locahl</title>
      <link>https://dev.to/locahl_9bd77121e3d366f72f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/locahl_9bd77121e3d366f72f"/>
    <language>en</language>
    <item>
      <title>Fix Permission denied when editing /etc/hosts</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Thu, 16 Jul 2026 22:38:26 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/fix-permission-denied-when-editing-etchosts-5c4f</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/fix-permission-denied-when-editing-etchosts-5c4f</guid>
      <description>&lt;p&gt;You open the hosts file, change one line, hit save, and get &lt;code&gt;Permission denied&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That is normal. The system hosts file is protected on purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it happens
&lt;/h2&gt;

&lt;p&gt;On macOS and Linux, &lt;code&gt;/etc/hosts&lt;/code&gt; is owned by root.&lt;/p&gt;

&lt;p&gt;On Windows, &lt;code&gt;C:\Windows\System32\drivers\etc\hosts&lt;/code&gt; needs Administrator rights.&lt;/p&gt;

&lt;p&gt;A normal editor process cannot overwrite it.&lt;/p&gt;

&lt;h2&gt;
  
  
  macOS / Linux fix
&lt;/h2&gt;

&lt;p&gt;Edit with elevated rights:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or open your editor as root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;code /etc/hosts
&lt;span class="c"&gt;# or&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;vim /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Safer pattern: edit a copy you own, then install it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cp&lt;/span&gt; /etc/hosts ~/hosts.work
&lt;span class="c"&gt;# edit ~/hosts.work&lt;/span&gt;
&lt;span class="nb"&gt;sudo cp&lt;/span&gt; /etc/hosts &lt;span class="s2"&gt;"/etc/hosts.bak.&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt; +%Y%m%d-%H%M%S&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;sudo cp&lt;/span&gt; ~/hosts.work /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then flush DNS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Windows fix
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Start Notepad &lt;strong&gt;as Administrator&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;File → Open&lt;/li&gt;
&lt;li&gt;Go to &lt;code&gt;C:\Windows\System32\drivers\etc\&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Set the filter to &lt;strong&gt;All Files&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Open &lt;code&gt;hosts&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Save&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If Notepad was not elevated, Windows often lets you open the file and then fails on save.&lt;/p&gt;

&lt;p&gt;PowerShell alternative:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Start-Process&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;notepad&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;C:\Windows\System32\drivers\etc\hosts&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Verb&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;RunAs&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;ipconfig&lt;/span&gt; &lt;span class="na"&gt;/flushdns
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  "I can edit but nothing changes"
&lt;/h2&gt;

&lt;p&gt;That is a different bug:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you saved a copy in Downloads / Desktop&lt;/li&gt;
&lt;li&gt;the line is still commented with &lt;code&gt;#&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;DNS cache was not flushed&lt;/li&gt;
&lt;li&gt;another line for the same hostname wins&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Verify the live file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"myapp.test"&lt;/span&gt; /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Avoid fighting permissions every day
&lt;/h2&gt;

&lt;p&gt;Keep project hosts snippets in your repo or home folder. Copy them into place with one &lt;code&gt;sudo&lt;/code&gt; command when needed.&lt;/p&gt;

&lt;p&gt;That keeps the protected system file boring, and your editable copy easy to version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick recovery if you break hosts
&lt;/h2&gt;

&lt;p&gt;You should still be able to reach the machine by IP and local loopback. Restore from your backup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo cp&lt;/span&gt; /etc/hosts.bak.YYYYMMDD-HHMMSS /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you did not make a backup, most OS installs still have a minimal localhost block you can recreate. Do that before you go hunting for network bugs.&lt;/p&gt;




&lt;p&gt;If you switch hosts a lot, a small desktop manager helps keep profiles and DNS flush in one place: &lt;a href="https://www.locahl.app/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=hosts-series" rel="noopener noreferrer"&gt;Locahl&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>DNS not updating after hosts file change? Fix it in order</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Thu, 16 Jul 2026 22:32:35 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/dns-not-updating-after-hosts-file-change-fix-it-in-order-57en</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/dns-not-updating-after-hosts-file-change-fix-it-in-order-57en</guid>
      <description>&lt;p&gt;You edited the hosts file. The line looks correct. The browser still opens the old site.&lt;/p&gt;

&lt;p&gt;Do not rewrite the hosts file again yet. Walk the stack in order.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Confirm the file that actually loaded
&lt;/h2&gt;

&lt;p&gt;macOS / Linux:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"example.com"&lt;/span&gt; /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Windows (Admin PowerShell):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Select-String&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;C:\Windows\System32\drivers\etc\hosts&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Pattern&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"example.com"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a &lt;code&gt;#&lt;/code&gt; commenting the line out&lt;/li&gt;
&lt;li&gt;a second line for the same hostname later in the file&lt;/li&gt;
&lt;li&gt;a typo in the hostname&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the terminal cannot see the line, the browser will not either.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Flush the OS DNS cache
&lt;/h2&gt;

&lt;p&gt;macOS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;dscacheutil &lt;span class="nt"&gt;-flushcache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;killall &lt;span class="nt"&gt;-HUP&lt;/span&gt; mDNSResponder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Windows (Admin):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;ipconfig&lt;/span&gt; &lt;span class="na"&gt;/flushdns
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Linux with systemd-resolved:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;resolvectl flush-caches
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Ask the OS, not the browser
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# macOS / Linux&lt;/span&gt;
ping &lt;span class="nt"&gt;-c&lt;/span&gt; 1 example.com
getent hosts example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Windows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;ping&lt;/span&gt; &lt;span class="kd"&gt;example&lt;/span&gt;.com
&lt;span class="nb"&gt;nslookup&lt;/span&gt; &lt;span class="kd"&gt;example&lt;/span&gt;.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the terminal shows the wrong IP, stop. Fix hosts or flush again. Do not debug the app yet.&lt;/p&gt;

&lt;p&gt;On some systems &lt;code&gt;nslookup&lt;/code&gt; talks to a DNS server and can ignore hosts. Prefer &lt;code&gt;ping&lt;/code&gt; / &lt;code&gt;getent&lt;/code&gt; for hosts checks.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Clear browser DNS
&lt;/h2&gt;

&lt;p&gt;Browsers cache names too.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Quit the browser fully (not just the tab)&lt;/li&gt;
&lt;li&gt;Reopen and retry&lt;/li&gt;
&lt;li&gt;Chrome: &lt;code&gt;chrome://net-internals/#dns&lt;/code&gt; → &lt;strong&gt;Clear host cache&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Try a private window once, to rule out extensions&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  5. Watch for HTTPS and HSTS traps
&lt;/h2&gt;

&lt;p&gt;Hosts can point &lt;code&gt;www.client.com&lt;/code&gt; at staging, while the browser still forces HTTPS and an old certificate story.&lt;/p&gt;

&lt;p&gt;Symptoms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;certificate warnings&lt;/li&gt;
&lt;li&gt;redirects back to production&lt;/li&gt;
&lt;li&gt;cookies scoped to the real domain behaving oddly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For local-only work, prefer &lt;code&gt;.test&lt;/code&gt; names. For cutover tests, expect TLS quirks and test with curl too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-vI&lt;/span&gt; https://www.client.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Docker and VPN layers
&lt;/h2&gt;

&lt;p&gt;If the browser is on the host but the service is in Docker, your laptop hosts file may not be what the container uses.&lt;/p&gt;

&lt;p&gt;If a VPN or corporate DNS is active, flush again after connect/disconnect. Some agents re-inject resolvers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Short checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Line present and uncommented in the real hosts file&lt;/li&gt;
&lt;li&gt;One active mapping per hostname&lt;/li&gt;
&lt;li&gt;OS DNS flushed&lt;/li&gt;
&lt;li&gt;Terminal resolves the expected IP&lt;/li&gt;
&lt;li&gt;Browser DNS cleared&lt;/li&gt;
&lt;li&gt;Only then debug the app, proxy, or TLS&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Most "hosts is broken" reports die at step 3 or 4.&lt;/p&gt;




&lt;p&gt;If you switch hosts a lot, a small desktop manager helps keep profiles and DNS flush in one place: &lt;a href="https://www.locahl.app/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=hosts-series" rel="noopener noreferrer"&gt;Locahl&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>dns</category>
    </item>
    <item>
      <title>Use a custom local domain instead of localhost:3000</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Thu, 16 Jul 2026 22:28:29 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/use-a-custom-local-domain-instead-of-localhost3000-340b</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/use-a-custom-local-domain-instead-of-localhost3000-340b</guid>
      <description>&lt;p&gt;&lt;code&gt;http://localhost:3000&lt;/code&gt; works. It also breaks a few real-world checks early:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;cookies scoped to a real-looking host&lt;/li&gt;
&lt;li&gt;absolute URLs in emails and webhooks&lt;/li&gt;
&lt;li&gt;multi-app setups (&lt;code&gt;app&lt;/code&gt;, &lt;code&gt;api&lt;/code&gt;, &lt;code&gt;admin&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;OAuth redirect allowlists that hate bare localhost quirks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A local hostname like &lt;code&gt;myapp.test&lt;/code&gt; is often cleaner.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Add the hostname
&lt;/h2&gt;

&lt;p&gt;In &lt;code&gt;/etc/hosts&lt;/code&gt; (macOS/Linux) or &lt;code&gt;C:\Windows\System32\drivers\etc\hosts&lt;/code&gt; (Windows):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;127.0.0.1   myapp.test
127.0.0.1   api.myapp.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Prefer &lt;code&gt;.test&lt;/code&gt;. It is reserved for testing. Avoid inventing fake &lt;code&gt;.com&lt;/code&gt; names you might later need for real DNS.&lt;/p&gt;

&lt;p&gt;Flush DNS after saving.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Point your app at it
&lt;/h2&gt;

&lt;p&gt;Many stacks already bind &lt;code&gt;0.0.0.0&lt;/code&gt; or &lt;code&gt;127.0.0.1&lt;/code&gt;. You only change the URL you open:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://myapp.test:3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the framework reads &lt;code&gt;HOST&lt;/code&gt; / &lt;code&gt;APP_URL&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;APP_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;http://myapp.test:3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep the port unless you put a reverse proxy in front.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Optional: drop the port with a proxy
&lt;/h2&gt;

&lt;p&gt;Caddy example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myapp.test {
  reverse_proxy localhost:3000
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then open &lt;code&gt;http://myapp.test&lt;/code&gt;. Same idea with nginx or Traefik.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. HTTPS locally
&lt;/h2&gt;

&lt;p&gt;Some features need secure cookies or HTTPS redirects.&lt;/p&gt;

&lt;p&gt;Options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Caddy or mkcert for a local cert on &lt;code&gt;myapp.test&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Your framework's built-in HTTPS in development&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not fight browser warnings with a public domain pointed at &lt;code&gt;127.0.0.1&lt;/code&gt; unless you control that name.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Frontend and API on sibling hosts
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;127.0.0.1   app.myapp.test
127.0.0.1   api.myapp.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Frontend on &lt;code&gt;:3000&lt;/code&gt;, API on &lt;code&gt;:4000&lt;/code&gt;. CORS and cookie domains become closer to production:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Domain=.myapp.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is often the whole reason to stop using plain &lt;code&gt;localhost&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist when it "does not work"
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Hosts line exists and is not commented&lt;/li&gt;
&lt;li&gt;DNS cache flushed&lt;/li&gt;
&lt;li&gt;App is listening on the port you typed&lt;/li&gt;
&lt;li&gt;You opened &lt;code&gt;myapp.test&lt;/code&gt;, not &lt;code&gt;localhost&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Proxy config matches the hostname if you use one&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Terminal check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ping &lt;span class="nt"&gt;-c&lt;/span&gt; 1 myapp.test
&lt;span class="c"&gt;# should show 127.0.0.1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  When to skip this
&lt;/h2&gt;

&lt;p&gt;Throwaway demos and single-file experiments are fine on &lt;code&gt;localhost&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Reach for a custom local domain when cookies, redirects, or multiple services start fighting you. One hosts line usually ends the fight.&lt;/p&gt;




&lt;p&gt;If you switch hosts a lot, a small desktop manager helps keep profiles and DNS flush in one place: &lt;a href="https://www.locahl.app/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=hosts-series" rel="noopener noreferrer"&gt;Locahl&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to block websites with the hosts file</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Thu, 16 Jul 2026 22:14:24 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/how-to-block-websites-with-the-hosts-file-3kd4</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/how-to-block-websites-with-the-hosts-file-3kd4</guid>
      <description>&lt;p&gt;You can block a domain on your machine without installing another browser extension.&lt;/p&gt;

&lt;p&gt;Point the hostname at a dead address in the hosts file. The OS resolves it locally and the site never loads.&lt;/p&gt;

&lt;p&gt;This is blunt. It works for distraction sites, telemetry hosts you do not need, and quick local tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pattern
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0.0.0.0   www.example.com
0.0.0.0   example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;0.0.0.0&lt;/code&gt; is the usual choice. Some people use &lt;code&gt;127.0.0.1&lt;/code&gt;. Both stop the real site from loading. &lt;code&gt;0.0.0.0&lt;/code&gt; avoids sending traffic to a local server you might already run.&lt;/p&gt;

&lt;p&gt;Block both apex and &lt;code&gt;www&lt;/code&gt; if the site uses both.&lt;/p&gt;

&lt;h2&gt;
  
  
  macOS and Linux
&lt;/h2&gt;

&lt;p&gt;Edit hosts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add your lines, save, then flush DNS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# macOS&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;dscacheutil &lt;span class="nt"&gt;-flushcache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;killall &lt;span class="nt"&gt;-HUP&lt;/span&gt; mDNSResponder

&lt;span class="c"&gt;# Linux (systemd-resolved)&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;resolvectl flush-caches
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Windows
&lt;/h2&gt;

&lt;p&gt;Open Notepad as Administrator, open:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Windows\System32\drivers\etc\hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the same style of lines, save, then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;ipconfig&lt;/span&gt; &lt;span class="na"&gt;/flushdns
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Verify
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ping &lt;span class="nt"&gt;-c&lt;/span&gt; 1 www.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see &lt;code&gt;0.0.0.0&lt;/code&gt; or a failed route, not the real public IP.&lt;/p&gt;

&lt;p&gt;Browser still loading the site? Quit it fully and reopen. Chrome also has its own DNS cache under &lt;code&gt;chrome://net-internals/#dns&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this does not block
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Apps that hardcode IPs&lt;/li&gt;
&lt;li&gt;Sites reached through a VPN or proxy that ignores your hosts file&lt;/li&gt;
&lt;li&gt;HTTPS hosts you only blocked under the wrong name (&lt;code&gt;example.com&lt;/code&gt; vs &lt;code&gt;www&lt;/code&gt; vs a CDN host)&lt;/li&gt;
&lt;li&gt;Mobile apps on another device (hosts is local to that machine)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For team-wide or network-wide blocking you need DNS or firewall rules, not a laptop hosts file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep it tidy
&lt;/h2&gt;

&lt;p&gt;Group blocks under a comment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# focus mode
0.0.0.0   www.reddit.com
0.0.0.0   reddit.com
0.0.0.0   www.youtube.com
0.0.0.0   youtube.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you need the site again, comment the lines or delete them and flush DNS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Safety note
&lt;/h2&gt;

&lt;p&gt;Do not block domains your OS or package manager needs unless you know what you are doing. A bad block looks like "the internet is broken" until you remember last night's edit.&lt;/p&gt;

&lt;p&gt;Start with one domain, verify, then add more.&lt;/p&gt;




&lt;p&gt;If you switch hosts a lot, a small desktop manager helps keep profiles and DNS flush in one place: &lt;a href="https://www.locahl.app/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=hosts-series" rel="noopener noreferrer"&gt;Locahl&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Where is the hosts file on Mac, Windows, and Linux?</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Thu, 16 Jul 2026 22:01:29 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/where-is-the-hosts-file-on-mac-windows-and-linux-5cko</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/where-is-the-hosts-file-on-mac-windows-and-linux-5cko</guid>
      <description>&lt;p&gt;You need to open the hosts file. You already know why. You just cannot remember the path.&lt;/p&gt;

&lt;p&gt;Here it is for each OS, plus how to open it without fighting permissions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Paths
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;OS&lt;/th&gt;
&lt;th&gt;Path&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;macOS&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/etc/hosts&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Linux&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/etc/hosts&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Windows&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C:\Windows\System32\drivers\etc\hosts&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On Unix systems &lt;code&gt;/etc/hosts&lt;/code&gt; is often a symlink into the real file. Edit the path above. Do not hunt for a second copy in your home folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open it on macOS
&lt;/h2&gt;

&lt;p&gt;Terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or open it in your editor with elevated rights:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;code /etc/hosts
&lt;span class="c"&gt;# or&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;vim /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save, then flush DNS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;dscacheutil &lt;span class="nt"&gt;-flushcache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;killall &lt;span class="nt"&gt;-HUP&lt;/span&gt; mDNSResponder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finder will not let you edit &lt;code&gt;/etc&lt;/code&gt; casually. Use the terminal or an editor launched with &lt;code&gt;sudo&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open it on Windows
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open Notepad &lt;strong&gt;as Administrator&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;File → Open&lt;/li&gt;
&lt;li&gt;Go to &lt;code&gt;C:\Windows\System32\drivers\etc\&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Change the file type filter to &lt;strong&gt;All Files&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Open &lt;code&gt;hosts&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Without admin rights Windows will open the file but refuse to save.&lt;/p&gt;

&lt;p&gt;Then flush DNS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;ipconfig&lt;/span&gt; &lt;span class="na"&gt;/flushdns
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Open it on Linux
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/hosts
&lt;span class="c"&gt;# or&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;vim /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Flush depends on the stack. Common options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;resolvectl flush-caches
&lt;span class="c"&gt;# or&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemd-resolve &lt;span class="nt"&gt;--flush-caches&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What a normal line looks like
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;127.0.0.1   localhost
127.0.0.1   myapp.test
# 203.0.113.10  staging.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rules that save time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IP first, hostname second&lt;/li&gt;
&lt;li&gt;Spaces or tabs both work&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;#&lt;/code&gt; comments out the rest of the line&lt;/li&gt;
&lt;li&gt;One hostname per line is easier to read than a long list&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Quick check after editing
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# macOS / Linux&lt;/span&gt;
ping &lt;span class="nt"&gt;-c&lt;/span&gt; 1 myapp.test
&lt;span class="c"&gt;# or&lt;/span&gt;
getent hosts myapp.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Windows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;ping&lt;/span&gt; &lt;span class="kd"&gt;myapp&lt;/span&gt;.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the IP in the reply is wrong, the hosts line did not apply yet. Flush DNS and try again before changing the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Editing a copy in Downloads instead of the system file&lt;/li&gt;
&lt;li&gt;Saving without admin rights (Windows especially)&lt;/li&gt;
&lt;li&gt;Leaving a &lt;code&gt;#&lt;/code&gt; in front of the line you meant to enable&lt;/li&gt;
&lt;li&gt;Forgetting the DNS flush&lt;/li&gt;
&lt;li&gt;Using a real public TLD like &lt;code&gt;.com&lt;/code&gt; for local names when &lt;code&gt;.test&lt;/code&gt; would avoid surprises&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bookmark the path for your OS. You will need it again.&lt;/p&gt;




&lt;p&gt;If you switch hosts a lot, a small desktop manager helps keep profiles and DNS flush in one place: &lt;a href="https://www.locahl.app/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=hosts-series" rel="noopener noreferrer"&gt;Locahl&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to switch local and staging domains with the hosts file</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Thu, 16 Jul 2026 21:53:52 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/how-to-switch-local-and-staging-domains-with-the-hosts-file-4aj7</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/how-to-switch-local-and-staging-domains-with-the-hosts-file-4aj7</guid>
      <description>&lt;p&gt;You want &lt;code&gt;shop.test&lt;/code&gt; on localhost during the day, then the real client domain pointed at staging, then maybe the same domain pointed at a new server before DNS moves.&lt;/p&gt;

&lt;p&gt;You do not need dnsmasq for that. You need a clean way to switch mappings without leaving three conflicting lines in &lt;code&gt;/etc/hosts&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why one big hosts file fails
&lt;/h2&gt;

&lt;p&gt;After a few months it often looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;127.0.0.1   shop.test
127.0.0.1   api.shop.test
# 203.0.113.10  www.client.com
10.0.0.5    www.client.com
127.0.0.1   www.client.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same hostname, several intentions. The browser will not tell you which line won. It just resolves something.&lt;/p&gt;

&lt;p&gt;Comments help for a day. They do not help when you are tired and switching contexts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use profiles instead of comments
&lt;/h2&gt;

&lt;p&gt;Keep separate files. Only one is active at a time for a given hostname.&lt;/p&gt;

&lt;p&gt;Example layout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/dev/hosts-profiles/
  local
  staging
  cutover
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;local&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;127.0.0.1   shop.test
127.0.0.1   api.shop.test
127.0.0.1   admin.shop.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;staging&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;203.0.113.40   www.client.com
203.0.113.40   api.client.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;cutover&lt;/strong&gt; (pre-DNS migration test)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;198.51.100.20   www.client.com
198.51.100.20   api.client.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Apply a profile
&lt;/h2&gt;

&lt;p&gt;macOS / Linux:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;PROFILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;staging
&lt;span class="nb"&gt;sudo cp&lt;/span&gt; /etc/hosts &lt;span class="s2"&gt;"/etc/hosts.bak.&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt; +%Y%m%d-%H%M%S&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;sudo cp&lt;/span&gt; ~/dev/hosts-profiles/&lt;span class="nv"&gt;$PROFILE&lt;/span&gt; /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then flush DNS for your OS.&lt;/p&gt;

&lt;p&gt;Windows: same idea. Keep profile files, back up the live hosts file, copy the profile over:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="n"&gt;C&lt;/span&gt;:\&lt;span class="n"&gt;Windows&lt;/span&gt;\&lt;span class="n"&gt;System32&lt;/span&gt;\&lt;span class="n"&gt;drivers&lt;/span&gt;\&lt;span class="n"&gt;etc&lt;/span&gt;\&lt;span class="n"&gt;hosts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;ipconfig&lt;/span&gt; &lt;span class="na"&gt;/flushdns
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Small bash helper
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-euo&lt;/span&gt; pipefail
&lt;span class="nv"&gt;PROFILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;:?usage:&lt;span class="p"&gt; hosts-use &amp;lt;profile&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nv"&gt;SRC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/dev/hosts-profiles/&lt;/span&gt;&lt;span class="nv"&gt;$PROFILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SRC&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"missing &lt;/span&gt;&lt;span class="nv"&gt;$SRC&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;exit &lt;/span&gt;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;sudo cp&lt;/span&gt; /etc/hosts &lt;span class="s2"&gt;"/etc/hosts.bak.&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt; +%Y%m%d-%H%M%S&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;sudo cp&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SRC&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; /etc/hosts

&lt;span class="c"&gt;# macOS. Swap this block on Windows/Linux.&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;dscacheutil &lt;span class="nt"&gt;-flushcache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;killall &lt;span class="nt"&gt;-HUP&lt;/span&gt; mDNSResponder
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Active hosts profile: &lt;/span&gt;&lt;span class="nv"&gt;$PROFILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./hosts-use &lt;span class="nb"&gt;local&lt;/span&gt;
./hosts-use staging
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Optional: base file + project overlay
&lt;/h2&gt;

&lt;p&gt;If you want personal localhost names plus project-specific domains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/dev/hosts-profiles/
  _base
  project-shop-local
  project-shop-staging
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; ~/dev/hosts-profiles/_base &lt;span class="se"&gt;\&lt;/span&gt;
    ~/dev/hosts-profiles/project-shop-staging &lt;span class="se"&gt;\&lt;/span&gt;
  | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/hosts &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep &lt;code&gt;_base&lt;/code&gt; small. Put production hostnames only in the project overlay so they are easy to turn off.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-DNS cutover checklist
&lt;/h2&gt;

&lt;p&gt;This is one of the best uses of hosts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Put the production hostnames on the new server IP in a &lt;code&gt;cutover&lt;/code&gt; profile&lt;/li&gt;
&lt;li&gt;Apply the profile and flush DNS&lt;/li&gt;
&lt;li&gt;Test login, cookies, HTTPS, redirects, anything that depends on the Host header&lt;/li&gt;
&lt;li&gt;Switch back when you are done&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Write the rollback next to the migration checklist. You will want it on cutover night.&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker caveat
&lt;/h2&gt;

&lt;p&gt;Hosts on your laptop affect the browser on your laptop.&lt;/p&gt;

&lt;p&gt;Processes inside containers usually use Docker DNS, not your host &lt;code&gt;/etc/hosts&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browser to &lt;code&gt;shop.test&lt;/code&gt; on the host: host hosts file&lt;/li&gt;
&lt;li&gt;Container to another container: Compose service names or &lt;code&gt;extra_hosts&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not debug the wrong layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  After every switch
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# What does the OS resolve?&lt;/span&gt;
getent hosts www.client.com
&lt;span class="c"&gt;# macOS alternative:&lt;/span&gt;
&lt;span class="c"&gt;# dscacheutil -q host -a name www.client.com&lt;/span&gt;

&lt;span class="c"&gt;# What is in the file?&lt;/span&gt;
&lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"www.client.com"&lt;/span&gt; /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the terminal IP is wrong, fix hosts first. Do not dig into the app yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  When hosts profiles stop being enough
&lt;/h2&gt;

&lt;p&gt;Move to dnsmasq, CoreDNS, or company DNS when you need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;lots of wildcards&lt;/li&gt;
&lt;li&gt;many services added every week&lt;/li&gt;
&lt;li&gt;one shared dynamic map for a whole team&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Until then, separate profile files beat a single commented hosts file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with three files
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;local&lt;/code&gt; for your &lt;code&gt;.test&lt;/code&gt; domains&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;staging&lt;/code&gt; for client staging IPs&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cutover&lt;/code&gt; left empty until migration week&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Switch the whole file, flush DNS, verify in the terminal. That is the whole method.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>docker</category>
    </item>
    <item>
      <title>How to edit /etc/hosts without breaking your local setup</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Thu, 16 Jul 2026 21:49:08 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/how-to-edit-etchosts-without-breaking-your-local-setup-2hf7</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/how-to-edit-etchosts-without-breaking-your-local-setup-2hf7</guid>
      <description>&lt;p&gt;Most people open &lt;code&gt;/etc/hosts&lt;/code&gt;, change one line, refresh the browser, and hope.&lt;/p&gt;

&lt;p&gt;That works until it does not. Then you spend twenty minutes on &lt;code&gt;Permission denied&lt;/code&gt;, a forgotten DNS flush, or a commented line from last week that is still active.&lt;/p&gt;

&lt;p&gt;This is a simple workflow that keeps hosts edits boring.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the hosts file does
&lt;/h2&gt;

&lt;p&gt;When your machine resolves a name like &lt;code&gt;myapp.test&lt;/code&gt;, it can use a local override before public DNS.&lt;/p&gt;

&lt;p&gt;Common cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Point &lt;code&gt;myapp.test&lt;/code&gt; to &lt;code&gt;127.0.0.1&lt;/code&gt; for local work&lt;/li&gt;
&lt;li&gt;Point a real domain at a staging IP before DNS cutover&lt;/li&gt;
&lt;li&gt;Temporarily block a host with &lt;code&gt;0.0.0.0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Give services readable names instead of raw IPs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The idea is simple. The mess comes from how people edit and apply it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A workflow that holds up
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Do not treat &lt;code&gt;/etc/hosts&lt;/code&gt; as your only copy
&lt;/h3&gt;

&lt;p&gt;Keep a file you own:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/dev/hosts/personal.hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or one file per project / client. Edit that. Apply it on purpose.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Edit the copy, then copy it into place
&lt;/h3&gt;

&lt;p&gt;macOS / Linux:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;code ~/dev/hosts/personal.hosts
&lt;span class="nb"&gt;sudo cp&lt;/span&gt; /etc/hosts &lt;span class="s2"&gt;"/etc/hosts.bak.&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt; +%Y%m%d-%H%M%S&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;sudo cp&lt;/span&gt; ~/dev/hosts/personal.hosts /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Windows: edit your copy, back up the live file, then replace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="n"&gt;C&lt;/span&gt;:\&lt;span class="n"&gt;Windows&lt;/span&gt;\&lt;span class="n"&gt;System32&lt;/span&gt;\&lt;span class="n"&gt;drivers&lt;/span&gt;\&lt;span class="n"&gt;etc&lt;/span&gt;\&lt;span class="n"&gt;hosts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You need admin rights for the live file. That is normal.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Flush DNS every time you apply
&lt;/h3&gt;

&lt;p&gt;Make this part of the apply step, not a later panic search.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;macOS&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;dscacheutil &lt;span class="nt"&gt;-flushcache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;killall &lt;span class="nt"&gt;-HUP&lt;/span&gt; mDNSResponder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Windows (Admin)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;ipconfig&lt;/span&gt; &lt;span class="na"&gt;/flushdns
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Linux (systemd-resolved)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;resolvectl flush-caches
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Verify in the terminal before the browser
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ping &lt;span class="nt"&gt;-c&lt;/span&gt; 1 myapp.test
&lt;span class="c"&gt;# Linux:&lt;/span&gt;
getent hosts myapp.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Right IP in the terminal, wrong page in the browser? Stop rewriting hosts. Look at browser DNS, HTTPS, redirects, or HSTS.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Avoid two active lines for the same hostname
&lt;/h3&gt;

&lt;p&gt;This breaks people constantly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10.0.0.5    www.client.com
127.0.0.1   www.client.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pick one. Comment the other, or better, keep separate profile files and swap the whole file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example: local frontend + API
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;127.0.0.1   shop.test
127.0.0.1   api.shop.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Frontend env:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NEXT_PUBLIC_API_URL=http://api.shop.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;API env:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;APP_URL=http://api.shop.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Apply hosts&lt;/li&gt;
&lt;li&gt;Flush DNS&lt;/li&gt;
&lt;li&gt;Confirm with &lt;code&gt;ping&lt;/code&gt; / &lt;code&gt;getent&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Open the browser&lt;/li&gt;
&lt;li&gt;Only then debug CORS, cookies, or TLS&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hosts bugs and app bugs look the same in a tab. Split them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Team onboarding
&lt;/h2&gt;

&lt;p&gt;If your README says “paste these 12 lines into hosts,” configs will drift.&lt;/p&gt;

&lt;p&gt;Better:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Commit a &lt;code&gt;hosts.example&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add a short apply script&lt;/li&gt;
&lt;li&gt;Say which environment the file is for (&lt;code&gt;local&lt;/code&gt;, &lt;code&gt;stEgin&lt;/code&gt;`, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Goal: new laptop works in a few minutes, not after three Slack threads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Short version
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Edit a file you own
&lt;/li&gt;
&lt;li&gt;Back up, then copy into the system hosts path
&lt;/li&gt;
&lt;li&gt;Flush DNS
&lt;/li&gt;
&lt;li&gt;Check resolution in the terminal
&lt;/li&gt;
&lt;li&gt;Keep one active mapping per hostname
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That is enough for most local and staging work. If you are changing hosts several times a day across clients, automate the swap with a script or a small hosts manager. The process above still matters either way.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to flush DNS on Mac, Windows, and Linux</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Thu, 16 Jul 2026 21:28:55 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/how-to-flush-dns-on-mac-windows-and-linux-285e</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/how-to-flush-dns-on-mac-windows-and-linux-285e</guid>
      <description>&lt;h1&gt;
  
  
  How to flush DNS on Mac, Windows, and Linux
&lt;/h1&gt;

&lt;p&gt;You changed your hosts file. The line looks right. The browser still loads the old IP.&lt;/p&gt;

&lt;p&gt;That is usually DNS cache, not a bad hosts entry.&lt;/p&gt;

&lt;p&gt;Flush the OS cache first. Check with a terminal command. Only then blame the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  macOS
&lt;/h2&gt;

&lt;p&gt;Works on recent macOS (Sequoia, Sonoma, Ventura, and neighbors):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;dscacheutil &lt;span class="nt"&gt;-flushcache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;killall &lt;span class="nt"&gt;-HUP&lt;/span&gt; mDNSResponder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enter your password. No output is normal.&lt;/p&gt;

&lt;p&gt;Still wrong after that?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Quit the browser fully and reopen it&lt;/li&gt;
&lt;li&gt;In Chrome, open &lt;code&gt;chrome://net-internals/#dns&lt;/code&gt; and click &lt;strong&gt;Clear host cache&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Re-check the hosts line (typo, or a &lt;code&gt;#&lt;/code&gt; that comments it out)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Windows 10 and 11
&lt;/h2&gt;

&lt;p&gt;Open Command Prompt or PowerShell &lt;strong&gt;as Administrator&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;ipconfig&lt;/span&gt; &lt;span class="na"&gt;/flushdns
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or in PowerShell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Clear-DnsClientCache&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hosts file location if you need it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Windows\System32\drivers\etc\hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Linux
&lt;/h2&gt;

&lt;p&gt;It depends which resolver is caching.&lt;/p&gt;

&lt;h3&gt;
  
  
  systemd-resolved (common on Ubuntu and Fedora)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;resolvectl flush-caches
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On older setups:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemd-resolve &lt;span class="nt"&gt;--flush-caches&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  nscd
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart nscd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  dnsmasq
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart dnsmasq
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hosts file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Check the result outside the browser
&lt;/h2&gt;

&lt;p&gt;Do this before you keep refreshing Chrome.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;macOS&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dscacheutil &lt;span class="nt"&gt;-q&lt;/span&gt; host &lt;span class="nt"&gt;-a&lt;/span&gt; name myapp.test
ping &lt;span class="nt"&gt;-c&lt;/span&gt; 1 myapp.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Linux&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;getent hosts myapp.test
ping &lt;span class="nt"&gt;-c&lt;/span&gt; 1 myapp.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Windows&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;ping&lt;/span&gt; &lt;span class="kd"&gt;myapp&lt;/span&gt;.test
&lt;span class="nb"&gt;nslookup&lt;/span&gt; &lt;span class="kd"&gt;myapp&lt;/span&gt;.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the terminal shows the right IP and the browser does not, the OS hosts file is probably fine. Clear browser DNS, or check HTTPS / HSTS / Secure DNS (DoH).&lt;/p&gt;

&lt;h2&gt;
  
  
  If you flushed DNS and it still fails
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Browser wrong, terminal correct&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Browser cache, Secure DNS, or a certificate / redirect issue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Terminal wrong too&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Typo in hosts, wrong file, line commented with &lt;code&gt;#&lt;/code&gt;, or you edited a copy that never got applied.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Works, then breaks after reboot&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Something rewrites hosts, or a VPN / DNS tool takes over.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Only one browser fails&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
That browser has its own DNS settings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Works on normal Wi-Fi, fails on VPN&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
VPN DNS is ignoring or overriding local hosts.&lt;/p&gt;

&lt;p&gt;Also check AdGuard, NextDNS, Cloudflare WARP, Pi-hole, and Tailscale MagicDNS. They can make a correct hosts change look like it did nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hosts syntax worth double-checking
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="m"&gt;127&lt;/span&gt;.&lt;span class="m"&gt;0&lt;/span&gt;.&lt;span class="m"&gt;0&lt;/span&gt;.&lt;span class="m"&gt;1&lt;/span&gt;   &lt;span class="n"&gt;myapp&lt;/span&gt;.&lt;span class="n"&gt;test&lt;/span&gt;
&lt;span class="m"&gt;127&lt;/span&gt;.&lt;span class="m"&gt;0&lt;/span&gt;.&lt;span class="m"&gt;0&lt;/span&gt;.&lt;span class="m"&gt;1&lt;/span&gt;   &lt;span class="n"&gt;api&lt;/span&gt;.&lt;span class="n"&gt;myapp&lt;/span&gt;.&lt;span class="n"&gt;test&lt;/span&gt;
&lt;span class="c"&gt;# 10.0.0.5  staging.myapp.test
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;IP first, then hostname(s)&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;#&lt;/code&gt; disables the rest of the line&lt;/li&gt;
&lt;li&gt;Keep the line clean (no random trailing junk)&lt;/li&gt;
&lt;li&gt;IPv6 localhost is &lt;code&gt;::1&lt;/code&gt; when you need it&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Copy-paste
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# macOS&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;dscacheutil &lt;span class="nt"&gt;-flushcache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;killall &lt;span class="nt"&gt;-HUP&lt;/span&gt; mDNSResponder

&lt;span class="c"&gt;# Windows (Admin)&lt;/span&gt;
ipconfig /flushdns

&lt;span class="c"&gt;# Linux (systemd-resolved)&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;resolvectl flush-caches
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Edit hosts, flush DNS, verify in the terminal. That order fixes most of these tickets.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>devops</category>
      <category>dns</category>
    </item>
  </channel>
</rss>
