Safely Modifying Your Hosts File with Gas Mask ¬
Sometimes the DNS for a specific domain on your machine needs to point somewhere else – at Curalate, we test changes microservices locally before shipping them, which could require redirecting requests to look at that local instance. One way to do this is by adding an entry like 127.0.0.1 some.service.curalate.com
to /etc/hosts
.
Why use a hosts file manager?
In most cases, it’s not advised to directly modify /etc/hosts
. Because it’s buried deep into the filesystem, it’s easy to forget you’ve modified it, which can lead to numerous problems ranging from annoying to dangerous.
Also, danger aside, it can begin to get messy and complex if you have a lot of entries to manage. Think of even just fifteen lines you’re constantly commenting/uncommenting to represent the configuration you need at a given moment. This would be insanity.
Gas Mask, a simple UI-based hosts file manager, allows you to set up different hosts files, while making it plainly obvious which hosts file is currently activated on your system via the OS Menu bar.
Installation instructions
- Go to https://github.com/2ndalpha/gasmask and download the latest version.
- Unpack and install.
- On first-run, the only hosts file listed will be
Original File
which is the/etc/hosts
file you’ll no longer be modifying.
Creating your first host file
- Create a new hosts file and name it something that makes sense.
- Add the test entry
127.0.0.1 google.com
and save. The format of these entries is<target IP address> <URL or IP to redirect>
. - Activate that hosts file. Gasmask substitutes in this file at
/etc/hosts
. - You may either need to flush your DNS cache or just restart the browser.
- To test it out, go to google.com in the browser.
- What happens now is, when the browser goes to get the IP for google.com, the OS sees the matching entry in your hosts file, then refers to
127.0.0.1
(your local computer) to make the request – which will fail. - Go ahead and reactivate your Original File, restart the browser, and you should be able to access google.com as expected.
Use the Menubar icon
It’s easy to forget to flip your hosts file back. You’ll end up spending 45 minutes on what you think is a bug, that doesn’t reproduce for anyone else, only to realize your hosts file is sending requests someplace else.
Next time you reach to modify that hosts file, consider integrating Gas Mask into your development workflow to keep it maintained and safe from unintended state.