While trying to edit the read-only hosts file on a Mac, you may see the following message and find that you cannot save your changes:
"hosts" [readonly] 13L, 403B
This article explains what this message means, why the hosts file is read-only, and how you can safely edit and save it with the proper permissions.
Explanation of Each Part
- hosts – The name of the file you are editing.
- [readonly] – The file is opened in read-only mode, so changes cannot be saved without elevated permissions.
- 13L – The file contains 13 lines.
- 403B – The file size is 403 bytes.
Why Is the Hosts File Read-Only?
The hosts file is a critical system file used to map hostnames to IP addresses before DNS resolution occurs.
Default locations:
- macOS / Linux:
/etc/hosts
- Windows:
C:\Windows\System32\drivers\etc\hosts
Because this file can affect network behavior and security, operating systems protect it and require administrator (root) privileges to modify.
How to Edit the Read-Only Hosts File
macOS / Linux
Use sudo to open the file with elevated permissions:
sudo vim /etc/hosts
If you prefer a simpler editor:
sudo nano /etc/hosts
After editing, save and exit the editor. Your changes will be applied immediately.
Windows
- Search for Notepad (or your preferred editor).
- Right-click and choose Run as administrator.
- Open the file:
C:\Windows\System32\drivers\etc\hosts
Once opened with admin privileges, you can edit and save the file normally.
Common Use Cases for Editing the Hosts File
- Pointing a domain to
127.0.0.1 for local development
- Testing staging environments
- Blocking unwanted domains
- Debugging DNS-related issues
Important Notes
- Always keep a backup before editing system files
- Incorrect entries can break network connectivity
- No reboot is required after editing the hosts file
I hope this helps! Feel free to comment if you have questions or suggestions for improving this article.
Prakash Pradhan
Sr. Software Engineer
Senior Software Engineer with 10+ years of experience in designing and scaling distributed systems and full-stack applications. Experts in optimizing system performance, and delivering high-impact technical solutions across the entire software development lifecycle.
Comments
No comments yet.