Restrict super user write access to some files

filesystemrootsip

Is there a way to add folders to the SIP (System Integrity Protection) configurations in order to prevent them to be modified by the root user?
Or any other way not involving System Integrity Protection?
I want to protect the host file so I can block distracting websites and not being able to modify it as a root user. As a developer, I still need to be a root user so deleting sudo is not an option.

I'm looking for a solution which is independent from my internet connection.

Best Answer

SelfControl

SelfControl is an open source project aimed at restricting distractions:

SelfControl is a free and open-source application for macOS that lets you block your own access to distracting websites, your mail servers, or anything else on the Internet. Just set a period of time to block for, add sites to your blacklist, and click "Start." Until that timer expires, you will be unable to access those sites—even if you restart your computer or delete the application.

Pi-Hole

To block distracting websites and services on all your devices, consider blocking them on your network using Pi-Hole.

With this approach you avoid needing to modify your macOS configuration.