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
Enter fullscreen mode Exit fullscreen mode
Or open it in your editor with elevated rights:
sudo code /etc/hosts
# or
sudo vim /etc/hosts
Enter fullscreen mode Exit fullscreen mode
Save, then flush DNS:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
Open it on Linux
sudo nano /etc/hosts
# or
sudo vim /etc/hosts
Enter fullscreen mode Exit fullscreen mode
Flush depends on the stack. Common options:
sudo resolvectl flush-caches
# or
sudo systemd-resolve --flush-caches
Enter fullscreen mode Exit fullscreen mode
What a normal line looks like
127.0.0.1 localhost
127.0.0.1 myapp.test
# 203.0.113.10 staging.example.com
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
Windows:
ping myapp.test
Enter fullscreen mode Exit fullscreen mode
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.
답글 남기기