How to prevent accidental website visits without Tor

Sometimes it's important to keep your identity a secret. Perhaps you don't yet have a working setup that redirects all of your internet traffic through the Tor network. Perhaps you occasionally use the Tor browser to access certain websites anonymously.

If so, you should make sure that you don't accidentally access the websites with a different browser. That would give away your identity.

A really easy way to avoid this is to just point the domains in your hosts file to your own machine.

If you want to block https://duckduckgo.com/ just edit your local hosts file with sudo nano /etc/hosts and add the following line:

127.0.0.1 duckduckgo.com

If you now open your web browser and try to get to the blocked site, it will no longer work. But you can still access the site through the Tor browser.