How to Block Websites on a Fedora Linux for Better Focus

Published:
November 24, 2025
Share:
How to Block Websites on a Fedora Linux for Better Focus

You can block websites on Fedora by editing the /etc/hosts file or by using Firewalld rules to restrict network connections. These methods work system-wide and prevent access to distracting or unsafe websites. For a simpler, GUI-based option, try DigitalZen, a modern website and app blocker for Linux.

 

Key Takeaways

  • Block Sites Manually Using the Hosts File: The /etc/hosts file lets you manually map domains like facebook.com to your local IP (127.0.0.1), preventing access system-wide. It’s a simple, lightweight method that requires no extra software.
  • Use Firewalld for Advanced, System-Wide Control: Fedora’s built-in Firewalld service allows you to block websites at the network level using IP-based rules. It’s more powerful than the hosts file but requires terminal commands and administrative privileges.
  • Simplify Blocking with DigitalZen: A desktop app like DigitalZen provides the easiest way to block both websites and apps without editing configuration files or running complex commands. It’s built for Linux, including Fedora, and supports scheduling and mindful focus modes.

Method 1: Edit the /etc/hosts File (Manual Method)

One of the simplest ways to block websites on Fedora Linux is by editing the /etc/hosts file. This file maps domain names to IP addresses before your browser even reaches the internet. By pointing specific domains to your own computer’s loopback address (127.0.0.1), you can effectively prevent Fedora from loading them.

 

For example, if you add these lines to your /etc/hosts file:

127.0.0.1 facebook.com

127.0.0.1 www.facebook.com

 

Fedora will redirect those addresses back to your system instead of their real servers, making the sites unreachable.

 

If you’re using Ubuntu, you might want to check our guide on blocking websites in Ubuntu, since the process is almost identical, with only minor command differences.

Step-by-Step Guide

Step 1: Open a Terminal

Press Ctrl + Alt + T to open the terminal.

Step 2: Open the Hosts File with Root Privileges

sudo nano /etc/hosts

 

This command opens the file in Nano so you can modify it.

Step 3: Add Domains to Block

Scroll to the bottom and add one line for each domain you want to block.

 

Example:

127.0.0.1 twitter.com

127.0.0.1 www.twitter.com

127.0.0.1 instagram.com

127.0.0.1 www.instagram.com

Step 4: Save and Exit

  • Press Ctrl + O to save
  • Press Ctrl + X to exit Nano

Step 5: Restart Your Network Service

Apply the changes immediately:

 

sudo systemctl restart NetworkManager

Pros

  • Simple and system-wide (affects all browsers and apps)
  • No extra software required

Cons

  • Manual updates required
  • Doesn’t log or schedule blocking times
  • Not ideal for users who prefer a GUI or dynamic control

When Blocking Many Websites at Once

Fedora users often want to import large public blocklists (such as StevenBlack’s fakenews-gambling-porn-social hosts list). However, pasting thousands of lines directly into /etc/hosts can cause the terminal to freeze, and using a normal redirection (>>) can fail with “Permission denied” errors,  because redirection doesn’t inherit sudo privileges.

 

To safely append an entire list, follow these steps:

 

1. Download the List File

wget https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts -O hosts.txt

2. Append It Correctly with Elevated Permissions

sudo tee -a /etc/hosts < hosts.txt

The tee command ensures the write operation happens with root privileges.

3. Restart Network Manager

sudo systemctl restart NetworkManager

Method 2: Block Websites Using Firewalld (Advanced System-Wide Control)

Fedora includes a built-in firewall service, Firewalld, that controls how your system handles network connections. Unlike the /etc/hosts method, Firewalld operates at the network level, blocking or allowing traffic based on IP addresses, ports, and services. You can use it to block specific websites system-wide by denying outgoing traffic to their IP addresses.

Step-by-Step Guide

Step 1: Verify That Firewalld Is Running

Firewalld is installed and enabled by default on most Fedora systems.
To confirm it’s active, run:

 

sudo firewall-cmd –state

 

If it returns running, you’re good to go. If it’s not installed or active, set it up with:

 

sudo dnf install firewalld

sudo systemctl unmask firewalld

sudo systemctl enable –now firewalld

Step 2: Find the IP Address of the Website You Want to Block

Firewalld filters by IP, so you’ll need to look up the site’s address.
Run:

 

host facebook.com

 

Example output:

 

facebook.com has address 157.240.22.35

 

Write down the IP address.

Step 3: Add a Blocking Rule for That IP

Use a rich rule to drop all outgoing traffic to that address:

 

sudo firewall-cmd –add-rich-rule=’rule family=ipv4 destination address=157.240.22.35 drop’

 

This tells Firewalld to silently drop any packet destined for that IP.

 

If you want to test first without making it permanent, you can also set a temporary block:

 

sudo firewall-cmd –add-rich-rule=’rule family=ipv4 destination address=157.240.22.35 drop’ –timeout 15m

 

This will automatically revert after 15 minutes.

Step 4: Make the Rule Permanent and Reload

To preserve the rule across reboots:

 

sudo firewall-cmd –runtime-to-permanent

sudo firewall-cmd –reload

 

Reloading applies all permanent rules to the active configuration.
(Note: reloading briefly interrupts network traffic, so avoid doing this during remote sessions.)

Step 5: Confirm the Block Is Active

List all active rich rules:

 

sudo firewall-cmd –list-rich-rules

 

You should see your IP entry listed.

Optional: Remove a Rule Later

If you decide to unblock the site:

 

sudo firewall-cmd –remove-rich-rule=’rule family=ipv4 destination address=157.240.22.35 drop’

sudo firewall-cmd –runtime-to-permanent

sudo firewall-cmd –reload

Pros

  • Works system-wide: covers browsers and apps
  • Dynamic and secure: no need to restart service after each change
  • Permanent rules provide consistent control

Cons

  • Blocks only by IP, not domain name
  • Requires command-line knowledge
  • Can momentarily interrupt network connections on reload

Modern Alternative to Firewalld and Hosts Edits

Both the /etc/hosts and Firewalld methods work for blocking websites on Fedora, but they can be time-consuming and technical. Even a small mistake can break your connection or undo your changes.

For Fedora users who want the same control without terminal commands or manual edits, DigitalZen offers a modern, all-in-one alternative that’s fast, intuitive, and built for Linux.

Block Websites and Apps the Smart Way

DigitalZen combines simplicity and flexibility, making it one of the best Linux website-blocking solutions for productivity-focused users. Block websites or desktop apps system-wide, set daily limits, and start focusing instantly without restarting services.

Designed for Linux, Built for Balance

Most productivity apps overlook Linux users, but DigitalZen includes a dedicated desktop agent that works seamlessly on Fedora, Ubuntu, and Debian. It supports all major browsers, including Chrome, Firefox, Brave, and Vivaldi, giving you complete control across your system.

What sets DigitalZen apart is its mindful blocking approach. Instead of rigidly locking you out, it adapts to your workflow. You can pause blocking, adjust your schedule, or take mindful breaks to stay productive. It’s the perfect Cold Turkey Alternative for Linux users who want balance and control.

Conclusion: Find the Best Way to Stay Focused on Fedora

Find the Best Way to Stay Focused on Fedora

Blocking websites on Fedora can be as simple or as advanced as you want it to be. The /etc/hosts method offers quick manual control for a few distracting sites, while Firewalld provides deeper, system-wide filtering for those who want complete network-level control.

But if you’d rather skip complex terminal commands and manage everything in one place, DigitalZen delivers a more straightforward, more innovative way to stay focused. With just a few clicks, you can block websites, apps, or social media, set focus schedules, and build healthier digital habits,  all while keeping the flexibility Linux users love. You can try the DigitalZen Linux website and app blocker to streamline everything.

FAQs About Blocking Websites on Fedora

How to Block Websites in Linux?

You can block websites in any Linux distribution,  including Fedora, Ubuntu, and Debian, by editing the /etc/hosts file or using the Firewalld firewall service. These methods prevent connections system-wide. If you prefer a visual tool, you can use DigitalZen, a cross-platform app blocker that works natively on Linux.

How Do I Completely Block Certain Websites?

To completely block a website, use Firewalld to drop all connections to that site’s IP address.
Example:

 

sudo firewall-cmd –add-rich-rule=’rule family=ipv4 destination address=157.240.22.35 drop’

sudo firewall-cmd –runtime-to-permanent

sudo firewall-cmd –reload

 

This ensures the site cannot be accessed from any browser or app on your Fedora system.

How to Block Websites From the Terminal?

On Fedora, open the terminal and edit the /etc/hosts file with:

 

sudo nano /etc/hosts

 

Add the domains you want to block and redirect them to your local system:

127.0.0.1 facebook.com

127.0.0.1 www.facebook.com

 

Save the file, then restart your network:

sudo systemctl restart NetworkManager

 

This will block the listed websites across all browsers.

How to Block an App From Accessing the Internet in Linux?

You can block apps using Firewalld by identifying the program’s network ports or IP destinations and applying a “drop” rule. However, this requires technical setup. If you want an easier option, DigitalZen lets you block both apps and websites directly through its Linux desktop interface, no terminal commands required.

 

References:

  • https://fedoramagazine.org/control-the-firewall-at-the-command-line/?utm_source=
  • https://discussion.fedoraproject.org/t/cant-paste-a-lot-of-lines-in-etc-hosts-to-retrict-access-to-sites/74303?utm_source=
  • https://docs.fedoraproject.org/en-US/quick-docs/firewalld/#:~:text=Fedora%20wiki:firewalld-,Setting%20up%20firewalld,and%20activate%20the%20firewall%20afterwards.&text=firewalld.,;%203%20days%20ago%20%E2%80%A6
  • https://www.baeldung.com/linux/etc-hosts-block-specific-websites?utm_source=

 

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