1

I have written a script to add websites to the hostfile at certain times of the day. For example, it can block Youtube from 8pm - 10pm. It works well, however the changes aren't reflected in Chrome. This has something to do with internal DNS caching in Chrome and seemingly cannot be flushed without going into Chrome's settings or restarting the browser.

Is there any way to flush this cache from the terminal?

1
  • I have removed everything in /.cache/google-chrome/... still to no avail.
    – DaraJ
    Oct 11, 2020 at 4:24

2 Answers 2

1

Cutting out the network and then restarting it works (thanks to this answer); on Ubuntu I'm using nmcli. I wrote this as a script called "social-media-break" and run it with an argument for sleep like "5m" or "15m". It relies on the existence of these hosts.socialmediaallow and hosts.normal files, where the "normal" one sends various social media sites to 127.0.0.1.

This is quick and dirty, requires root.

#!/bin/bash
sudo -v
sudo cp /etc/hosts.socialmediaallow /etc/hosts
sleep $1
sudo cp /etc/hosts.normal /etc/hosts
nmcli networking off && nmcli networking on
2
  • This is what I ended up doing back then.
    – DaraJ
    Nov 28, 2023 at 23:10
  • Revised to do network restart instead of restarting Chrome, which seems less invasive. Nov 29, 2023 at 20:45
-1

Have you ever tried:

Open a new tab>Type the url in the search box: chrome://net-internals/#dns Hit the “Clear host cache” button.

You may need to flush out socket pools too: Open a new tab and type the following in search box: chrome://net-internals/#sockets Click on the “Flush socket pools“:

1
  • 1
    I need to be able to do it programatically... I'm sure that would work though.
    – DaraJ
    Oct 14, 2020 at 14:35

You must log in to answer this question.

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