Dev.to
7/16/2026

How to switch local and staging domains with the hosts file
Short summary
A practical guide to managing /etc/hosts entries using separate profile files for local, staging, and cutover scenarios instead of leaving conflicting commented lines. The method involves keeping individual profile files, swapping them with a simple bash script, and flushing DNS afterward. The article also clarifies that hosts files only affect the host browser, not container-internal DNS resolution.
- •Use separate profile files (local, staging, cutover) instead of one cluttered hosts file
- •A bash script automates backup, swap, and DNS flush in one command
- •Hosts file affects host browser only; containers use Docker DNS or extra_hosts
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



