0

I am running Ubuntu 24.04.2 LTS.

I updated the /etc/hosts file and tried blocking some websites using the 127.0.0.1 websitename.com and it did not work. I even rebooted the machine and it still did not work.

How do I block specific websites in Ubuntu 24.04?

6
  • Are you talking about modifying /etc/hosts? That should work. Try to ping websitename.com and you will notice that 127.0.0.1 is used as the IP address.
    – Jos
    Commented Nov 22 at 10:01
  • I'd check your details; you mention Ubuntu 24.02.2 LTS which is scheduled for release on 13 February 2025 (discourse.ubuntu.com/t/noble-numbat-release-schedule/35649) where most of us don't have time-travel as an option; do you? or are your details incorrect? if so please correct. The host method you mention WILL work, but you may not have used it correctly as you provided few specifics & an invalid/future Ubuntu release (product may also be helpful; as server/desktop do differ a little in networking)
    – guiverc
    Commented Nov 22 at 10:52
  • So I updated my /etc/hosts file by typing in: sudo nano /etc/hosts and I added in: 127.0.0.1 infowars.com as a test (I figured I would try banning one of the most banned sites on the internet). When I type in: ping infowars.com it says: 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.013 ms. Then when I go to the browser and type in: infowars.com, it loads up no problem. What do I now? Thanks!
    – GoodJBoy
    Commented Nov 22 at 14:42
  • I wonder if my chrome browser (which I need to use for development of a website for my job) is ignoring the hosts file.
    – GoodJBoy
    Commented Nov 22 at 14:50
  • So it works now and here is what happened. After having updated my hosts file and then testing it and it still loaded in the browser, I simply left the file alone this time and did not remove the site I was trying to delete. After about 20 minutes, the site is now banned in my browser. So in other words, for whatever reason, it takes time for the hosts file to kick in and ban websites. Now I can ban Amazon Prime as my family is staying up way too late watching stupidity.
    – GoodJBoy
    Commented Nov 22 at 15:13

1 Answer 1

0

In my situation, after updating the /etc/hosts file, I needed to let the computer wait for around 20 minutes before it started working. In other words, I updated the /etc/hosts file and the site I was trying to ban loaded in the browser anyway. But after 20 minutes, it was blocked in the Chrome browser. I just needed to be patient.

1
  • You need to tell the system to re-read the HOSTS file; its part of the change process (eg. since i'm a desktop user I could service NetworkManager restart for example) if you don't want to wait... Networking would be slow if it was constantly re-reading that file for every web access!
    – guiverc
    Commented Nov 22 at 21:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .