You need to open the hosts file. You already know why. You just cannot remember the path.
Here it is for each OS, plus how to open it without fighting permissions.
Paths
| OS | Path |
|---|---|
| macOS | /etc/hosts |
| Linux | /etc/hosts |
| Windows | C:\Windows\System32\drivers\etc\hosts |
On Unix systems /etc/hosts is often a symlink into the real file. Edit the path above. Do not hunt for a second copy in your home folder.
Open it on macOS
Terminal:
sudo nano /etc/hosts
Or open it in your editor with elevated rights:
sudo code /etc/hosts
# or
sudo vim /etc/hosts
Save, then flush DNS:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Finder will not let you edit /etc casually. Use the terminal or an editor launched with sudo.
Open it on Windows
- Open Notepad as Administrator
- File → Open
- Go to
C:\Windows\System32\drivers\etc\ - Change the file type filter to All Files
- Open
hosts
Without admin rights Windows will open the file but refuse to save.
Then flush DNS:
ipconfig /flushdns
Open it on Linux
sudo nano /etc/hosts
# or
sudo vim /etc/hosts
Flush depends on the stack. Common options:
sudo resolvectl flush-caches
# or
sudo systemd-resolve --flush-caches
What a normal line looks like
127.0.0.1 localhost
127.0.0.1 myapp.test
# 203.0.113.10 staging.example.com
Rules that save time:
- IP first, hostname second
- Spaces or tabs both work
-
#comments out the rest of the line - One hostname per line is easier to read than a long list
Quick check after editing
# macOS / Linux
ping -c 1 myapp.test
# or
getent hosts myapp.test
Windows:
ping myapp.test
If the IP in the reply is wrong, the hosts line did not apply yet. Flush DNS and try again before changing the app.
Common mistakes
- Editing a copy in Downloads instead of the system file
- Saving without admin rights (Windows especially)
- Leaving a
#in front of the line you meant to enable - Forgetting the DNS flush
- Using a real public TLD like
.comfor local names when.testwould avoid surprises
Bookmark the path for your OS. You will need it again.
If you switch hosts a lot, a small desktop manager helps keep profiles and DNS flush in one place: Locahl.
Top comments (0)