- 10 Oct 2024
- 1 読む分
- 印刷する
- PDF
Block URLs/Websites
- 更新日 10 Oct 2024
- 1 読む分
- 印刷する
- PDF
Use this script to block the websites defined in the script on the Linux machine.
Copy and save the contents below to a UTF-8 editor like notepad++ OR Sublime Text in Windows or gedit in Ubuntu.
If you are using notepad++ then use the bottom right panel to change the type to Unix (LF).
Or click here to download the file.
#!/bin/bash # Get the current username USERNAME=$(whoami) # Add the user to sudoers.d directory to restrict their permissions echo "$USERNAME ALL=(ALL) /bin/echo 'Permission denied'" | sudo tee /etc/sudoers.d/block_websites >/dev/null # Define the list of websites to block WEBSITES=( "www.example.com" "www.facebook.com") # Add entries to block the websites to hosts file for website in "${WEBSITES[@]}"; do echo "0.0.0.0 $website" | sudo tee -a /etc/hosts >/dev/null done # Flush DNS cache sudo systemctl restart systemd-resolved.service echo "Websites are now blocked."
In the script, replace the following placeholder:
WEBSITES=(): Provide a list of URLs with each URL in a new line, that you want to block.
Follow our guide to upload & publish the script using Scalefusion Dashboard.
Note:
Some of the scripts and their contents are sourced from internet and yes, our new friend ChatGPT.
Please validate the scripts on a test machine before deploying them on all your managed devices.
Scalefusion has tested these scripts, however Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the usage of these scripts.