How Do I Block Any Website in Ubuntu: 4 Simple Methods

Published:
November 27, 2025
Share:
How Do I Block Any Website in Ubuntu

You can block websites on Ubuntu by editing the system’s hosts file, automating schedules with cron, or using tools like DigitalZen for app-level and browser-wide blocking. These methods let you control access, limit distractions, and maintain focus without a complex technical setup.

 

Key Takeaways

  • Use the Hosts File for System-Wide Blocking: Editing /etc/hosts blocks websites across all browsers and works without installing extra tools.
  • Automate Blocking with Cron: Cron can switch between hosts file versions on a schedule, letting you block sites automatically during specific hours.
  • Choose Browser Extensions for Per-Browser Control: Extensions make URL-level blocking simple and visual, though each browser must be configured separately.
  • Use an App Like DigitalZen for Full Device Coverage: A dedicated app provides unified, system-wide website and app blocking and is harder to bypass than a browser extension.
  • Match the Method to Your Needs: Ubuntu gives you several reliable options, whether you prefer manual edits, scheduled blocking, browser-level control, or full desktop protection.

Method 1: Edit /etc/hosts in Ubuntu

This is the simplest and most reliable way to block websites across all browsers on your Ubuntu system.

Step 1: Open the Terminal

Press Ctrl + Alt + T to open your terminal.

Step 2: Open the /etc/hosts file with admin rights

# Open the hosts file in Ubuntu

sudo nano /etc/hosts

Step 3: Add the websites you want to block

Scroll to the end of the file and add the sites like this:

127.0.0.1 facebook.com

127.0.0.1 www.facebook.com

127.0.0.1 youtube.com

127.0.0.1 www.youtube.com

You can also use 0.0.0.0 instead of 127.0.0.1. Both will redirect the domain to your local computer, so it can’t load.

Step 4: Save and close the file

If you’re using Nano:

  • Press Ctrl + O → Enter → Ctrl + X

Step 5: Apply the changes

Flush your DNS cache:

sudo systemd-resolve –flush-caches

Or simply restart your computer.

Now the websites you added should no longer load in any browser.

How to Unblock a Website in Ubuntu

  1. To unblock a website, reopen the same file:

sudo nano /etc/hosts

  1. Then either delete the line or comment it out:

#127.0.0.1 facebook.com

  1. Save, close, and flush DNS again:

sudo systemd-resolve –flush-caches

Method 2: Schedule Blocking Automatically with Cron (Ubuntu Built-In Tool)

If you only want to block websites during work hours, you can automate it using cron, which comes pre-installed in Ubuntu.

Step 1: Create two versions of your hosts file

# Make a copy of the current hosts file

sudo cp /etc/hosts /etc/hosts_playtime

sudo cp /etc/hosts /etc/hosts_worktime

Edit /etc/hosts_worktime and add your blocked websites (like in Method 1).

Step 2: Schedule automatic switching with cron

Open the cron editor:

sudo crontab -e

Add these lines at the bottom:

# Block websites during work hours

0 9 * * * cp /etc/hosts_worktime /etc/hosts

# Unblock after hours

0 18 * * * cp /etc/hosts_playtime /etc/hosts

This setup blocks sites from 9 AM to 6 PM every day automatically. You can adjust the times to fit your schedule.

Method 3: Use Ubuntu-Compatible Browser Extensions

If you prefer not to edit system files, you can block websites in Ubuntu using a browser extension. This method applies only inside the browser you install it on, but it is quick, visual, and does not require admin permissions.

 

Many Ubuntu users choose cross-browser extensions that support Chrome, Firefox, Brave, Vivaldi, Edge, and other Chromium-based browsers. These tools let you block websites by URL even as you switch between different browsers on Linux. Because they run at the browser level, they work on any Linux distribution and give you flexible, per-browser control without modifying configuration files.

To set up a site-blocking extension:

  1. Open your browser’s extension store. Search for a website-blocking tool that supports custom rules.
  2. Install the extension. Add it to Chrome, Firefox, Brave, Vivaldi, or your preferred browser with one click.
  3. Configure the blocklist. Open the extension settings and add the URLs you want to block. Changes usually apply instantly.

Just keep in mind that browser extensions only block websites inside the browser itself. They cannot handle the complete blocking of websites on Linux, since they do not block access in other browsers or apps on your system.

Method 4: Use a Desktop App for Full System-Wide Blocking 

If you want stronger, system-wide control that works across all browsers and apps on Ubuntu, a dedicated desktop app is the most reliable option. Unlike browser extensions, which only block websites inside a single browser, a desktop app keeps your blocking unified, harder to bypass, and active everywhere on your device.

 

DigitalZen offers a desktop agent that provides real Linux support and full system-wide blocking on Ubuntu, Debian, Pop!_OS, Zorin OS, and more.

To set up DigitalZen for complete desktop blocking:

  1. Click the “One Click Setup” button.  Use the One Click Setup option inside the extension or on the DigitalZen site. This instantly applies the recommended configuration and links your browser to the desktop agent.
  2. Install the DigitalZen desktop agent. To enable full system-wide blocking, including apps, chat tools, and any browser, install the Linux desktop agent from within the DigitalZen interface. This upgrades blocking from browser-only to full desktop coverage.
  3. Create your website and app blocklists. Add distracting websites or applications to your blocklists. Changes take effect immediately across all supported browsers and system-level apps.
  4. Configure your focus tools. DigitalZen offers several productivity features you can enable:
  • Focus Mode
  • Schedules
  • Pomodoro timers
  • Adaptive Blocking (automatically adjusts to your workflow)

These tools help you maintain long-term focus without relying on manual blocking.

Conclusion: Find the Right Website Blocking Setup for Your Ubuntu System

Right Website Blocking Setup for Your Ubuntu System

Blocking websites on Ubuntu is straightforward once you know which configuration fits your needs. Editing the /etc/hosts file gives you full control over what loads on your system, while using cron lets you automate focus hours and block certain websites without manual changes.

 

If you prefer an easier, visual option that works across apps and browsers, DigitalZen provides a modern, Ubuntu-compatible solution for distraction-free productivity. Each user can choose a method that balances convenience and control, helping you stay focused, maintain network performance, and prevent access to distracting or unsafe sites.

FAQs About Blocking Websites on Ubuntu

Can I Block Websites On Ubuntu Without Using The Terminal?

Yes. Use the DigitalZen browser extension to block websites easily. If you need a full Linux solution to block apps from accessing the internet, the DigitalZen desktop app handles that system-wide.

How Can I Block Websites Only During Work Hours On Ubuntu?

You can automate blocking using cron, Ubuntu’s built-in scheduler. By switching between two versions of your hosts file, you can block and unblock websites during work hours and allow them later automatically, ideal for managing focus and productivity.

What Is The Best App To Block Websites And Apps In Ubuntu?

DigitalZen is a cross-platform blocker that works on Ubuntu, Debian, and other Linux systems. It offers smart scheduling, focus sessions, and technology that improves how you block sites across browsers and apps, giving you total control of your digital environment.

Does The Hosts File Method Work On All Browsers?

Yes. Editing the hosts file affects all browsers and apps that connect to the internet, including Firefox, Chrome, and Chromium. It’s a system-wide block that relies on Ubuntu’s DNS server resolution, so it works using any browser by redirecting hostnames locally to your machine.

 

References:

  • https://askubuntu.com/questions/752601/how-do-i-block-unblock-websites-in-ubuntu-14-04
  • https://askubuntu.com/questions/71817/how-to-block-websites-temporarily
  • https://www.digitalocean.com/community/tutorials/how-to-use-cron-to-automate-tasks-ubuntu-1804
More from Digital Zen
How to Block Websites on Windows: Easy & System-Wide
The Benefits of Blocking Distracting Apps and Websites
How to Block Websites on Mac: Screen Time to System-Wide