<?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>Free hosts file editor alternatives: SwitchHosts, PowerToys, Terminal, and when to pay</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Mon, 20 Jul 2026 18:55:31 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/free-hosts-file-editor-alternatives-switchhosts-powertoys-terminal-and-when-to-pay-4m2l</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/free-hosts-file-editor-alternatives-switchhosts-powertoys-terminal-and-when-to-pay-4m2l</guid>
      <description>&lt;p&gt;You can manage the hosts file without paying anyone. Plenty of people should.&lt;/p&gt;

&lt;p&gt;This is the free stack, plus the one case where a one-time paid app is rational.&lt;/p&gt;

&lt;h2&gt;
  
  
  Free options that actually work
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. SwitchHosts
&lt;/h3&gt;

&lt;p&gt;Best free GUI for most developers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Win / Mac / Linux&lt;/li&gt;
&lt;li&gt;Profiles and groups&lt;/li&gt;
&lt;li&gt;Open source&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cost of free: flush DNS yourself; live with the Electron-style desktop footprint.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. PowerToys Hosts File Editor (Windows)
&lt;/h3&gt;

&lt;p&gt;Best free "just edit the file" tool on Windows if PowerToys is already installed.&lt;/p&gt;

&lt;p&gt;Cost of free: weak multi-environment story, Windows only.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Terminal / text editor + sudo
&lt;/h3&gt;

&lt;p&gt;Best free option for people who already script their machines.&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;span class="c"&gt;# then flush DNS for your OS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or keep profile files and copy them into place.&lt;/p&gt;

&lt;p&gt;Cost of free: no seatbelts unless you add backups and checks.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Built-in Notepad / TextEdit (elevated)
&lt;/h3&gt;

&lt;p&gt;Works. Painful. Easy to edit a copy that is not the system file.&lt;/p&gt;

&lt;p&gt;Use only for rare one-line changes.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Gas Mask
&lt;/h3&gt;

&lt;p&gt;Free historically. Not a free &lt;em&gt;recommendation&lt;/em&gt; in 2026. Unmaintained.&lt;/p&gt;

&lt;h2&gt;
  
  
  Paid option worth mentioning
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Locahl
&lt;/h3&gt;

&lt;p&gt;Not free. One-time purchase. Cross-platform.&lt;/p&gt;

&lt;p&gt;You pay for automatic DNS flush, backups, and a more guided multi-environment UI.&lt;/p&gt;

&lt;p&gt;Pay only if the free tools are costing you real time (stale DNS, broken hosts, no shared OS story).&lt;/p&gt;

&lt;h2&gt;
  
  
  Free vs paid decision
&lt;/h2&gt;

&lt;p&gt;Stay free if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you edit hosts weekly or less&lt;/li&gt;
&lt;li&gt;you remember DNS flush&lt;/li&gt;
&lt;li&gt;OSS or zero budget is the rule&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Consider paid if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you switch environments daily&lt;/li&gt;
&lt;li&gt;teammates keep hitting Permission denied / stale cache&lt;/li&gt;
&lt;li&gt;you want one tool on Windows, macOS, and Linux&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Suggested free setups
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Solo, mixed OS, free only&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SwitchHosts + a shell alias for DNS flush.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Windows-only, rare edits&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;PowerToys Hosts + &lt;code&gt;ipconfig /flushdns&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Power users&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;~/hosts-profiles/local
~/hosts-profiles/staging
./hosts-use &amp;lt;name&amp;gt;   # copies + flushes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Do not confuse "free editor" with "safe workflow"
&lt;/h2&gt;

&lt;p&gt;Every free path still needs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Backup before big edits&lt;/li&gt;
&lt;li&gt;One active mapping per hostname&lt;/li&gt;
&lt;li&gt;DNS flush after apply&lt;/li&gt;
&lt;li&gt;Terminal verification before blaming the app&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Those four steps matter more than the logo on the window.&lt;/p&gt;




&lt;p&gt;Free default: &lt;a href="https://github.com/oldj/SwitchHosts" rel="noopener noreferrer"&gt;SwitchHosts&lt;/a&gt;. If free is costing you time on flush and backups, &lt;a href="https://www.locahl.app/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=alt-free" rel="noopener noreferrer"&gt;Locahl&lt;/a&gt; is the paid cross-platform alternative.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>PowerToys Hosts File Editor alternative (when you need more than an edit box)</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Mon, 20 Jul 2026 18:42:13 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/powertoys-hosts-file-editor-alternative-when-you-need-more-than-an-edit-box-3kd3</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/powertoys-hosts-file-editor-alternative-when-you-need-more-than-an-edit-box-3kd3</guid>
      <description>&lt;p&gt;Microsoft PowerToys includes a Hosts File Editor. It is free, signed, and already on many Windows machines.&lt;/p&gt;

&lt;p&gt;It is a good editor. It is not always a good hosts &lt;em&gt;workflow&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What PowerToys Hosts does well
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Opens the real Windows hosts file with the right elevation story&lt;/li&gt;
&lt;li&gt;Simpler than hunting &lt;code&gt;C:\Windows\System32\drivers\etc\hosts&lt;/code&gt; in Notepad&lt;/li&gt;
&lt;li&gt;Free if you already use PowerToys&lt;/li&gt;
&lt;li&gt;Fine for a handful of static lines&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When people search for an alternative
&lt;/h2&gt;

&lt;h3&gt;
  
  
  You switch environments all day
&lt;/h3&gt;

&lt;p&gt;Local shop in the morning, client staging after lunch, cutover IP at night. An editor with one big file turns into commented chaos.&lt;/p&gt;

&lt;p&gt;You want named profiles you can toggle, not archaeology in comments.&lt;/p&gt;

&lt;h3&gt;
  
  
  You also use a Mac or Linux box
&lt;/h3&gt;

&lt;p&gt;PowerToys is Windows-only. Your hosts process should not fork by OS if the team shares domain names.&lt;/p&gt;

&lt;h3&gt;
  
  
  You forget &lt;code&gt;ipconfig /flushdns&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Same bug as every other hosts tool without auto flush: file correct, browser wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternatives on Windows
&lt;/h2&gt;

&lt;h3&gt;
  
  
  SwitchHosts
&lt;/h3&gt;

&lt;p&gt;Free, open source, profiles, also runs on Mac/Linux.&lt;/p&gt;

&lt;p&gt;Best PowerToys alternative when you need environment switching and maybe multi-OS later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Locahl
&lt;/h3&gt;

&lt;p&gt;Paid one-time. Windows, macOS, Linux. Automatic DNS flush and backups.&lt;/p&gt;

&lt;p&gt;Best when PowerToys feels too manual and you want the apply step to include flush + safety.&lt;/p&gt;

&lt;h3&gt;
  
  
  Notepad as Administrator
&lt;/h3&gt;

&lt;p&gt;Still works. Still easy to save the wrong copy or skip flush.&lt;/p&gt;

&lt;p&gt;Only fine for rare edits.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hostly / CLI hosts switchers
&lt;/h3&gt;

&lt;p&gt;Interesting if you want &lt;code&gt;hosts open Dev&lt;/code&gt; from scripts. Check that the project is maintained before you depend on it in CI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feature snapshot (Windows view)
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Profiles&lt;/th&gt;
&lt;th&gt;Auto flush&lt;/th&gt;
&lt;th&gt;Multi-OS&lt;/th&gt;
&lt;th&gt;Cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;PowerToys Hosts&lt;/td&gt;
&lt;td&gt;Limited&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SwitchHosts&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Locahl&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;One-time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Notepad Admin&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Manual&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Practical upgrade path
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Keep PowerToys for now if you only have 5 stable lines&lt;/li&gt;
&lt;li&gt;When you start commenting &lt;code&gt;/ staging&lt;/code&gt; blocks every week, move to SwitchHosts or Locahl&lt;/li&gt;
&lt;li&gt;Always backup before the first import&lt;/li&gt;
&lt;li&gt;After every apply:
&lt;/li&gt;
&lt;/ol&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;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 PowerToys is "just an editor," that is not an insult. Editors are useful. Managers exist for the days the editor is not enough.&lt;/p&gt;




&lt;p&gt;If you need profile switching and automatic DNS flush beyond PowerToys, try &lt;a href="https://www.locahl.app/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=alt-powertoys" rel="noopener noreferrer"&gt;Locahl&lt;/a&gt; on Windows (and Mac/Linux when you need them). SwitchHosts stays the free profile-based option.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>productivity</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>iHosts alternative for Mac developers who need Windows or Linux too</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Mon, 20 Jul 2026 18:34:42 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/ihosts-alternative-for-mac-developers-who-need-windows-or-linux-too-m2e</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/ihosts-alternative-for-mac-developers-who-need-windows-or-linux-too-m2e</guid>
      <description>&lt;p&gt;iHosts is a clean macOS hosts editor. If your world is only Apple hardware, it can be enough.&lt;/p&gt;

&lt;p&gt;The search for an iHosts alternative usually means one of three things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You need the same tool on a Windows or Linux machine&lt;/li&gt;
&lt;li&gt;You want a different price / feature mix&lt;/li&gt;
&lt;li&gt;You are standardizing a mixed OS team&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What iHosts is good at
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Native Mac UI&lt;/li&gt;
&lt;li&gt;Visual editing of hosts entries&lt;/li&gt;
&lt;li&gt;DNS flush support in the Mac workflow&lt;/li&gt;
&lt;li&gt;Fine for solo Mac local development&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Where it stops fitting
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;No help for the teammate on Windows&lt;/li&gt;
&lt;li&gt;No Linux desktop parity&lt;/li&gt;
&lt;li&gt;Harder to document "everyone use the same hosts app" in a mixed stack company&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your README says "install iHosts" and half the team cannot, you do not have a shared tool. You have a Mac preference.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternatives
&lt;/h2&gt;

&lt;h3&gt;
  
  
  SwitchHosts
&lt;/h3&gt;

&lt;p&gt;Free, open source, Win / Mac / Linux. Closest free iHosts alternative when OS coverage matters.&lt;/p&gt;

&lt;p&gt;Tradeoff: flush DNS yourself after switches.&lt;/p&gt;

&lt;h3&gt;
  
  
  Locahl
&lt;/h3&gt;

&lt;p&gt;Paid one-time, Win / Mac / Linux. Visual environments, automatic DNS flush, backups.&lt;/p&gt;

&lt;p&gt;Tradeoff: not free. Worth it if the team already loses time to stale DNS and broken hosts edits.&lt;/p&gt;

&lt;h3&gt;
  
  
  Gas Mask
&lt;/h3&gt;

&lt;p&gt;Do not use as your iHosts replacement. Abandoned path.&lt;/p&gt;

&lt;h3&gt;
  
  
  Terminal profiles
&lt;/h3&gt;

&lt;p&gt;Works on Mac and everywhere else. Same scripts for the whole team.&lt;/p&gt;

&lt;p&gt;Tradeoff: no GUI. Higher chance of drift without discipline.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stay on iHosts
&lt;/h3&gt;

&lt;p&gt;Valid if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;every developer is on macOS&lt;/li&gt;
&lt;li&gt;your environments are simple&lt;/li&gt;
&lt;li&gt;you are fine maintaining Mac-only docs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Migration checklist (iHosts → cross-platform)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Export or copy current hosts content&lt;/li&gt;
&lt;li&gt;Backup &lt;code&gt;/etc/hosts&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Install SwitchHosts or Locahl on each OS you care about&lt;/li&gt;
&lt;li&gt;Recreate &lt;code&gt;local&lt;/code&gt; / &lt;code&gt;staging&lt;/code&gt; profiles with identical hostnames&lt;/li&gt;
&lt;li&gt;On Mac, confirm flush still happens (auto or script)&lt;/li&gt;
&lt;li&gt;On Windows, confirm Admin write + &lt;code&gt;ipconfig /flushdns&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Verify with terminal before browser
&lt;/li&gt;
&lt;/ol&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 api.myapp.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Identical hostnames across machines matter more than identical apps. The app just reduces mistakes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pick by constraint
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Constraint&lt;/th&gt;
&lt;th&gt;Pick&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Free + multi-OS&lt;/td&gt;
&lt;td&gt;SwitchHosts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multi-OS + auto flush&lt;/td&gt;
&lt;td&gt;Locahl&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mac-only forever&lt;/td&gt;
&lt;td&gt;iHosts is fine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scriptable everywhere&lt;/td&gt;
&lt;td&gt;Terminal profiles&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;If you outgrew a Mac-only hosts app, &lt;a href="https://www.locahl.app/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=alt-ihosts" rel="noopener noreferrer"&gt;Locahl&lt;/a&gt; covers Windows, macOS, and Linux with automatic DNS flush. SwitchHosts is the free cross-platform option.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Best hosts file managers in 2026: SwitchHosts, Gas Mask, and the rest</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Mon, 20 Jul 2026 18:20:12 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/best-hosts-file-managers-in-2026-switchhosts-gas-mask-and-the-rest-4g8h</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/best-hosts-file-managers-in-2026-switchhosts-gas-mask-and-the-rest-4g8h</guid>
      <description>&lt;p&gt;If you edit &lt;code&gt;/etc/hosts&lt;/code&gt; more than once a week, a dedicated manager beats Notepad-as-Admin.&lt;/p&gt;

&lt;p&gt;Here is a clear map of the usual options in 2026, including the abandoned ones people still Google.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who this list is for
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Local domains like &lt;code&gt;app.test&lt;/code&gt; instead of &lt;code&gt;localhost:3000&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Staging / pre-DNS cutover tests&lt;/li&gt;
&lt;li&gt;Focus-mode site blocking via &lt;code&gt;0.0.0.0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Teams that need the same workflow on Windows, macOS, and Linux&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The short list
&lt;/h2&gt;

&lt;h3&gt;
  
  
  SwitchHosts — best free default
&lt;/h3&gt;

&lt;p&gt;Open source, cross-platform, profile switching, remote lists.&lt;/p&gt;

&lt;p&gt;Choose it when price is zero and you accept manual DNS flush.&lt;/p&gt;

&lt;h3&gt;
  
  
  Locahl — best polished paid default
&lt;/h3&gt;

&lt;p&gt;Cross-platform desktop app. Automatic DNS flush, backups, visual multi-environment flow. One-time purchase.&lt;/p&gt;

&lt;p&gt;Choose it when you want fewer "why is the browser still wrong?" loops.&lt;/p&gt;

&lt;h3&gt;
  
  
  Gas Mask — legacy Mac only
&lt;/h3&gt;

&lt;p&gt;Historically popular. Not maintained for modern macOS.&lt;/p&gt;

&lt;p&gt;Do not start a new setup on Gas Mask. If you are on it, migrate.&lt;/p&gt;

&lt;h3&gt;
  
  
  iHosts — Mac-native GUI
&lt;/h3&gt;

&lt;p&gt;Solid if your whole team is on macOS and you want a native editor.&lt;/p&gt;

&lt;p&gt;Skip it if you need Windows or Linux parity.&lt;/p&gt;

&lt;h3&gt;
  
  
  PowerToys Hosts File Editor — Windows built-in-ish
&lt;/h3&gt;

&lt;p&gt;Free with PowerToys. Good for quick edits.&lt;/p&gt;

&lt;p&gt;Not a full multi-profile manager like SwitchHosts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Terminal + profile files — best for scripters
&lt;/h3&gt;

&lt;p&gt;Copy &lt;code&gt;~/hosts-profiles/$ENV&lt;/code&gt; over &lt;code&gt;/etc/hosts&lt;/code&gt;, flush, verify.&lt;/p&gt;

&lt;p&gt;Maximum control. You own backups and mistakes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hostly / CLI-first tools — automation angle
&lt;/h3&gt;

&lt;p&gt;Useful when you need &lt;code&gt;hosts switch&lt;/code&gt; inside scripts or CI, especially on Windows. Check maintenance and OS support before standardizing a team on one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparison table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Platforms&lt;/th&gt;
&lt;th&gt;Cost&lt;/th&gt;
&lt;th&gt;Maintained&lt;/th&gt;
&lt;th&gt;Profiles&lt;/th&gt;
&lt;th&gt;Auto DNS flush&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;SwitchHosts&lt;/td&gt;
&lt;td&gt;Win / Mac / Linux&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Locahl&lt;/td&gt;
&lt;td&gt;Win / Mac / Linux&lt;/td&gt;
&lt;td&gt;One-time&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gas Mask&lt;/td&gt;
&lt;td&gt;Mac&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;iHosts&lt;/td&gt;
&lt;td&gt;Mac&lt;/td&gt;
&lt;td&gt;Paid&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PowerToys Hosts&lt;/td&gt;
&lt;td&gt;Windows&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Basic&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Terminal profiles&lt;/td&gt;
&lt;td&gt;All&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;DIY&lt;/td&gt;
&lt;td&gt;DIY&lt;/td&gt;
&lt;td&gt;DIY&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Decision tree
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Need free + cross-platform? → SwitchHosts&lt;/li&gt;
&lt;li&gt;Need auto flush + backups + cross-platform? → Locahl&lt;/li&gt;
&lt;li&gt;Mac only + native UI? → iHosts&lt;/li&gt;
&lt;li&gt;Windows only + already use PowerToys? → PowerToys Hosts&lt;/li&gt;
&lt;li&gt;Live in the shell? → profile files&lt;/li&gt;
&lt;li&gt;Still on Gas Mask? → migrate to 1, 2, or 3 this week&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Features that matter more than branding
&lt;/h2&gt;

&lt;p&gt;Whatever you pick, insist on:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Easy elevated write to the real hosts path&lt;/li&gt;
&lt;li&gt;Clear active vs inactive mappings&lt;/li&gt;
&lt;li&gt;Backup before overwrite&lt;/li&gt;
&lt;li&gt;DNS flush in the apply path (app or script)&lt;/li&gt;
&lt;li&gt;Terminal verification habit (&lt;code&gt;ping&lt;/code&gt; / &lt;code&gt;getent&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Fancy UI without those five still wastes your afternoon.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related reads
&lt;/h2&gt;

&lt;p&gt;If you are replacing a specific tool, start here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Gas Mask alternatives&lt;/li&gt;
&lt;li&gt;SwitchHosts alternative&lt;/li&gt;
&lt;li&gt;PowerToys Hosts File Editor alternative&lt;/li&gt;
&lt;li&gt;iHosts alternative&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same market. Different search intent.&lt;/p&gt;




&lt;p&gt;For a cross-platform hosts manager with automatic DNS flush and backups, see &lt;a href="https://www.locahl.app/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=alt-roundup" rel="noopener noreferrer"&gt;Locahl&lt;/a&gt;. SwitchHosts remains the best free open-source pick.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Looking for a SwitchHosts alternative? Here is what actually differs</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Mon, 20 Jul 2026 16:13:13 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/looking-for-a-switchhosts-alternative-here-is-what-actually-differs-4nma</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/looking-for-a-switchhosts-alternative-here-is-what-actually-differs-4nma</guid>
      <description>&lt;p&gt;SwitchHosts is still the most common free hosts manager. It works. It is open source. It runs on Windows, macOS, and Linux.&lt;/p&gt;

&lt;p&gt;People search for a SwitchHosts alternative when something in the daily loop gets annoying: forgotten DNS flush, Electron footprint, or wanting clearer multi-environment switching.&lt;/p&gt;

&lt;p&gt;This is a practical comparison, not a takedown.&lt;/p&gt;

&lt;h2&gt;
  
  
  What SwitchHosts is great at
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Free and open source&lt;/li&gt;
&lt;li&gt;Profiles / groups you can toggle&lt;/li&gt;
&lt;li&gt;Remote hosts lists&lt;/li&gt;
&lt;li&gt;Cross-platform&lt;/li&gt;
&lt;li&gt;Active enough community for a niche tool&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If that covers your needs, stay. Free is a real feature.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why people look elsewhere
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. DNS flush is still your job
&lt;/h3&gt;

&lt;p&gt;Change a profile, refresh the browser, still on the old IP. Classic.&lt;/p&gt;

&lt;p&gt;You need an OS flush every time:&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;# 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;Tools that flush automatically remove a whole class of "is hosts broken?" mornings.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. You want stronger backups
&lt;/h3&gt;

&lt;p&gt;A bad paste into hosts can take down local resolution for half your stack. Automatic pre-change backups matter more than people admit until it happens once.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. You want a lighter or more guided UI
&lt;/h3&gt;

&lt;p&gt;SwitchHosts is capable. Some teams want fewer panels and a clearer "what is active right now?" signal when jumping between client projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternatives to SwitchHosts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Locahl
&lt;/h3&gt;

&lt;p&gt;Paid one-time desktop app (Windows, macOS, Linux).&lt;/p&gt;

&lt;p&gt;Same problem space: manage hosts visually, switch environments. Adds automatic DNS flush and backups.&lt;/p&gt;

&lt;p&gt;Pick it if SwitchHosts works but the manual flush / polish gap bothers you enough to pay once.&lt;/p&gt;

&lt;h3&gt;
  
  
  Terminal profiles
&lt;/h3&gt;

&lt;p&gt;Keep separate hosts files and copy the active one into place. Scriptable. Free.&lt;/p&gt;

&lt;p&gt;Pick it if you already live in the shell and do not want another desktop app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Gas Mask
&lt;/h3&gt;

&lt;p&gt;Mac-only legacy option. Do not migrate &lt;em&gt;to&lt;/em&gt; Gas Mask in 2026. Migrate &lt;em&gt;away&lt;/em&gt; from it.&lt;/p&gt;

&lt;h3&gt;
  
  
  iHosts
&lt;/h3&gt;

&lt;p&gt;macOS-focused GUI. Fine for Apple-only setups.&lt;/p&gt;

&lt;h3&gt;
  
  
  PowerToys Hosts File Editor
&lt;/h3&gt;

&lt;p&gt;Windows-only editor. Good for simple edits, weaker as a full SwitchHosts replacement if you depend on many named profiles.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hostly (and similar CLI-first tools)
&lt;/h3&gt;

&lt;p&gt;Newer Windows-oriented tools that advertise SwitchHosts import plus a CLI for scripts/CI. Worth a look if automation matters more than a polished cross-platform GUI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feature snapshot
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Need&lt;/th&gt;
&lt;th&gt;SwitchHosts&lt;/th&gt;
&lt;th&gt;Locahl&lt;/th&gt;
&lt;th&gt;Terminal&lt;/th&gt;
&lt;th&gt;PowerToys&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Win / Mac / Linux&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Win only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Profiles / environments&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;DIY&lt;/td&gt;
&lt;td&gt;Limited&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Auto DNS flush&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;DIY&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Auto backups&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;DIY&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Open source&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;Yes (PowerToys)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Should you switch?
&lt;/h2&gt;

&lt;p&gt;Stay on SwitchHosts if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;free / OSS is non-negotiable&lt;/li&gt;
&lt;li&gt;you remember to flush DNS&lt;/li&gt;
&lt;li&gt;profiles already match your workflow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Try an alternative if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you lose time to stale DNS every week&lt;/li&gt;
&lt;li&gt;you want safer undo after bad edits&lt;/li&gt;
&lt;li&gt;you share a Win/Mac/Linux team and want one consistent paid tool&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Migration tip
&lt;/h2&gt;

&lt;p&gt;Export or copy your SwitchHosts content first. Keep a raw &lt;code&gt;/etc/hosts&lt;/code&gt; backup. Import into the new tool. Verify with terminal resolution before you uninstall anything.&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="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;p&gt;Same checks you should already run with SwitchHosts.&lt;/p&gt;




&lt;p&gt;If automatic DNS flush and backups are the reason you are shopping, look at &lt;a href="https://www.locahl.app/en/alternatives/switchhosts?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=alt-switchhosts" rel="noopener noreferrer"&gt;Locahl&lt;/a&gt; as a SwitchHosts alternative. Keep SwitchHosts if free and OSS matter more.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>opensource</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Best Gas Mask alternatives in 2026 (hosts file managers)</title>
      <dc:creator>Locahl</dc:creator>
      <pubDate>Mon, 20 Jul 2026 15:57:50 +0000</pubDate>
      <link>https://dev.to/locahl_9bd77121e3d366f72f/best-gas-mask-alternatives-in-2026-hosts-file-managers-2mi3</link>
      <guid>https://dev.to/locahl_9bd77121e3d366f72f/best-gas-mask-alternatives-in-2026-hosts-file-managers-2mi3</guid>
      <description>&lt;p&gt;Gas Mask was the default Mac hosts app for years. Profiles, a simple UI, done.&lt;/p&gt;

&lt;p&gt;It is no longer a safe default. Maintenance stalled, and modern macOS versions are a gamble. If you still rely on it, pick a maintained alternative before the next OS upgrade breaks your workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Gas Mask did well
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Profile-based hosts switching on macOS&lt;/li&gt;
&lt;li&gt;Simple mental model: enable a set, apply&lt;/li&gt;
&lt;li&gt;Free&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What you still need from any replacement:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Edit &lt;code&gt;/etc/hosts&lt;/code&gt; without fighting permissions every time&lt;/li&gt;
&lt;li&gt;Switch local / staging / cutover maps cleanly&lt;/li&gt;
&lt;li&gt;Flush DNS after apply (or you will think the app is broken)&lt;/li&gt;
&lt;li&gt;Prefer something that still gets updates&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Alternatives worth considering
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. SwitchHosts (free, cross-platform)
&lt;/h3&gt;

&lt;p&gt;Open source. Windows, macOS, Linux. Profiles, remote hosts sources, tray switching.&lt;/p&gt;

&lt;p&gt;Best if you want free and you are fine flushing DNS yourself after changes.&lt;/p&gt;

&lt;p&gt;Gap: no automatic DNS flush. After every switch, run the OS flush command or you keep seeing the old IP in the browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Locahl (paid, cross-platform)
&lt;/h3&gt;

&lt;p&gt;Desktop app for Windows, macOS, and Linux. One-time purchase.&lt;/p&gt;

&lt;p&gt;Built around the same job as Gas Mask (visual hosts editing + environments) with automatic DNS flush and backups when you change entries.&lt;/p&gt;

&lt;p&gt;Best if you want Gas Mask’s simplicity without the abandoned-app risk, and you work on more than one OS.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. iHosts (macOS)
&lt;/h3&gt;

&lt;p&gt;Native Mac feel. Visual editor. Fine if you only care about Apple machines and like a Mac-only UI.&lt;/p&gt;

&lt;p&gt;Gap: not useful for a Windows/Linux teammate using the same workflow.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Terminal + profile files (free)
&lt;/h3&gt;

&lt;p&gt;Keep &lt;code&gt;~/dev/hosts-profiles/local&lt;/code&gt; and &lt;code&gt;staging&lt;/code&gt;, copy into &lt;code&gt;/etc/hosts&lt;/code&gt; with &lt;code&gt;sudo&lt;/code&gt;, flush DNS.&lt;/p&gt;

&lt;p&gt;Best if you hate GUI apps and already script your machine.&lt;/p&gt;

&lt;p&gt;Gap: easy to leave conflicting lines, no safety net unless you build backups yourself.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. PowerToys Hosts File Editor (Windows only)
&lt;/h3&gt;

&lt;p&gt;Part of Macrosoft PowerToys. Clean editor for the Windows hosts file.&lt;/p&gt;

&lt;p&gt;Best if you are Windows-only and already run PowerToys.&lt;/p&gt;

&lt;p&gt;Gap: not a Gas Mask replacement on Mac, and not a multi-environment manager by itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Platforms&lt;/th&gt;
&lt;th&gt;Price&lt;/th&gt;
&lt;th&gt;Maintained&lt;/th&gt;
&lt;th&gt;Auto DNS flush&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Gas Mask&lt;/td&gt;
&lt;td&gt;macOS&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SwitchHosts&lt;/td&gt;
&lt;td&gt;Win / Mac / Linux&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Locahl&lt;/td&gt;
&lt;td&gt;Win / Mac / Linux&lt;/td&gt;
&lt;td&gt;One-time&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;iHosts&lt;/td&gt;
&lt;td&gt;macOS&lt;/td&gt;
&lt;td&gt;Paid&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Terminal profiles&lt;/td&gt;
&lt;td&gt;All&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;You&lt;/td&gt;
&lt;td&gt;Manual&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PowerToys Hosts&lt;/td&gt;
&lt;td&gt;Windows&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Manual&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  How to migrate off Gas Mask
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Uxport or copy your active hosts content while Gas Mask still opens&lt;/li&gt;
&lt;li&gt;Save a backup of &lt;code&gt;/etc/hosts&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Install the replacement&lt;/li&gt;
&lt;li&gt;Recreate profiles: &lt;code&gt;local&lt;/code&gt;, &lt;code&gt;staging&lt;/code&gt;, maybe &lt;code&gt;blocklist&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Apply one profile, flush DNS, verify with &lt;code&gt;ping&lt;/code&gt; / &lt;code&gt;getent&lt;/code&gt; before trusting the browser&lt;/li&gt;
&lt;li&gt;Uninstall Gas Mask after a week of clean use&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Do not delete Gas Mask on day one if it is the only place your profiles live.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which one should you pick?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Stay free + cross-platform → SwitchHosts&lt;/li&gt;
&lt;li&gt;Want auto flush + backups + Win/Mac/Linux → Locahl&lt;/li&gt;
&lt;li&gt;Mac only, native UI → iHosts&lt;/li&gt;
&lt;li&gt;Happy in the shell → profile files + scripts&lt;/li&gt;
&lt;li&gt;Windows only → PowerToys Hosts File Editor&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Gas Mask earned its reputation. It does not earn a place on a 2026 Mac setup anymore.&lt;/p&gt;




&lt;p&gt;If you want a maintained Gas Mask-style workflow with automatic DNS flush on Windows, macOS, and Linux, try &lt;a href="https://www.locahl.app/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=alt-gasmask" 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>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>
  </channel>
</rss>
