Add project hosts entry on MacOS
Add project hosts entry on MacOS
macOS resolves names from /etc/hosts before DNS. Use it for one-off
project names, or use Devilbox auto DNS for every project under your
TLD_SUFFIX.
Example project names
Assume .env uses TLD_SUFFIX=loc and you have these project folders:
| Project directory | URL | Hostname to add |
|---|---|---|
project-1 | http://project-1.loc | project-1.loc |
www.project-1 | http://www.project-1.loc | www.project-1.loc |
Use 127.0.0.1 with Docker Desktop on macOS.
Add entries
Open the hosts file:
sudo nano /etc/hostsAdd one line per hostname:
127.0.0.1 project-1.loc127.0.0.1 www.project-1.locSave the file, then flush the resolver cache:
sudo dscacheutil -flushcachesudo killall -HUP mDNSResponderVerify
Check that macOS returns loopback:
ping -c1 project-1.locping -c1 www.project-1.locExpected result:
PING project-1.loc (127.0.0.1): 56 data bytes64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.050 msOpen the site:
open http://project-1.locUse auto DNS instead
Start the DNS container and configure macOS once:
./dvl.sh up bindsudo mkdir -p /etc/resolverecho "nameserver 127.0.0.1" | sudo tee /etc/resolver/locNow every *.loc name resolves through Devilbox.
Remove an entry
Edit the file again, delete the matching line, and flush the cache:
sudo nano /etc/hostssudo dscacheutil -flushcachesudo killall -HUP mDNSResponder