Can't paste a lot of lines in /etc/hosts to retrict access to sites

I have been trying to copy and paste a list of sites in the /etc/hosts file to restrict access to those.

To be exact I am using this list: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts

But every time I copy and paste it the terminal doesn’t seem to work properly. I noticed its possible to paste a few at a time without losing responsiveness but thats going to take forever.

Although I would argue there are better ways to achieve this (like using ublock origin on browser and blocking them there) perhaps easier way to achieve this is something like:

  • Download file locally (txt)
  • Inspect contents to be sure nothing fishy is injected
  • Append whole list with cat

Example:

cat list.txt >> /etc/hosts
1 Like

I already have something setup there. I wanted to block them in the hosts as well.

I tried using cat but didnt work. Tried again using sudo, same results.

$ cat hosts.txt >> /etc/hosts 
bash: /etc/hosts: Permission denied

I used su before using

cat list.txt >> /etc/hosts

and worked! thank you!

1 Like

You also failed to show the use of sudo
As your regular user in your home directory cat /etc/hosts hosts.txt > newhosts followed by sudo cp newhosts /etc/hosts would probably have worked.

Thanks to @mhdave for noting an error in the way I originally formatted the command.

You might try the dns 1.1.1.3 and 1.0.0.3 who filters such kind of content allready with DNS.

See here:

For the records
cat hosts.txt | sudo tee -a /etc/hosts
should also work.

2 Likes