Question
Use the /etc/hosts file to personal firewall block unwanted domains. The goal is to make the file immutable, so I don't accidentally modify it. How can I achieve this on a macOS system?
Answer
- Open Terminal (Applications > Utilities or Spotlight Search).
- Navigate to the root directory of your system:
cd / - Make a backup of the /etc/hosts file:
sudo cp hosts hosts.bak - Change the permissions of the /etc/hosts file to make it immutable:
sudo chflags -w hosts
Note:
If you ever need to modify the file, you can temporarily remove the immutable flag with the following command: sudo chflags -R -u immutable hosts
After making changes, remember to set the immutable flag back to secure the file: sudo chflags -w hosts